Skip to content

Commit

Permalink
tests(storage): add integration test for universe domain (#7713)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiyaguk09 authored Sep 30, 2024
1 parent 7bbcfd6 commit b5642e6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Storage/tests/System/StorageTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
68 changes: 68 additions & 0 deletions Storage/tests/System/UniverseDomainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Storage\Tests\System;

use Google\Cloud\Storage\Bucket;

class UniverseDomainTest extends StorageTestCase
{
private static $universeDomainBucket;
private static $bucketName;
/**
* 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')
]
);
$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);
}
}

0 comments on commit b5642e6

Please sign in to comment.