Skip to content

Commit d526f84

Browse files
authored
chore: fix dlp trigger tests (GoogleCloudPlatform#1432)
1 parent 15ce8d0 commit d526f84

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

dlp/src/list_jobs.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* List Data Loss Prevention API jobs corresponding to a given filter.
3737
*/
3838
use Google\Cloud\Dlp\V2\DlpServiceClient;
39+
use Google\Cloud\Dlp\V2\DlpJob\JobState;
3940
use Google\Cloud\Dlp\V2\DlpJobType;
4041

4142
/** Uncomment and populate these variables in your code */
@@ -63,16 +64,18 @@
6364
printf('Job %s status: %s' . PHP_EOL, $job->getName(), $job->getState());
6465
$infoTypeStats = $job->getInspectDetails()->getResult()->getInfoTypeStats();
6566

66-
if (count($infoTypeStats) > 0) {
67-
foreach ($infoTypeStats as $infoTypeStat) {
68-
printf(
69-
' Found %s instance(s) of type %s' . PHP_EOL,
70-
$infoTypeStat->getCount(),
71-
$infoTypeStat->getInfoType()->getName()
72-
);
67+
if ($job->getState() == JobState::DONE) {
68+
if (count($infoTypeStats) > 0) {
69+
foreach ($infoTypeStats as $infoTypeStat) {
70+
printf(
71+
' Found %s instance(s) of type %s' . PHP_EOL,
72+
$infoTypeStat->getCount(),
73+
$infoTypeStat->getInfoType()->getName()
74+
);
75+
}
76+
} else {
77+
print(' No findings.' . PHP_EOL);
7378
}
74-
} else {
75-
print(' No findings.' . PHP_EOL);
7679
}
7780
}
7881
# [END dlp_list_jobs]

dlp/test/dlpTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public function testDeidReidFPE()
168168
public function testTriggers()
169169
{
170170
$bucketName = $this->requireEnv('GOOGLE_STORAGE_BUCKET');
171+
// Use a different bucket for triggers so we don't trigger a bunch of
172+
// DLP jobs on our actual storage bucket. This will create the trigger
173+
// on a nonexistant bucket.
174+
$bucketName .= '-dlp-triggers';
175+
171176
$displayName = uniqid("My trigger display name ");
172177
$description = uniqid("My trigger description ");
173178
$triggerId = uniqid('my-php-test-trigger-');

0 commit comments

Comments
 (0)