Skip to content

Commit 2254b43

Browse files
authored
chore: upgrade media-livestream tests to new surface (#1992)
1 parent db9784d commit 2254b43

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

media/livestream/test/livestreamTest.php

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@
2222
use Google\ApiCore\ApiException;
2323
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
2424
use Google\Cloud\TestUtils\TestTrait;
25-
use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient;
25+
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
26+
use Google\Cloud\Video\LiveStream\V1\DeleteAssetRequest;
27+
use Google\Cloud\Video\LiveStream\V1\DeleteChannelRequest;
28+
use Google\Cloud\Video\LiveStream\V1\DeleteEventRequest;
29+
use Google\Cloud\Video\LiveStream\V1\DeleteInputRequest;
30+
use Google\Cloud\Video\LiveStream\V1\GetChannelRequest;
31+
use Google\Cloud\Video\LiveStream\V1\GetInputRequest;
32+
use Google\Cloud\Video\LiveStream\V1\GetPoolRequest;
33+
use Google\Cloud\Video\LiveStream\V1\ListAssetsRequest;
34+
use Google\Cloud\Video\LiveStream\V1\ListChannelsRequest;
35+
use Google\Cloud\Video\LiveStream\V1\ListEventsRequest;
36+
use Google\Cloud\Video\LiveStream\V1\ListInputsRequest;
37+
use Google\Cloud\Video\LiveStream\V1\StopChannelRequest;
2638
use PHPUnit\Framework\TestCase;
2739

2840
/**
@@ -107,7 +119,9 @@ public function testUpdateInput()
107119
self::$location,
108120
self::$inputId
109121
);
110-
$input = $livestreamClient->getInput($formattedName);
122+
$getInputRequest = (new GetInputRequest())
123+
->setName($formattedName);
124+
$input = $livestreamClient->getInput($getInputRequest);
111125
$this->assertTrue($input->getPreprocessingConfig()->hasCrop());
112126
}
113127

@@ -198,7 +212,9 @@ public function testUpdateChannel()
198212
self::$location,
199213
self::$channelId
200214
);
201-
$channel = $livestreamClient->getChannel($formattedName);
215+
$getChannelRequest = (new GetChannelRequest())
216+
->setName($formattedName);
217+
$channel = $livestreamClient->getChannel($getChannelRequest);
202218
$inputAttachments = $channel->getInputAttachments();
203219
foreach ($inputAttachments as $inputAttachment) {
204220
$this->assertStringContainsString('updated-input', $inputAttachment->getKey());
@@ -476,15 +492,19 @@ public function testUpdatePool()
476492
self::$location,
477493
self::$poolId
478494
);
479-
$pool = $livestreamClient->getPool($formattedName);
495+
$getPoolRequest = (new GetPoolRequest())
496+
->setName($formattedName);
497+
$pool = $livestreamClient->getPool($getPoolRequest);
480498
$this->assertEquals($pool->getNetworkConfig()->getPeeredNetwork(), '');
481499
}
482500

483501
private static function deleteOldInputs(): void
484502
{
485503
$livestreamClient = new LivestreamServiceClient();
486504
$parent = $livestreamClient->locationName(self::$projectId, self::$location);
487-
$response = $livestreamClient->listInputs($parent);
505+
$listInputsRequest = (new ListInputsRequest())
506+
->setParent($parent);
507+
$response = $livestreamClient->listInputs($listInputsRequest);
488508
$inputs = $response->iterateAllElements();
489509

490510
$currentTime = time();
@@ -498,7 +518,9 @@ private static function deleteOldInputs(): void
498518

499519
if ($currentTime - $timestamp >= $oneHourInSecs) {
500520
try {
501-
$livestreamClient->deleteInput($input->getName());
521+
$deleteInputRequest = (new DeleteInputRequest())
522+
->setName($input->getName());
523+
$livestreamClient->deleteInput($deleteInputRequest);
502524
} catch (ApiException $e) {
503525
// Cannot delete inputs that are added to channels
504526
if ($e->getStatus() === 'FAILED_PRECONDITION') {
@@ -515,7 +537,9 @@ private static function deleteOldChannels(): void
515537
{
516538
$livestreamClient = new LivestreamServiceClient();
517539
$parent = $livestreamClient->locationName(self::$projectId, self::$location);
518-
$response = $livestreamClient->listChannels($parent);
540+
$listChannelsRequest = (new ListChannelsRequest())
541+
->setParent($parent);
542+
$response = $livestreamClient->listChannels($listChannelsRequest);
519543
$channels = $response->iterateAllElements();
520544

521545
$currentTime = time();
@@ -529,18 +553,24 @@ private static function deleteOldChannels(): void
529553

530554
if ($currentTime - $timestamp >= $oneHourInSecs) {
531555
// Must delete channel events before deleting the channel
532-
$response = $livestreamClient->listEvents($channel->getName());
556+
$listEventsRequest = (new ListEventsRequest())
557+
->setParent($channel->getName());
558+
$response = $livestreamClient->listEvents($listEventsRequest);
533559
$events = $response->iterateAllElements();
534560
foreach ($events as $event) {
535561
try {
536-
$livestreamClient->deleteEvent($event->getName());
562+
$deleteEventRequest = (new DeleteEventRequest())
563+
->setName($event->getName());
564+
$livestreamClient->deleteEvent($deleteEventRequest);
537565
} catch (ApiException $e) {
538566
printf('Channel event delete failed: %s.' . PHP_EOL, $e->getMessage());
539567
}
540568
}
541569

542570
try {
543-
$livestreamClient->stopChannel($channel->getName());
571+
$stopChannelRequest = (new StopChannelRequest())
572+
->setName($channel->getName());
573+
$livestreamClient->stopChannel($stopChannelRequest);
544574
} catch (ApiException $e) {
545575
// Cannot delete channels that are running, but
546576
// channel may already be stopped
@@ -552,7 +582,9 @@ private static function deleteOldChannels(): void
552582
}
553583

554584
try {
555-
$livestreamClient->deleteChannel($channel->getName());
585+
$deleteChannelRequest = (new DeleteChannelRequest())
586+
->setName($channel->getName());
587+
$livestreamClient->deleteChannel($deleteChannelRequest);
556588
} catch (ApiException $e) {
557589
// Cannot delete inputs that are added to channels
558590
if ($e->getStatus() === 'FAILED_PRECONDITION') {
@@ -569,7 +601,9 @@ private static function deleteOldAssets(): void
569601
{
570602
$livestreamClient = new LivestreamServiceClient();
571603
$parent = $livestreamClient->locationName(self::$projectId, self::$location);
572-
$response = $livestreamClient->listAssets($parent);
604+
$listAssetsRequest = (new ListAssetsRequest())
605+
->setParent($parent);
606+
$response = $livestreamClient->listAssets($listAssetsRequest);
573607
$assets = $response->iterateAllElements();
574608

575609
$currentTime = time();
@@ -583,7 +617,9 @@ private static function deleteOldAssets(): void
583617

584618
if ($currentTime - $timestamp >= $oneHourInSecs) {
585619
try {
586-
$livestreamClient->deleteAsset($asset->getName());
620+
$deleteAssetRequest = (new DeleteAssetRequest())
621+
->setName($asset->getName());
622+
$livestreamClient->deleteAsset($deleteAssetRequest);
587623
} catch (ApiException $e) {
588624
printf('Asset delete failed: %s.' . PHP_EOL, $e->getMessage());
589625
}

0 commit comments

Comments
 (0)