From 809530a3d27828af21ffd7bec5816f8d3e331f3d Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Fri, 27 Sep 2024 15:08:51 +0000 Subject: [PATCH 1/3] feat: add integration test for universe domain feat: add integration test for universe domain --- 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 fcca3297cdda..ceb107e5fade 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; @@ -55,6 +56,11 @@ public static function setUpBeforeClass(): 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..6ec8fbdcca24 --- /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); + } + } + ?> From a31558805af6efbc489c6293234008c4d999ef84 Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Mon, 30 Sep 2024 09:16:26 +0000 Subject: [PATCH 2/3] style fix --- Storage/tests/System/UniverseDomainTest.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php index 6ec8fbdcca24..8ec42dcf000d 100644 --- a/Storage/tests/System/UniverseDomainTest.php +++ b/Storage/tests/System/UniverseDomainTest.php @@ -15,11 +15,11 @@ * limitations under the License. */ - namespace Google\Cloud\Storage\Tests\System; - use Google\Cloud\Storage\Bucket; +namespace Google\Cloud\Storage\Tests\System; - class UniverseDomainTest extends StorageTestCase - { +use Google\Cloud\Storage\Bucket; +class UniverseDomainTest extends StorageTestCase +{ private static $universeDomainBucket; private static $bucketName; /** @@ -64,5 +64,4 @@ public function testListsObjectsWithUniverseDomain() } $this->assertEquals($objectsToCreate, $foundObjects); } - } - ?> +} From f701a10a680755477bc2cafc5e4ae714f94acaf1 Mon Sep 17 00:00:00 2001 From: Thiyagu K Date: Mon, 30 Sep 2024 09:49:00 +0000 Subject: [PATCH 3/3] style fix --- Storage/tests/System/UniverseDomainTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php index 8ec42dcf000d..3f93e13e30e0 100644 --- a/Storage/tests/System/UniverseDomainTest.php +++ b/Storage/tests/System/UniverseDomainTest.php @@ -18,6 +18,7 @@ namespace Google\Cloud\Storage\Tests\System; use Google\Cloud\Storage\Bucket; + class UniverseDomainTest extends StorageTestCase { private static $universeDomainBucket;