Skip to content

Commit 20c6a89

Browse files
Merge pull request #1523 from keboola/zajca/ct-2180/task_migrate_BucketsController__deleteMetadataAction
CT-2180 fix metadata delete test after SF update
2 parents 2b4016c + 66f4ed3 commit 20c6a89

1 file changed

Lines changed: 79 additions & 54 deletions

File tree

tests/Common/MetadataTest.php

Lines changed: 79 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
class MetadataTest extends StorageApiTestCase
2121
{
2222
use MetadataUtils;
23-
const TEST_PROVIDER = 'test';
2423

24+
const TEST_PROVIDER = 'test';
2525
const TEST_METADATA_KEY_1 = 'test_metadata_key1';
2626
const TEST_METADATA_KEY_2 = 'test_metadata_key2';
27-
2827
const ISO8601_REGEXP = '/^([0-9]{4})-(1[0-2]|0[1-9])-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\+([0-9]{4})$/';
2928
// constants used for data providers in order to run it on all endpoints but also represents part of URL
3029
const ENDPOINT_TYPE_COLUMNS = 'columns';
@@ -64,7 +63,7 @@ public function setUp(): void
6463
$this->_testClient->createTableAsync($this->getTestBucketId(), 'test_table', new CsvFile(__DIR__ . '/../_data/users.csv'));
6564
}
6665

67-
/**
66+
/**
6867
* @dataProvider provideComponentsClientTypeBasedOnSuite
6968
* @group SOX-66
7069
*/
@@ -208,7 +207,7 @@ public function testColumnMetadataOverwrite(string $devBranchType, string $userR
208207
$this->assertSame($metadata[0]['value'], 'testValue');
209208
}
210209

211-
/**
210+
/**
212211
* @dataProvider provideComponentsClientTypeBasedOnSuite
213212
* @group SOX-66
214213
*/
@@ -281,7 +280,7 @@ public function testTableMetadata(string $devBranchType, string $userRole): void
281280
/**
282281
* @return void
283282
*/
284-
/**
283+
/**
285284
* @dataProvider provideComponentsClientTypeBasedOnSuite
286285
* @group SOX-66
287286
*/
@@ -405,7 +404,7 @@ public function testTableMetadataWithColumns(string $devBranchType, string $user
405404
}
406405
}
407406

408-
/**
407+
/**
409408
* @dataProvider provideComponentsClientTypeBasedOnSuite
410409
* @group SOX-66
411410
*/
@@ -447,10 +446,14 @@ public function testColumnMetadataWithColumnsWithIntegers(string $devBranchType,
447446
$this->assertArrayEqualsExceptKeys($mdForTable, $tableDetail['metadata'][0], ['id', 'provider', 'timestamp']);
448447

449448
$this->assertCount(1, $tableDetail['columnMetadata']);
450-
$this->assertArrayEqualsExceptKeys($mdForColumn, $tableDetail['columnMetadata'][0][0], ['id', 'provider', 'timestamp']);
449+
$this->assertArrayEqualsExceptKeys($mdForColumn, $tableDetail['columnMetadata'][0][0], [
450+
'id',
451+
'provider',
452+
'timestamp',
453+
]);
451454
}
452455

453-
/**
456+
/**
454457
* @dataProvider provideComponentsClientTypeBasedOnSuite
455458
* @group SOX-66
456459
*/
@@ -541,7 +544,7 @@ public function testTableMetadataWithColumnsWithIntegers(string $devBranchType,
541544
$this->assertEquals(self::TEST_PROVIDER, $metadata[0]['provider']);
542545
}
543546

544-
/**
547+
/**
545548
* @dataProvider provideComponentsClientTypeBasedOnSuite
546549
* @group SOX-66
547550
*/
@@ -632,7 +635,7 @@ public function testTableMetadataForTokenWithReadPrivilege(string $devBranchType
632635
$this->assertCount(1, $metadataArray);
633636
}
634637

635-
/**
638+
/**
636639
* @dataProvider provideComponentsClientTypeBasedOnSuite
637640
* @group SOX-66
638641
*/
@@ -677,7 +680,7 @@ public function testTableDeleteWithMetadata(string $devBranchType, string $userR
677680
$metadataApi->listTableMetadata($columnId);
678681
}
679682

680-
/**
683+
/**
681684
* @dataProvider provideComponentsClientTypeBasedOnSuite
682685
* @group SOX-66
683686
*/
@@ -786,7 +789,7 @@ public function testColumnMetadata(string $devBranchType, string $userRole): voi
786789
);
787790
}
788791

