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

CT-1849 - bucket lastShareChangeDate update test #1425

Merged
merged 3 commits into from
Dec 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
30 changes: 26 additions & 4 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ All buckets are returned.
"owner": {
"id": 123,
"name": "Jan Developer"
}
},
"updated": "2024-11-28T13:03:13+0100"
},
{
"uri": "https://connection.keboola.com/v2/storage/buckets/in.c-organizationData",
Expand All @@ -1027,6 +1028,7 @@ All buckets are returned.
}
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}
]

Expand Down Expand Up @@ -1083,7 +1085,8 @@ existing bucket from another project (see below).
"hasExternalSchema": false,
"databaseName": null,
"path": "database_name.c-my-new-bucket",
"sharing": null
"sharing": null,
"updated": "2024-11-28T13:03:13+0100"
}

### Link Shared Bucket [POST /v2/storage/buckets?async={async}]
Expand Down Expand Up @@ -1142,7 +1145,9 @@ Synchronous call response (async=false)
"id": 123,
"name": "Project name"
}
}
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -1345,7 +1350,8 @@ Obtains information about a bucket.
"owner": {
"id": 123,
"name": "Jan Developer"
}
},
"updated": "2024-11-28T13:03:13+0100"
}

### Bucket Update [PUT /v2/storage/buckets/{bucket_id}/?async={async}]
Expand Down Expand Up @@ -1390,6 +1396,8 @@ Synchronous call response (async=false)
"isMaintenance": false,
"backend": "snowflake",
"sharing": null,
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}
+ Response 202
Asynchronous call response (async=true) that creates a new job. To see job detail use [Job Detail API endpoint](#reference/jobs/manage-jobs/job-detail)
Expand Down Expand Up @@ -1660,6 +1668,8 @@ Synchronous call response (async=false)
"isMaintenance": false,
"backend": "snowflake",
"sharing": "organization",
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -1735,6 +1745,8 @@ Synchronous call response (async=false)
"name": "[email protected]",
"date": "2020-02-03T14:58:29+0100"
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -1809,6 +1821,8 @@ Synchronous call response (async=false)
"name": "[email protected]",
"date": "2020-02-03T14:58:29+0100"
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -1911,6 +1925,8 @@ Synchronous call response (async=false)
"name": "[email protected]",
"date": "2020-02-03T14:58:29+0100"
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -2019,6 +2035,8 @@ Synchronous call response (async=false)
"name": "[email protected]",
"date": "2020-02-03T14:58:29+0100"
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -2103,6 +2121,8 @@ Synchronous call response (async=false)
"name": "[email protected]",
"date": "2020-02-03T14:58:29+0100"
},
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}

+ Response 202
Expand Down Expand Up @@ -2293,6 +2313,8 @@ Lists buckets which may be shared to the project.
"name": "[email protected]",
"date": "2020-02-03T14:58:29+0100"
}
"owner": null,
"updated": "2024-11-28T13:03:13+0100"
}
]

Expand Down
82 changes: 82 additions & 0 deletions tests/Backend/CommonPart1/BucketsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ public function testBucketOwner(string $devBranchType, string $userRole): void
$this->assertSame("Owner of Bucket in.c-{$bucketName} not found", $e->getMessage());
}

$this->assertNull($bucket['updated']);

try {
$this->_testClient->updateBucketOwner($bucketId, new BucketOwnerUpdateOptions(id: 99999999));
$this->fail('Should fail.');
Expand Down Expand Up @@ -640,6 +642,86 @@ public function testBucketOwner(string $devBranchType, string $userRole): void
$bucket = $this->_testClient->getBucket($bucketId);
$this->assertEquals($ownerId, $bucket['owner']['id']);
$this->assertEquals($ownerName, $bucket['owner']['name']);
$this->assertNotNull($bucket['updated']);
}

/**
* @dataProvider provideComponentsClientTypeBasedOnSuite
*/
public function testBucketDisplayNameUpdate(): void
{
$this->initEvents($this->_testClient);

$bucketName = 'bucketDisplayNameTesting';

$this->dropBucketIfExists($this->_testClient, "in.c-{$bucketName}", true);
$bucketId = $this->_testClient->createBucket($bucketName, self::STAGE_IN);

$bucket = $this->_testClient->getBucket($bucketId);
$this->assertNull($bucket['updated']);

$this->_testClient->updateBucket(new BucketUpdateOptions($bucketId, 'newBucketDisplayNameTesting'));

$eventAssertCallback = function ($events) use ($bucketId) {
$this->assertCount(1, $events);

$this->assertSame('bucket', $events[0]['objectType']);
$this->assertSame($bucketId, $events[0]['objectId']);
};

$query = new EventsQueryBuilder();
$query->setEvent('storage.bucketUpdated')
->setTokenId($this->tokenId)
->setObjectId($bucketId);
$this->assertEventWithRetries($this->_testClient, $eventAssertCallback, $query);

// update displayName do not change updated column
$bucket = $this->_testClient->getBucket($bucketId);
$this->assertNull($bucket['updated']);
}

