From b5642e6e572a72ba62c2edcb2c6654042e582959 Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Mon, 30 Sep 2024 23:03:42 +0530 Subject: [PATCH] tests(storage): add integration test for universe domain (#7713) --- Storage/tests/System/StorageTestCase.php | 6 ++ Storage/tests/System/UniverseDomainTest.php | 68 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Storage/tests/System/UniverseDomainTest.php diff --git a/Storage/tests/System/StorageTestCase.php b/Storage/tests/System/StorageTestCase.php index dd3b69db48f7..db13a7495ee6 100644 --- a/Storage/tests/System/StorageTestCase.php +++ b/Storage/tests/System/StorageTestCase.php @@ -35,6 +35,7 @@ class StorageTestCase extends SystemTestCase protected static $bucket; protected static $client; protected static $unauthenticatedClient; + protected static $universeDomainClient; protected static $pubsubClient; protected static $object; protected static $mainBucketName; @@ -53,6 +54,11 @@ 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); diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php new file mode 100644 index 000000000000..3f93e13e30e0 --- /dev/null +++ b/Storage/tests/System/UniverseDomainTest.php @@ -0,0 +1,68 @@ + getenv('TEST_UNIVERSE_LOCATION') + ] + ); + $this->assertEquals(self::$bucketName, self::$universeDomainBucket->info()['name']); + } + + /** + * Test uploading and retrieving objects to a bucket using universe domain credentials. + */ + public function testListsObjectsWithUniverseDomain() + { + $foundObjects = []; + $objectsToCreate = [ + uniqid(self::TESTING_PREFIX), + uniqid(self::TESTING_PREFIX) + ]; + + foreach ($objectsToCreate as $objectToCreate) { + self::$universeDomainBucket->upload('data', ['name' => $objectToCreate]); + } + + $objects = self::$universeDomainBucket->objects(['prefix' => self::TESTING_PREFIX]); + + foreach ($objects as $object) { + foreach ($objectsToCreate as $key => $objectToCreate) { + if ($object->name() === $objectToCreate) { + $foundObjects[$key] = $object->name(); + } + } + } + $this->assertEquals($objectsToCreate, $foundObjects); + } +}