From 965dd965dd182dd2903100ca061a839d9954e079 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Sat, 28 Sep 2024 08:46:50 -0700 Subject: [PATCH 1/8] skip flakey tests --- Storage/tests/System/ManageAclTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Storage/tests/System/ManageAclTest.php b/Storage/tests/System/ManageAclTest.php index b3fedf4f9c7d..fdaf2097887b 100644 --- a/Storage/tests/System/ManageAclTest.php +++ b/Storage/tests/System/ManageAclTest.php @@ -21,8 +21,12 @@ use Google\Cloud\Core\Exception\NotFoundException; /** + * These tests are marked flakey because they often throw RateLimitExceeded and + * ServiceException. + * * @group storage * @group storage-acl + * @group flakey */ class ManageAclTest extends StorageTestCase { @@ -32,12 +36,6 @@ public function testManageBucketAcl() $this->assertAcl(self::$bucket->acl(), $kind); } - /** - * This test is marked flakey because it often throws a RateLimitExceeded - * error - * - * @group flakey - */ public function testManageDefaultObjectAcl() { $kind = 'storage#objectAccessControl'; From 233280367520a60b3d4bef33a17e58a9e8a1b697 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 30 Sep 2024 10:30:04 -0700 Subject: [PATCH 2/8] misc changes to UniverseDomain system tests --- Storage/tests/System/StorageTestCase.php | 5 -- Storage/tests/System/UniverseDomainTest.php | 75 ++++++++++++++------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Storage/tests/System/StorageTestCase.php b/Storage/tests/System/StorageTestCase.php index db13a7495ee6..161db8b211be 100644 --- a/Storage/tests/System/StorageTestCase.php +++ b/Storage/tests/System/StorageTestCase.php @@ -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); diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php index 3f93e13e30e0..ffeec2b4d654 100644 --- a/Storage/tests/System/UniverseDomainTest.php +++ b/Storage/tests/System/UniverseDomainTest.php @@ -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); } } From 6d3bb9ebbfb0d1ab0fbd9b870cb1836253f0a5e6 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 30 Sep 2024 10:36:06 -0700 Subject: [PATCH 3/8] Update Storage/tests/System/UniverseDomainTest.php --- Storage/tests/System/UniverseDomainTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php index ffeec2b4d654..ccb9b3ca4de7 100644 --- a/Storage/tests/System/UniverseDomainTest.php +++ b/Storage/tests/System/UniverseDomainTest.php @@ -32,7 +32,7 @@ class UniverseDomainTest extends SystemTestCase 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'); + self::markTestSkipped('Set GOOGLE_CLOUD_PHP_TESTS_UNIVERSE_DOMAIN_KEY_PATH to run system tests'); } $credentials = json_decode(file_get_contents($keyFilePath), true); From d304b7dc01951a88ca7739d7c29f5355b49afe01 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 30 Sep 2024 10:39:02 -0700 Subject: [PATCH 4/8] add bucket delete test --- Storage/tests/System/UniverseDomainTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php index ffeec2b4d654..38e91864dd37 100644 --- a/Storage/tests/System/UniverseDomainTest.php +++ b/Storage/tests/System/UniverseDomainTest.php @@ -90,4 +90,19 @@ public function testListsObjectsWithUniverseDomain() $this->assertCount(2, $foundObjects); } + /** + * Test uploading and retrieving objects to a bucket using universe domain credentials. + * + * @depends testCreateBucketWithUniverseDomain + */ + public function testDeleteBucketWithUniverseDomain() + { + foreach (self::$bucket->objects() as $object) { + $object->delete(); + } + self::$bucket->delete(); + $this->assertFalse(self::$bucket->exists()); + $buckets = self::$client->buckets(['prefix' => self::$bucket->name()]); + $this->assertCount(0, iterator_to_array($buckets)); + } } From 40ec5572f4d5b89af5f1d164de9755982266ce8f Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 30 Sep 2024 14:25:10 -0700 Subject: [PATCH 5/8] feat(dev): add starts_with filter --- dev/src/Command/ComponentInfoCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/src/Command/ComponentInfoCommand.php b/dev/src/Command/ComponentInfoCommand.php index 82654e0184c6..a3984163cdb8 100644 --- a/dev/src/Command/ComponentInfoCommand.php +++ b/dev/src/Command/ComponentInfoCommand.php @@ -276,7 +276,7 @@ private function parseFilters(string $filterString): array { $filters = []; foreach (array_filter(explode(',', $filterString)) as $filter) { - if (!preg_match('/^(\w+?)(!~=|~=|!=|>=|<=|=|<|>)(.+)$/', $filter, $matches)) { + if (!preg_match('/^(\w+?)(!~=|~=|!=|>=|<=|=|<|>|\^=)(.+)$/', $filter, $matches)) { throw new \InvalidArgumentException(sprintf('Invalid filter: %s', $filter)); } $filters[] = [$matches[1], $matches[3], $matches[2]]; @@ -303,6 +303,7 @@ private function filterRow(array $row, array $filters): bool '!=' => ($row[$field] !== $value), '~=' => strpos($row[$field], $value) !== false, '!~=' => strpos($row[$field], $value) === false, + '^=' => str_starts_with($row[$field], $value) !== false, '>','<','>=','<=' => match($field) { 'downloads' => version_compare( str_replace(',' , '', $row[$field]), From e0e85416ef7bd74b52d74dccc20de7ce345a371b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 30 Sep 2024 15:46:49 -0700 Subject: [PATCH 6/8] typo fix in Redis system test --- Redis/tests/System/V1/CloudRedisClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Redis/tests/System/V1/CloudRedisClientTest.php b/Redis/tests/System/V1/CloudRedisClientTest.php index 2065ead61ac3..37cd2dd4cf21 100644 --- a/Redis/tests/System/V1/CloudRedisClientTest.php +++ b/Redis/tests/System/V1/CloudRedisClientTest.php @@ -109,7 +109,7 @@ public function testDeleteOperation() // Ensure delete op succeeded $instances = self::$client->listInstances(ListInstancesRequest::build(self::$parent)); $this->assertSame(0, count(array_map( - fn ($instance) => $instance->getName() === $instanceName, + fn ($instance) => $instance->getName() === self::$instanceName, iterator_to_array($instances->iterateAllElements()) ))); } From 0a304e2dffc5d5204309baaa20cfa1f917fe4659 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 1 Oct 2024 09:42:15 -0700 Subject: [PATCH 7/8] fix logic in feature detect --- .github/workflows/backwards-compatibility-checks.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backwards-compatibility-checks.yaml b/.github/workflows/backwards-compatibility-checks.yaml index 64995944328e..033e3e70ce9b 100644 --- a/.github/workflows/backwards-compatibility-checks.yaml +++ b/.github/workflows/backwards-compatibility-checks.yaml @@ -72,11 +72,11 @@ jobs: - name: "Print the action item" run: | if [[ "${{ steps.compatibility-checker.outcome }}" == 'failure' ]]; then - if [[ "${{ startsWith(github.event.pull_request.title, 'feat') }}" == "true" ]]; then + if [[ "${{ startsWith(github.event.pull_request.title, 'feat') }}" == "false" ]]; then echo "Action item: Change the conventional commit to use 'feat'" exit 1 fi - elif [[ "${{ startsWith(github.event.pull_request.title, 'feat') }}" == "false" ]]; then + elif [[ "${{ startsWith(github.event.pull_request.title, 'feat') }}" == "true" ]]; then echo "Action item: No features found, do not use 'feat' for the conventional commit" exit 1 fi From a2290bc7b571788a270fe72597e8465f8864b28a Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 1 Oct 2024 12:30:11 -0700 Subject: [PATCH 8/8] hopefully fix conventional commit check --- .github/workflows/backwards-compatibility-checks.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backwards-compatibility-checks.yaml b/.github/workflows/backwards-compatibility-checks.yaml index 033e3e70ce9b..d70fede112d9 100644 --- a/.github/workflows/backwards-compatibility-checks.yaml +++ b/.github/workflows/backwards-compatibility-checks.yaml @@ -68,7 +68,9 @@ jobs: continue-on-error: true # OwlBot PRs which are not labelled feat should not add new files or methods run: | - ~/.composer/vendor/bin/roave-backward-compatibility-check --to=origin/main --format=github-actions + ~/.composer/vendor/bin/roave-backward-compatibility-check \ + --from=${{ github.ref_name }} \ + --to=origin/main --format=github-actions - name: "Print the action item" run: | if [[ "${{ steps.compatibility-checker.outcome }}" == 'failure' ]]; then