Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Dec 27, 2023
1 parent 7d93a3d commit 47be9fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
7 changes: 5 additions & 2 deletions secretmanager/test/quickstartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
declare(strict_types=1);

use Google\ApiCore\ApiException as GaxApiException;
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;
use Google\Cloud\TestUtils\TestTrait;
use PHPUnit\Framework\TestCase;

Expand All @@ -39,7 +40,9 @@ public static function tearDownAfterClass(): void
$name = $client->secretName(self::$projectId, self::$secretId);

try {
$client->deleteSecret($name);
$deleteSecretRequest = (new DeleteSecretRequest())
->setName($name);
$client->deleteSecret($deleteSecretRequest);
} catch (GaxApiException $e) {
if ($e->getStatus() != 'NOT_FOUND') {
throw $e;
Expand Down
31 changes: 22 additions & 9 deletions secretmanager/test/secretmanagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
namespace Google\Cloud\Samples\SecretManager;

use Google\ApiCore\ApiException as GaxApiException;
use Google\Cloud\SecretManager\V1\AddSecretVersionRequest;
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;
use Google\Cloud\SecretManager\V1\DisableSecretVersionRequest;
use Google\Cloud\SecretManager\V1\Replication;
use Google\Cloud\SecretManager\V1\Replication\Automatic;
use Google\Cloud\SecretManager\V1\Secret;
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\SecretPayload;
use Google\Cloud\SecretManager\V1\SecretVersion;
use Google\Cloud\TestUtils\TestTrait;
Expand Down Expand Up @@ -81,32 +85,41 @@ private static function createSecret(): Secret
{
$parent = self::$client->projectName(self::$projectId);
$secretId = self::randomSecretId();

return self::$client->createSecret($parent, $secretId,
new Secret([
$createSecretRequest = (new CreateSecretRequest())
->setParent($parent)
->setSecretId($secretId)
->setSecret(new Secret([
'replication' => new Replication([
'automatic' => new Automatic(),
]),
])
);
]));

return self::$client->createSecret($createSecretRequest);
}

private static function addSecretVersion(Secret $secret): SecretVersion
{
return self::$client->addSecretVersion($secret->getName(), new SecretPayload([
$addSecretVersionRequest = (new AddSecretVersionRequest())
->setParent($secret->getName())
->setPayload(new SecretPayload([
'data' => 'my super secret data',
]));
return self::$client->addSecretVersion($addSecretVersionRequest);
}

private static function disableSecretVersion(SecretVersion $version): SecretVersion
{
return self::$client->disableSecretVersion($version->getName());
$disableSecretVersionRequest = (new DisableSecretVersionRequest())
->setName($version->getName());
return self::$client->disableSecretVersion($disableSecretVersionRequest);
}

private static function deleteSecret(string $name)
{
try {
self::$client->deleteSecret($name);
$deleteSecretRequest = (new DeleteSecretRequest())
->setName($name);
self::$client->deleteSecret($deleteSecretRequest);
} catch (GaxApiException $e) {
if ($e->getStatus() != 'NOT_FOUND') {
throw $e;
Expand Down

0 comments on commit 47be9fe

Please sign in to comment.