Skip to content

Commit 5a18bcb

Browse files
committed
test bucket response and backendPath
1 parent de29eee commit 5a18bcb

2 files changed

Lines changed: 101 additions & 7 deletions

File tree

apiary.apib

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,10 @@ All buckets are returned.
10101010
},
10111011
"updated": "2024-11-28T13:03:13+0100",
10121012
"color": null
1013+
"backendPath": [
1014+
"KBC_PRJ_123",
1015+
"in.c-main"
1016+
],
10131017
},
10141018
{
10151019
"uri": "https://connection.keboola.com/v2/storage/buckets/in.c-organizationData",
@@ -1021,6 +1025,10 @@ All buckets are returned.
10211025
"tables": "https://connection.keboola.com/v2/storage/buckets/in.c-organizationData/tables",
10221026
"backend": "snowflake",
10231027
"isReadonly": true,
1028+
"backendPath": [
1029+
"KBC_PRJ_123",
1030+
"in.c-main"
1031+
],
10241032
"sourceBucket": {
10251033
"id": "in.c-main",
10261034
"name": "c-main",
@@ -1092,7 +1100,11 @@ existing bucket from another project (see below).
10921100
"path": "database_name.c-my-new-bucket",
10931101
"sharing": null,
10941102
"updated": "2024-11-28T13:03:13+0100",
1095-
"color": null
1103+
"color": null,
1104+
"backendPath": [
1105+
"KBC_PRJ_123",
1106+
"in.c-main"
1107+
],
10961108
}
10971109

10981110
### Link Shared Bucket [POST /v2/storage/buckets?async={async}]
@@ -1153,7 +1165,11 @@ Synchronous call response (async=false)
11531165
}
11541166
},
11551167
"owner": null,
1156-
"updated": "2024-11-28T13:03:13+0100"
1168+
"updated": "2024-11-28T13:03:13+0100",
1169+
"backendPath": [
1170+
"KBC_PRJ_123",
1171+
"in.c-main"
1172+
],
11571173
}
11581174

11591175
+ Response 202
@@ -1367,7 +1383,11 @@ Obtains information about a bucket.
13671383
"name": "Jan Developer",
13681384
"email": "jan.dev@keboola.com"
13691385
},
1370-
"updated": "2024-11-28T13:03:13+0100"
1386+
"updated": "2024-11-28T13:03:13+0100",
1387+
"backendPath": [
1388+
"KBC_PRJ_123",
1389+
"in.c-main"
1390+
],
13711391
}
13721392

13731393
### Bucket Update [PUT /v2/storage/buckets/{bucket_id}/?async={async}]
@@ -1416,7 +1436,11 @@ Synchronous call response (async=false)
14161436
"sharing": null,
14171437
"owner": null,
14181438
"updated": "2024-11-28T13:03:13+0100",
1419-
"color": "#00FF00"
1439+
"color": "#00FF00",
1440+
"backendPath": [
1441+
"KBC_PRJ_123",
1442+
"in.c-main"
1443+
],
14201444
}
14211445
+ Response 202
14221446
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)
@@ -3555,7 +3579,11 @@ Obtains information about a table.
35553579
"isMaintenance": false,
35563580
"backend": "snowflake",
35573581
"sharing": null,
3558-
"metadata": []
3582+
"metadata": [],
3583+
"backendPath": [
3584+
"KBC_PRJ_123",
3585+
"in.c-main"
3586+
],
35593587
},
35603588
"configuration": {
35613589
"componentId": "keboola.app-custom-query-manager",
@@ -3654,7 +3682,11 @@ Synchronous call response (async=false)
36543682
"isMaintenance": false,
36553683
"backend": "snowflake",
36563684
"sharing": null,
3657-
"metadata": []
3685+
"metadata": [],
3686+
"backendPath": [
3687+
"KBC_PRJ_123",
3688+
"in.c-main"
3689+
],
36583690
},
36593691
"configuration": {
36603692
"componentId": "keboola.app-custom-query-manager",
@@ -4411,6 +4443,10 @@ An alias cannot be created from tables in an external bucket or from a table in
44114443
"isMaintenance": false,
44124444
"backend": "snowflake",
44134445
"sharing": null,
4446+
"backendPath": [
4447+
"KBC_PRJ_123",
4448+
"in.c-main"
4449+
],
44144450
}
44154451
}
44164452

tests/Backend/CommonPart1/BucketsTest.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,51 @@ public function testBucketsList(string $devBranchType, string $userRole): void
6060

6161
$this->assertTrue(count($buckets) >= 2);
6262

63+
$firstBucket = null;
6364
$inBucketFound = false;
6465
$outBucketFound = false;
6566
foreach ($buckets as $bucket) {
6667
if ($bucket['id'] == $this->getTestBucketId(self::STAGE_IN)) {
6768
$inBucketFound = true;
69+
$firstBucket = $bucket;
6870
}
6971
if ($bucket['id'] == $this->getTestBucketId(self::STAGE_OUT)) {
7072
$outBucketFound = true;
7173
}
7274
}
7375
$this->assertTrue($inBucketFound);
7476
$this->assertTrue($outBucketFound);
77+
$this->assertNotNull($firstBucket);
7578

