Skip to content

Commit e142f45

Browse files
authored
fix: failing monitoring, dlp, and video samples (GoogleCloudPlatform#1400)
1 parent e20d8e7 commit e142f45

12 files changed

+68
-30
lines changed

dlp/test/dlpTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
use Google\Cloud\TestUtils\TestTrait;
2121
use PHPUnit\Framework\TestCase;
22+
use PHPUnitRetry\RetryTrait;
2223

2324
/**
2425
* Unit Tests for dlp commands.
2526
*/
2627
class dlpTest extends TestCase
2728
{
2829
use TestTrait;
30+
use RetryTrait;
2931

3032
public function testInspectImageFile()
3133
{
@@ -224,9 +226,16 @@ public function testInspectTemplates()
224226
$this->assertStringContainsString('Successfully deleted template ' . $fullTemplateId, $output);
225227
}
226228

229+
/**
230+
* @retryAttempts 3
231+
*/
227232
public function testJobs()
228233
{
229-
$filter = 'state=DONE';
234+
// Set filter to only go back a day, so that we do not pull every job.
235+
$filter = sprintf(
236+
'state=DONE AND end_time>"%sT00:00:00+00:00"',
237+
date('Y-m-d', strtotime('-1 day'))
238+
);
230239
$jobIdRegex = "~projects/.*/dlpJobs/i-\d+~";
231240

232241
$output = $this->runSnippet('list_jobs', [

monitoring/test/alertsTest.php

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
use Google\Cloud\TestUtils\ExecuteCommandTrait;
2323
use Google\Cloud\TestUtils\TestTrait;
2424
use PHPUnit\Framework\TestCase;
25+
use PHPUnitRetry\RetryTrait;
2526

2627
class alertsTest extends TestCase
2728
{
2829
use ExecuteCommandTrait;
2930
use TestTrait;
31+
use RetryTrait;
3032

3133
private static $commandFile = __DIR__ . '/../alerts.php';
3234
private static $policyId;
@@ -43,9 +45,17 @@ public function testCreatePolicy()
4345
self::$policyId = $matches[1];
4446
}
4547

48+
/**
49+
* @depends testCreatePolicy
50+
* @retryAttempts 2
51+
* @retryDelaySeconds 10
52+
*/
4653
public function testEnablePolicies()
4754
{
48-
$policyName = AlertPolicyServiceClient::alertPolicyName(self::$projectId, self::$policyId);
55+
$policyName = AlertPolicyServiceClient::alertPolicyName(
56+
self::$projectId,
57+
self::$policyId
58+
);
4959
$output = $this->runAlertCommand('enable-policies', [
5060
'filter' => sprintf('name = "%s"', $policyName),
5161
'enable' => true,
@@ -54,13 +64,25 @@ public function testEnablePolicies()
5464
sprintf('Policy %s is already enabled', $policyName),
5565
$output
5666
);
67+
}
5768

69+
/**
70+
* @depends testEnablePolicies
71+
*/
72+
public function testDisablePolicies()
73+
{
74+
$policyName = AlertPolicyServiceClient::alertPolicyName(
75+
self::$projectId,
76+
self::$policyId
77+
);
5878
$output = $this->runAlertCommand('enable-policies', [
5979
'filter' => sprintf('name = "%s"', $policyName),
6080
'enable' => false,
6181
]);
62-
63-
$this->assertStringContainsString(sprintf('Disabled %s', $policyName), $output);
82+
$this->assertStringContainsString(
83+
sprintf('Disabled %s', $policyName),
84+
$output
85+
);
6486
}
6587

6688
/** @depends testCreatePolicy */
@@ -148,10 +170,11 @@ public function testListChannels()
148170
$this->assertStringContainsString(self::$channelId, $output);
149171
}
150172

151-
/** @depends testCreateChannel */
152-
public function testBackupAndRestore()
173+
/**
174+
* @depends testCreateChannel
175+
*/
176+
public function testBackupPolicies()
153177
{
154-
// backup
155178
$output = $this->runAlertCommand('backup-policies');
156179
$this->assertStringContainsString('Backed up alert policies', $output);
157180

@@ -163,8 +186,15 @@ public function testBackupAndRestore()
163186
$this->assertGreaterThan(0, count($backup['channels']));
164187
$this->assertStringContainsString(self::$policyId, $backupJson);
165188
$this->assertStringContainsString(self::$channelId, $backupJson);
189+
}
166190

167-
// restore
191+
/**
192+
* @depends testBackupPolicies
193+
* @retryAttempts 2
194+
* @retryDelaySeconds 10
195+
*/
196+
public function testRestorePolicies()
197+
{
168198
$output = $this->runAlertCommand('restore-policies');
169199
$this->assertStringContainsString('Restored alert policies', $output);
170200
}

video/quickstart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
$video = new VideoIntelligenceServiceClient();
2727

2828
# Execute a request.
29+
$features = [Feature::LABEL_DETECTION];
2930
$options = [
3031
'inputUri' => 'gs://cloud-samples-data/video/cat.mp4',
31-
'features' => [Feature::LABEL_DETECTION]
3232
];
33-
$operation = $video->annotateVideo($options);
33+
$operation = $video->annotateVideo($features, $options);
3434

3535
# Wait for the request to complete.
3636
$operation->pollUntilComplete();

video/src/analyze_explicit_content.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
$video = new VideoIntelligenceServiceClient();
4444

4545
# Execute a request.
46-
$operation = $video->annotateVideo([
46+
$features = [Feature::EXPLICIT_CONTENT_DETECTION];
47+
$operation = $video->annotateVideo($features, [
4748
'inputUri' => $uri,
48-
'features' => [Feature::EXPLICIT_CONTENT_DETECTION]
4949
]);
5050

5151
# Wait for the request to complete.

video/src/analyze_labels_file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
$inputContent = file_get_contents($path);
4141

4242
# Execute a request.
43-
$operation = $video->annotateVideo([
43+
$features = [Feature::LABEL_DETECTION];
44+
$operation = $video->annotateVideo($features, [
4445
'inputContent' => $inputContent,
45-
'features' => [Feature::LABEL_DETECTION]
4646
]);
4747

4848
# Wait for the request to complete.

video/src/analyze_labels_gcs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
$video = new VideoIntelligenceServiceClient();
3838

3939
# Execute a request.
40-
$operation = $video->annotateVideo([
40+
$features = [Feature::LABEL_DETECTION];
41+
$operation = $video->annotateVideo($features, [
4142
'inputUri' => $uri,
42-
'features' => [Feature::LABEL_DETECTION]
4343
]);
4444

4545
# Wait for the request to complete.

video/src/analyze_object_tracking.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
$video = new VideoIntelligenceServiceClient();
3838

3939
# Execute a request.
40-
$operation = $video->annotateVideo([
40+
$features = [Feature::OBJECT_TRACKING];
41+
$operation = $video->annotateVideo($features, [
4142
'inputUri' => $uri,
42-
'features' => [Feature::OBJECT_TRACKING]
4343
]);
4444

4545
# Wait for the request to complete.

video/src/analyze_object_tracking_file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
$inputContent = file_get_contents($path);
4141

4242
# Execute a request.
43-
$operation = $video->annotateVideo([
43+
$features = [Feature::OBJECT_TRACKING];
44+
$operation = $video->annotateVideo($features, [
4445
'inputContent' => $inputContent,
45-
'features' => [Feature::OBJECT_TRACKING]
4646
]);
4747

4848
# Wait for the request to complete.

video/src/analyze_shots.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
$video = new VideoIntelligenceServiceClient();
3838

3939
# Execute a request.
40-
$operation = $video->annotateVideo([
40+
$features = [Feature::SHOT_CHANGE_DETECTION];
41+
$operation = $video->annotateVideo($features, [
4142
'inputUri' => $uri,
42-
'features' => [Feature::SHOT_CHANGE_DETECTION]
4343
]);
4444

4545
# Wait for the request to complete.

video/src/analyze_text_detection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
$video = new VideoIntelligenceServiceClient();
3838

3939
# Execute a request.
40-
$operation = $video->annotateVideo([
40+
$features = [Feature::TEXT_DETECTION];
41+
$operation = $video->annotateVideo($features, [
4142
'inputUri' => $uri,
42-
'features' => [Feature::TEXT_DETECTION]
4343
]);
4444

4545
# Wait for the request to complete.

video/src/analyze_text_detection_file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
$inputContent = file_get_contents($path);
4141

4242
# Execute a request.
43-
$operation = $video->annotateVideo([
43+
$features = [Feature::TEXT_DETECTION];
44+
$operation = $video->annotateVideo($features, [
4445
'inputContent' => $inputContent,
45-
'features' => [Feature::TEXT_DETECTION]
4646
]);
4747

4848
# Wait for the request to complete.

video/src/analyze_transcription.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
// $options = [];
3737

3838
# set configs
39-
$features = [Feature::SPEECH_TRANSCRIPTION];
4039
$speechTranscriptionConfig = (new SpeechTranscriptionConfig())
4140
->setLanguageCode('en-US')
4241
->setEnableAutomaticPunctuation(true);
@@ -47,10 +46,10 @@
4746
$client = new VideoIntelligenceServiceClient();
4847

4948
# execute a request.
50-
$operation = $client->annotateVideo([
49+
$features = [Feature::SPEECH_TRANSCRIPTION];
50+
$operation = $client->annotateVideo($features, [
5151
'inputUri' => $uri,
52-
'features' => $features,
53-
'videoContext' => $videoContext
52+
'videoContext' => $videoContext,
5453
]);
5554

5655
print('Processing video for speech transcription...' . PHP_EOL);

0 commit comments

Comments
 (0)