789-
/**
792+
/**
790793
* @dataProvider provideComponentsClientTypeBasedOnSuite
791794
* @group SOX-66
792795
*/
@@ -877,7 +880,7 @@ public function testColumnMetadataForTokenWithReadPrivilege(string $devBranchTyp
877880
$this->assertCount(1, $metadataArray);
878881
}
879882

880-
/**
883+
/**
881884
* @dataProvider provideComponentsClientTypeBasedOnSuite
882885
* @group SOX-66
883886
*/
@@ -911,15 +914,15 @@ public function testTableColumnDeleteWithMetadata(string $devBranchType, string
911914
$tableDetail = $this->_testClient->getTable($tableId);
912915
$this->assertEmpty($tableDetail['columnMetadata']);
913916

914-
$this->assertEquals(['id','name','city'], $tableDetail['columns']);
917+
$this->assertEquals(['id', 'name', 'city'], $tableDetail['columns']);
915918

916919
$this->expectException(ClientException::class);
917920
$this->expectExceptionCode(404);
918921

919922
$metadataApi->listColumnMetadata($columnId);
920923
}
921924

922-
/**
925+
/**
923926
* @dataProvider provideComponentsClientTypeBasedOnSuite
924927
* @group SOX-66
925928
*/
@@ -1025,8 +1028,12 @@ public function testInvalidMetadata(string $devBranchType, string $userRole, $ap
10251028
* @dataProvider apiEndpoints
10261029
* @group SOX-66
10271030
*/
1028-
public function testInvalidMetadataWhenMetadataIsNotArray(string $devBranchType, string $userRole, $apiEndpoint, $object): void
1029-
{
1031+
public function testInvalidMetadataWhenMetadataIsNotArray(
1032+
string $devBranchType,
1033+
string $userRole,
1034+
$apiEndpoint,
1035+
$object
1036+
): void {
10301037
$bucketId = self::getTestBucketId();
10311038
$objectId = $bucketId . $object;
10321039

@@ -1047,8 +1054,12 @@ public function testInvalidMetadataWhenMetadataIsNotArray(string $devBranchType,
10471054
* @dataProvider apiEndpoints
10481055
* @group SOX-66
10491056
*/
1050-
public function testInvalidMetadataWhenMetadataIsNotPresent(string $devBranchType, string $userRole, $apiEndpoint, $object): void
1051-
{
1057+
public function testInvalidMetadataWhenMetadataIsNotPresent(
1058+
string $devBranchType,
1059+
string $userRole,
1060+
$apiEndpoint,
1061+
$object
1062+
): void {
10521063
$bucketId = self::getTestBucketId();
10531064
$objectId = $bucketId . $object;
10541065

@@ -1069,44 +1080,58 @@ public function testInvalidMetadataWhenMetadataIsNotPresent(string $devBranchTyp
10691080
*/
10701081
public function testMetadata40xs(string $devBranchType, string $userRole, $apiEndpoint, $object): void
10711082
{
1072-
$bucketId = self::getTestBucketId();
1083+
$bucketId = $this->getTestBucketId();
10731084
$object = ($apiEndpoint === 'bucket') ? $bucketId : $bucketId . $object;
10741085

10751086
// test invalid number
1076-
try {
1077-
$this->deleteMetadata($apiEndpoint, $object, 9999999);
1078-
$this->fail('Invalid metadataId');
1079-
} catch (ClientException $e) {
1080-
$this->assertEquals(404, $e->getCode());
1081-
$this->assertEquals('storage.metadata.notFound', $e->getStringCode());
1082-
$this->assertEquals('The supplied metadata ID was not found', $e->getMessage());
1087+
if ($apiEndpoint === 'buckets') {
1088+
// test this on migrated endpoint
1089+
try {
1090+
$this->deleteMetadata($apiEndpoint, $object, 9999999);
1091+
$this->fail('Invalid metadataId');
1092+
} catch (ClientException $e) {
1093+
$this->assertEquals(404, $e->getCode());
1094+
$this->assertEquals('storage.metadata.notFound', $e->getStringCode());
1095+
$this->assertEquals(sprintf('Metadata "9999999" not found for bucket "%s".', $this->getTestBucketId()), $e->getMessage());
1096+
}
1097+
} else {
1098+
try {
1099+
$this->deleteMetadata($apiEndpoint, $object, 9999999);
1100+
$this->fail('Invalid metadataId');
1101+
} catch (ClientException $e) {
1102+
$this->assertEquals(404, $e->getCode());
1103+
$this->assertEquals('storage.metadata.notFound', $e->getStringCode());
1104+
$this->assertEquals('The supplied metadata ID was not found', $e->getMessage());
1105+
}
10831106
}
10841107

10851108
// test null
1086-
try {
1087-
$this->deleteMetadata($apiEndpoint, $object, null);
1088-
$this->fail('Invalid metadataId');
1089-
} catch (ClientException $e) {
1090-
$this->assertEquals(400, $e->getCode());
1091-
$this->assertEquals('APPLICATION_ERROR', $e->getStringCode());
1092-
$this->assertEquals('exceptions.storage.metadata.invalidDelete', $e->getMessage());
1093-
}
1094-
1095-
// not numeric value
1096-
try {
1097-
$this->deleteMetadata($apiEndpoint, $object, 'notNumber');
1098-
$this->fail('Invalid metadataId');
1099-
} catch (ClientException $e) {
1100-
$this->assertEquals(400, $e->getCode());
1101-
$this->assertEquals('APPLICATION_ERROR', $e->getStringCode());
1102-
$this->assertEquals(
1103-
'Argument "subResource" is expected to be type "int", value "notNumber" given.',
1104-
$e->getMessage(),
1105-
);
1109+
if ($apiEndpoint !== 'buckets') {
1110+
// don't test this on migrated endpoint, this had an extra handling in zend, 404 is returned from Symfony
1111+
try {
1112+
$this->deleteMetadata($apiEndpoint, $object, null);
1113+
$this->fail('Invalid metadataId');
1114+
} catch (ClientException $e) {
1115+
$this->assertEquals(400, $e->getCode());
1116+
$this->assertEquals('APPLICATION_ERROR', $e->getStringCode());
1117+
$this->assertEquals('exceptions.storage.metadata.invalidDelete', $e->getMessage());
1118+
}
1119+
// not numeric value
1120+
try {
1121+
$this->deleteMetadata($apiEndpoint, $object, 'notNumber');
1122+
$this->fail('Invalid metadataId');
1123+
} catch (ClientException $e) {
1124+
$this->assertEquals(400, $e->getCode());
1125+
$this->assertEquals('APPLICATION_ERROR', $e->getStringCode());
1126+
$this->assertEquals(
1127+
'Argument "subResource" is expected to be type "int", value "notNumber" given.',
1128+
$e->getMessage(),
1129+
);
1130+
}
11061131
}
11071132
}
11081133

1109-
/**
1134+
/**
11101135
* @dataProvider provideComponentsClientTypeBasedOnSuite
11111136
* @group SOX-66
11121137
*/
@@ -1138,7 +1163,7 @@ public function testInvalidProvider(string $devBranchType, string $userRole): vo
11381163
}
11391164
}
11401165

1141-
/**
1166+
/**
11421167
* @dataProvider provideComponentsClientTypeBasedOnSuite
11431168
* @group SOX-66
11441169
*/
@@ -1154,11 +1179,11 @@ public function testTryToRemoveForeignData(string $devBranchType, string $userRo
11541179
$anotherBucketId = $this->getTestBucketId(self::STAGE_OUT);
11551180

11561181
$this->expectException(ClientException::class);
1157-
$this->expectExceptionMessage('The supplied metadata ID was not found');
1182+
$this->expectExceptionMessage(sprintf('Metadata "%s" not found for bucket "%s".', $createdMetadata[0]['id'], $anotherBucketId));
11581183
$medataApi->deleteBucketMetadata($anotherBucketId, $createdMetadata[0]['id']);
11591184
}
11601185

1161-
/**
1186+
/**
11621187
* @dataProvider provideComponentsClientTypeBasedOnSuite
11631188
* @group SOX-66
11641189
*/
@@ -1174,11 +1199,11 @@ public function testTryToRemoveForeignMetadataFromTable(string $devBranchType, s
11741199
$createdMetadata = $medataApi->postTableMetadata($tableId, 'provider', [$md]);
11751200

11761201
$this->expectException(ClientException::class);
1177-
$this->expectExceptionMessage('The supplied metadata ID was not found');
1202+
$this->expectExceptionMessage(sprintf('Metadata "%s" not found for bucket "%s".', $createdMetadata[0]['id'], $this->getTestBucketId()));
11781203
$medataApi->deleteBucketMetadata($this->getTestBucketId(), $createdMetadata[0]['id']);
11791204
}
11801205

1181-
/**
1206+
/**
11821207
* @dataProvider provideComponentsClientTypeBasedOnSuite
11831208
* @group SOX-66
11841209
*/
@@ -1341,7 +1366,7 @@ private function getMetadataTestColumnId($tableId, $columnId)
13411366
return sprintf('%s.%s.%s', $this->getTestBucketId(), $tableId, $columnId);
13421367
}
13431368

1344-
/**
1369+
/**
13451370
* @dataProvider provideComponentsClientTypeBasedOnSuite
13461371
* @group SOX-66
13471372
*/

0 commit comments

Comments
 (0)