76-
$firstBucket = reset($buckets);
79+
$this->assertArrayHasKey('id', $firstBucket);
80+
$this->assertSame($this->getTestBucketId(self::STAGE_IN), $firstBucket['id']);
81+
$this->assertArrayHasKey('name', $firstBucket);
7782
$this->assertArrayHasKey('displayName', $firstBucket);
7883
$this->assertNotEquals('', $firstBucket['displayName']);
7984
$this->assertArrayHasKey('created', $firstBucket);
85+
$this->assertArrayHasKey('uri', $firstBucket);
86+
$this->assertArrayHasKey('tables', $firstBucket);
87+
$this->assertArrayHasKey('created', $firstBucket);
88+
$this->assertArrayHasKey('lastChangeDate', $firstBucket);
89+
$this->assertArrayHasKey('updated', $firstBucket);
90+
$this->assertArrayHasKey('idBranch', $firstBucket);
91+
$this->assertArrayHasKey('stage', $firstBucket);
92+
$this->assertSame('in', $firstBucket['stage']);
93+
$this->assertArrayHasKey('description', $firstBucket);
94+
$this->assertArrayHasKey('dataSizeBytes', $firstBucket);
95+
$this->assertArrayHasKey('rowsCount', $firstBucket);
96+
$this->assertArrayHasKey('backend', $firstBucket);
97+
$this->assertArrayHasKey('sharing', $firstBucket);
98+
$this->assertArrayHasKey('databaseName', $firstBucket);
99+
$this->assertArrayHasKey('path', $firstBucket);
100+
$this->assertArrayHasKey('color', $firstBucket);
101+
$this->assertArrayHasKey('owner', $firstBucket);
102+
$this->assertArrayHasKey('backendPath', $firstBucket);
103+
$this->assertFalse($firstBucket['isReadOnly']);
104+
$this->assertFalse($firstBucket['isMaintenance']);
105+
$this->assertFalse($firstBucket['hasExternalSchema']);
106+
$this->assertFalse($firstBucket['isSnowflakeSharedDatabase']);
107+
80108
if ($devBranchType === ClientProvider::DEV_BRANCH) {
81109
$this->assertEquals($this->clientProvider->getExistingBranchForTestCase()['id'], $firstBucket['idBranch']);
82110
} elseif ($devBranchType === ClientProvider::DEFAULT_BRANCH) {
@@ -87,6 +115,9 @@ public function testBucketsList(string $devBranchType, string $userRole): void
87115
} else {
88116
throw new \Exception(sprintf('Unknown devBranchType "%s"', $devBranchType));
89117
}
118+
119+
//@phpstan-ignore-next-line
120+
$this->assertBucketBackendPath($firstBucket);
90121
}
91122

92123
/**
@@ -109,6 +140,8 @@ public function testBucketDetail(string $devBranchType, string $userRole): void
109140
$bucketId = $this->_testClient->createBucket(name: $bucketName, stage: self::STAGE_IN, color: '#00FF00');
110141

111142
$bucket = $this->_testClient->getBucket($bucketId);
143+
//@phpstan-ignore-next-line
144+
$this->assertBucketBackendPath($bucket);
112145
$this->assertEquals($branch['id'], $bucket['idBranch']);
113146

114147
$this->assertEquals($tokenData['owner']['defaultBackend'], $bucket['backend']);
@@ -149,6 +182,8 @@ public function testBucketDetail(string $devBranchType, string $userRole): void
149182
$bucketUpdateOptions = new BucketUpdateOptions($bucketId, $displayName);
150183
$bucketUpdateOptions->deleteColor();
151184
$bucket = $this->_testClient->updateBucket($bucketUpdateOptions);
185+
//@phpstan-ignore-next-line
186+
$this->assertBucketBackendPath($bucket);
152187
try {
153188
$this->_testClient->createBucket($displayName, self::STAGE_IN);
154189
$this->fail('Should throw exception');
@@ -246,6 +281,29 @@ public function testBucketDetail(string $devBranchType, string $userRole): void
246281
$this->_testClient->dropBucket($bucket['id']);
247282
}
248283

284+
285+
/**
286+
* @param array{
287+
* backendPath: string[],
288+
* backend: string,
289+
* path: string,
290+
* } $bucket
291+
*/
292+
private function assertBucketBackendPath(array $bucket): void
293+
{
294+
if ($bucket['backend'] === self::BACKEND_SNOWFLAKE) {
295+
$projectId = $this->getProjectId($this->_testClient);
296+
$this->assertCount(2, $bucket['backendPath']);
297+
$this->assertStringContainsString((string) $projectId, $bucket['backendPath'][0]);
298+
$this->assertSame($bucket['path'], $bucket['backendPath'][1]);
299+
} elseif ($bucket['backend'] === self::BACKEND_BIGQUERY) {
300+
$this->assertCount(1, $bucket['backendPath']);
301+
$this->assertSame($bucket['path'], $bucket['backendPath'][0]);
302+
} else {
303+
$this->fail('Unknown backend ' . $bucket['backend']);
304+
}
305+
}
306+
249307
private function assertBucketWithColumnMetadata(array $bucket): void
250308
{
251309
self::assertArrayHasKey('tables', $bucket);

0 commit comments

Comments
 (0)