Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: misc system test fixes and cleanup #7717

Merged
merged 9 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/backwards-compatibility-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ 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
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
Expand Down
2 changes: 1 addition & 1 deletion Redis/tests/System/V1/CloudRedisClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)));
}
Expand Down
10 changes: 4 additions & 6 deletions Storage/tests/System/ManageAclTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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';
Expand Down
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
88 changes: 64 additions & 24 deletions Storage/tests/System/UniverseDomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,92 @@

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;

/**
* Test creating a bucket with universe domain credentials
* @beforeClass
*/
public static function setUpTestFixtures(): void
{
if (!$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_UNIVERSE_DOMAIN_KEY_PATH')) {
self::markTestSkipped('Set GOOGLE_CLOUD_PHP_TESTS_UNIVERSE_DOMAIN_KEY_PATH 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
*/
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]);

$foundObjects = array_filter(
iterator_to_array($objects),
fn ($object) => in_array($object->name(), $objectsToCreate)
);

foreach ($objects as $object) {
foreach ($objectsToCreate as $key => $objectToCreate) {
if ($object->name() === $objectToCreate) {
$foundObjects[$key] = $object->name();
}
}
$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();
}
$this->assertEquals($objectsToCreate, $foundObjects);
self::$bucket->delete();
$this->assertFalse(self::$bucket->exists());
$buckets = self::$client->buckets(['prefix' => self::$bucket->name()]);
$this->assertCount(0, iterator_to_array($buckets));
}
}
3 changes: 2 additions & 1 deletion dev/src/Command/ComponentInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand All @@ -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]),
Expand Down
Loading