/**
* @dataProvider provideComponentsClientTypeBasedOnSuite
*/
public function testBucketDescriptionMetadataUpdate(): void
{
$this->initEvents($this->_testClient);

$bucketName = 'bucketMetadataDescriptionTesting';
$metadataProvider = 'user';
$descriptionKey = 'KBC.description';

$this->dropBucketIfExists($this->_testClient, "in.c-{$bucketName}", true);
$bucketId = $this->_testClient->createBucket($bucketName, self::STAGE_IN);

$bucket = $this->_testClient->getBucket($bucketId);
$this->assertNull($bucket['updated']);

$metadataClient = new Metadata($this->_testClient);

$bucketMetadata = $metadataClient->listBucketMetadata($bucketId);
$this->assertEmpty($bucketMetadata);

$metadataClient->postBucketMetadata($bucketId, $metadataProvider, [[ 'key' => $descriptionKey, 'value' => 'Testing bucket description']]);

$eventAssertCallback = function ($events) use ($bucketId) {
$this->assertCount(1, $events);

$this->assertSame('bucket', $events[0]['objectType']);
$this->assertSame($bucketId, $events[0]['objectId']);
};

$query = new EventsQueryBuilder();
$query->setEvent('storage.bucketMetadataSet')
->setTokenId($this->tokenId)
->setObjectId($bucketId);
$this->assertEventWithRetries($this->_testClient, $eventAssertCallback, $query);

$bucketMetadata = $metadataClient->listBucketMetadata($bucketId);
$this->assertNotEmpty($bucketMetadata);

$bucket = $this->_testClient->getBucket($bucketId);
$this->assertNotNull($bucket['updated']);
}

public function provideComponentsClientTypeBasedOnSuite(): array
Expand Down
72 changes: 72 additions & 0 deletions tests/Backend/MixedSnowflakeBigquery/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Keboola\Test\Backend\MixedSnowflakeBigquery;

use DateTime;
use Generator;
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\BigQuery\Table;
Expand All @@ -14,6 +15,7 @@
use Keboola\Test\Backend\WorkspaceConnectionTrait;
use Keboola\Test\Backend\Workspaces\Backend\BigqueryWorkspaceBackend;
use Keboola\Test\Backend\Workspaces\Backend\WorkspaceBackendFactory;
use Keboola\Test\Utils\EventsQueryBuilder;
use Throwable;

class SharingTest extends StorageApiSharingTestCase
Expand Down Expand Up @@ -358,6 +360,76 @@ public function testLinkBucketExport(): void
);
}

public function testBucketShareUpdate(): void
{
$this->initEvents($this->_client);

$bucketName = 'bucketShareTesting';

$this->dropBucketIfExists($this->_client, "in.c-{$bucketName}", true);
$bucketId = $this->_client->createBucket($bucketName, self::STAGE_IN);

$bucket = $this->_client->getBucket($bucketId);
$this->assertNull($bucket['updated']);

$this->_client->shareOrganizationProjectBucket($bucketId);

$eventAssertCallback = function ($events) use ($bucketId) {
$this->assertCount(1, $events);

$this->assertSame('bucket', $events[0]['objectType']);
$this->assertSame($bucketId, $events[0]['objectId']);
};

$tokenData = $this->_client->verifyToken();
$query = new EventsQueryBuilder();
$query->setEvent('storage.bucketSharingEnabled')
->setTokenId($tokenData['id'])
->setObjectId($bucketId);
$this->assertEventWithRetries($this->_client, $eventAssertCallback, $query);

$bucket = $this->_client->getBucket($bucketId);
$this->assertNotNull($bucket['updated']);

$shareEnabledTime = $bucket['updated'];

$this->_client->shareOrganizationBucket($bucketId);

$query = new EventsQueryBuilder();
$query->setEvent('storage.bucketSharingTypeChanged')
->setTokenId($tokenData['id'])
->setObjectId($bucketId);
$this->assertEventWithRetries($this->_client, $eventAssertCallback, $query);

$bucket = $this->_client->getBucket($bucketId);
$this->assertNotNull($bucket['updated']);

$shareTypeChangedTime = $bucket['updated'];

$this->assertGreaterThan(
DateTime::createFromFormat(DateTime::ATOM, $shareEnabledTime),
DateTime::createFromFormat(DateTime::ATOM, $shareTypeChangedTime),
);

$this->_client->unshareBucket($bucketId);

$query = new EventsQueryBuilder();
$query->setEvent('storage.bucketSharingDisabled')
->setTokenId($tokenData['id'])
->setObjectId($bucketId);
$this->assertEventWithRetries($this->_client, $eventAssertCallback, $query);

$bucket = $this->_client->getBucket($bucketId);
$this->assertNotNull($bucket['updated']);

$shareDisabledTime = $bucket['updated'];

$this->assertGreaterThan(
DateTime::createFromFormat(DateTime::ATOM, $shareTypeChangedTime),
DateTime::createFromFormat(DateTime::ATOM, $shareDisabledTime),
);
}

private function assertColumns(Table $table, array $expectedColumns): void
{
$table->reload();
Expand Down