Skip to content

Commit 7017fb9

Browse files
durgesh-ninave-crestYashSaraf11
authored andcommitted
chore(secretmanager): Updated test assertions
1 parent 07896ed commit 7017fb9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

secretmanager/test/regionalsecretmanagerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
3434
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;
3535
use Google\Cloud\SecretManager\V1\DisableSecretVersionRequest;
36+
use Google\Cloud\SecretManager\V1\GetSecretRequest;
3637
use Google\Cloud\SecretManager\V1\Secret;
3738
use Google\Cloud\SecretManager\V1\SecretPayload;
3839
use Google\Cloud\SecretManager\V1\SecretVersion;
@@ -166,6 +167,13 @@ private static function deleteSecret(string $name)
166167
}
167168
}
168169

170+
private static function getSecret(string $projectId, string $locationId, string $secretId): Secret
171+
{
172+
$name = self::$client->projectLocationSecretName($projectId, $locationId, $secretId);
173+
$getSecretRequest = (new GetSecretRequest())->setName($name);
174+
return self::$client->getSecret($getSecretRequest);
175+
}
176+
169177
private static function createTagKey(string $short_name): string
170178
{
171179
$parent = self::$client->projectName(self::$projectId);
@@ -605,6 +613,9 @@ public function testCreateSecretWithDelayedDestroyed()
605613
]);
606614

607615
$this->assertStringContainsString('Created secret', $output);
616+
617+
$secret = self::getSecret($name['project'], $name['location'], $name['secret']);
618+
$this->assertEquals(self::$testDelayedDestroyTime, $secret->getVersionDestroyTtl()->getSeconds());
608619
}
609620

610621
public function testDisableSecretDelayedDestroy()
@@ -618,6 +629,9 @@ public function testDisableSecretDelayedDestroy()
618629
]);
619630

620631
$this->assertStringContainsString('Updated secret', $output);
632+
633+
$secret = self::getSecret($name['project'], $name['location'], $name['secret']);
634+
$this->assertNull($secret->getVersionDestroyTtl());
621635
}
622636

623637
public function testUpdateSecretWithDelayedDestroyed()
@@ -632,5 +646,7 @@ public function testUpdateSecretWithDelayedDestroyed()
632646
]);
633647

634648
$this->assertStringContainsString('Updated secret', $output);
649+
$secret = self::getSecret($name['project'], $name['location'], $name['secret']);
650+
$this->assertEquals(self::$testDelayedDestroyTime, $secret->getVersionDestroyTtl()->getSeconds());
635651
}
636652
}

secretmanager/test/secretmanagerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
3434
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;
3535
use Google\Cloud\SecretManager\V1\DisableSecretVersionRequest;
36+
use Google\Cloud\SecretManager\V1\GetSecretRequest;
3637
use Google\Cloud\SecretManager\V1\Replication;
3738
use Google\Cloud\SecretManager\V1\Replication\Automatic;
3839
use Google\Cloud\SecretManager\V1\Secret;
@@ -171,6 +172,14 @@ private static function deleteSecret(string $name)
171172
}
172173
}
173174

175+
private static function getSecret(string $projectId, string $secretId): Secret
176+
{
177+
$name = self::$client->secretName($projectId, $secretId);
178+
$getSecretRequest = (new GetSecretRequest())
179+
->setName($name);
180+
return self::$client->getSecret($getSecretRequest);
181+
}
182+
174183
private static function createTagKey(string $short_name): string
175184
{
176185
$parent = self::$client->projectName(self::$projectId);
@@ -598,6 +607,9 @@ public function testCreateSecretWithDelayedDestroyed()
598607
]);
599608

600609
$this->assertStringContainsString('Created secret', $output);
610+
611+
$secret = self::getSecret($name['project'], $name['secret']);
612+
$this->assertEquals(self::$testDelayedDestroyTime, $secret->getVersionDestroyTtl()->getSeconds());
601613
}
602614

603615
public function testDisableSecretDelayedDestroy()
@@ -610,6 +622,9 @@ public function testDisableSecretDelayedDestroy()
610622
]);
611623

612624
$this->assertStringContainsString('Updated secret', $output);
625+
626+
$secret = self::getSecret($name['project'], $name['secret']);
627+
$this->assertNull($secret->getVersionDestroyTtl());
613628
}
614629

615630
public function testUpdateSecretWithDelayedDestroyed()
@@ -623,5 +638,8 @@ public function testUpdateSecretWithDelayedDestroyed()
623638
]);
624639

625640
$this->assertStringContainsString('Updated secret', $output);
641+
642+
$secret = self::getSecret($name['project'], $name['secret']);
643+
$this->assertEquals(self::$testDelayedDestroyTime, $secret->getVersionDestroyTtl()->getSeconds());
626644
}
627645
}

0 commit comments

Comments
 (0)