Skip to content

Commit

Permalink
misc changes to UniverseDomain system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Sep 30, 2024
1 parent 965dd96 commit 2332803
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
5 changes: 0 additions & 5 deletions Storage/tests/System/StorageTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public static function setUpTestFixtures(): void
self::$unauthenticatedClient = new StorageClient([
'credentialsFetcher' => new AnonymousCredentials()
]);
self::$universeDomainClient = new StorageClient([
'keyFilePath' => getenv('TEST_UNIVERSE_DOMAIN_CREDENTIAL'),
'projectId' => getenv('TEST_UNIVERSE_PROJECT_ID'),
'universeDomain' => getenv('TEST_UNIVERSE_DOMAIN')
]);
self::$pubsubClient = new PubSubClient($config);

self::$mainBucketName = getenv('BUCKET') ?: uniqid(self::TESTING_PREFIX);
Expand Down
75 changes: 50 additions & 25 deletions Storage/tests/System/UniverseDomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,77 @@

namespace Google\Cloud\Storage\Tests\System;

use Google\Cloud\Core\Testing\System\SystemTestCase;
use Google\Cloud\Storage\Bucket;
use Google\Cloud\Storage\StorageClient;

class UniverseDomainTest extends StorageTestCase
class UniverseDomainTest extends SystemTestCase
{
private static $universeDomainBucket;
private static $bucketName;
private static $bucket;
private static $client;

/**
* @beforeClass
*/
public static function setUpTestFixtures(): void
{
if (!$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_UNIVERSE_DOMAIN_KEY_PATH')) {
self::markTestSkipped('Set TEST_UNIVERSE_DOMAIN_CREDENTIAL to run system tests');
}

$credentials = json_decode(file_get_contents($keyFilePath), true);
if (!isset($credentials['universe_domain'])) {
throw new \Exception('The provided key file does not contain universe domain credentials');
}

self::$client = new StorageClient([
'keyFilePath' => $keyFilePath,
'projectId' => $credentials['project_id'] ?? null,
'universeDomain' => $credentials['universe_domain'] ?? null
]);
}

/**
* Test creating a bucket with universe domain credentials
* Test creating a bucket with universe domain credentials
*/
public function testCreateBucketWithUniverseDomain()
{
self::$bucketName = uniqid(self::TESTING_PREFIX);
self::$universeDomainBucket = self::createBucket(
self::$universeDomainClient,
self::$bucketName,
[
'location' => getenv('TEST_UNIVERSE_LOCATION')
]
if (!$location = getenv('GOOGLE_CLOUD_PHP_TESTS_UNIVERSE_DOMAIN_LOCATION')) {
$this->markTestSkipped('Set GOOGLE_CLOUD_PHP_TESTS_UNIVERSE_DOMAIN_LOCATION to run system tests');
}
$bucketName = uniqid(StorageTestCase::TESTING_PREFIX);
self::$bucket = self::createBucket(
self::$client,
$bucketName,
['location' => $location]
);
$this->assertEquals(self::$bucketName, self::$universeDomainBucket->info()['name']);
$this->assertEquals($bucketName, self::$bucket->info()['name']);
}

/**
* Test uploading and retrieving objects to a bucket using universe domain credentials.
* Test uploading and retrieving objects to a bucket using universe domain credentials.
*
* @depends testCreateBucketWithUniverseDomain
*/
public function testListsObjectsWithUniverseDomain()
{
$foundObjects = [];
$objectsToCreate = [
uniqid(self::TESTING_PREFIX),
uniqid(self::TESTING_PREFIX)
uniqid(StorageTestCase::TESTING_PREFIX),
uniqid(StorageTestCase::TESTING_PREFIX)
];

foreach ($objectsToCreate as $objectToCreate) {
self::$universeDomainBucket->upload('data', ['name' => $objectToCreate]);
self::$bucket->upload('data', ['name' => $objectToCreate]);
}

$objects = self::$universeDomainBucket->objects(['prefix' => self::TESTING_PREFIX]);
$objects = self::$bucket->objects(['prefix' => StorageTestCase::TESTING_PREFIX]);

foreach ($objects as $object) {
foreach ($objectsToCreate as $key => $objectToCreate) {
if ($object->name() === $objectToCreate) {
$foundObjects[$key] = $object->name();
}
}
}
$this->assertEquals($objectsToCreate, $foundObjects);
$foundObjects = array_filter(
iterator_to_array($objects),
fn ($object) => in_array($object->name(), $objectsToCreate)
);

$this->assertCount(2, $foundObjects);
}
}

0 comments on commit 2332803

Please sign in to comment.