22
33namespace Keboola \Test \Backend \Snowflake ;
44
5+ use Generator ;
56use Keboola \Csv \CsvFile ;
67use Keboola \StorageApi \Client ;
78use Keboola \StorageApi \ClientException ;
@@ -19,7 +20,7 @@ class CloneIntoWorkspaceTest extends ParallelWorkspacesTestCase
1920 /**
2021 * @dataProvider cloneProvider
2122 */
22- public function testClone (int $ aliasNestingLevel ): void
23+ public function testClone (int $ aliasNestingLevel, string $ method , array $ extraInput ): void
2324 {
2425 $ this ->initEvents ($ this ->workspaceSapiClient );
2526
@@ -38,11 +39,12 @@ public function testClone(int $aliasNestingLevel): void
3839 $ runId = $ this ->workspaceSapiClient ->generateRunId ();
3940 $ this ->workspaceSapiClient ->setRunId ($ runId );
4041
41- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
42+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
4243 'input ' => [
4344 [
4445 'source ' => $ sourceTableId ,
4546 'destination ' => 'languagesDetails ' ,
47+ ...$ extraInput ,
4648 ],
4749 ],
4850 ]);
@@ -125,12 +127,13 @@ public function testClone(int $aliasNestingLevel): void
125127 }
126128
127129 // clone again but drop timestamp
128- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
130+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
129131 'input ' => [
130132 [
131133 'source ' => $ sourceTableId ,
132134 'destination ' => 'languagesDetailsNoTimestamp ' ,
133135 'dropTimestampColumn ' => true ,
136+ ...$ extraInput ,
134137 ],
135138 ],
136139 ]);
@@ -156,22 +159,50 @@ public function testClone(int $aliasNestingLevel): void
156159 );
157160 }
158161
159- public function cloneProvider (): array
162+ /**
163+ * @return Generator<string, array{method: string, extraInputsOptions: array, operationName: string}>
164+ */
165+ public function cloneEndpointProvider (): Generator
160166 {
161- return [
162- 'normal table ' => [
163- 0 ,
167+ yield 'cloneUsingCloneEndpoint ' => [
168+ 'method ' => 'cloneIntoWorkspace ' ,
169+ 'extraInputsOptions ' => [],
170+ 'operationName ' => 'workspaceLoadClone ' ,
171+ ];
172+ yield 'cloneUsingLoadEndpoint ' => [
173+ 'method ' => 'loadWorkspaceData ' ,
174+ 'extraInputsOptions ' => [
175+ 'loadType ' => 'CLONE ' ,
164176 ],
165- 'simple alias ' => [
177+ 'operationName ' => 'workspaceLoad ' ,
178+ ];
179+ }
180+
181+ public function cloneProvider (): Generator
182+ {
183+ foreach ($ this ->cloneEndpointProvider () as $ name => $ data ) {
184+ yield $ name . ' - normal table ' => [
185+ 0 ,
186+ $ data ['method ' ],
187+ $ data ['extraInputsOptions ' ],
188+ ];
189+ yield $ name . ' - simple alias ' => [
166190 1 ,
167- ],
168- 'simple alias 2 levels ' => [
191+ $ data ['method ' ],
192+ $ data ['extraInputsOptions ' ],
193+ ];
194+ yield $ name . ' - simple alias 2 levels ' => [
169195 2 ,
170- ],
171- ];
196+ $ data ['method ' ],
197+ $ data ['extraInputsOptions ' ],
198+ ];
199+ }
172200 }
173201
174- public function testCloneMultipleTables (): void
202+ /**
203+ * @dataProvider cloneEndpointProvider
204+ */
205+ public function testCloneMultipleTables (string $ method , array $ extraInput , string $ operationName ): void
175206 {
176207 $ bucketId = $ this ->getTestBucketId (self ::STAGE_IN );
177208 $ table1Id = $ this ->workspaceSapiClient ->createTableAsync (
@@ -189,22 +220,24 @@ public function testCloneMultipleTables(): void
189220 $ workspacesClient = new Workspaces ($ this ->workspaceSapiClient );
190221 $ workspace = $ this ->initTestWorkspace ();
191222
192- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
223+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
193224 'input ' => [
194225 [
195226 'source ' => $ table1Id ,
196227 'destination ' => 'languages ' ,
228+ ...$ extraInput ,
197229 ],
198230 [
199231 'source ' => $ table2Id ,
200232 'destination ' => 'rates ' ,
233+ ...$ extraInput ,
201234 ],
202235 ],
203236 ]);
204237
205238 $ actualJob = null ;
206239 foreach ($ this ->workspaceSapiClient ->listJobs () as $ job ) {
207- if ($ job ['operationName ' ] === ' workspaceLoadClone ' ) {
240+ if ($ job ['operationName ' ] === $ operationName ) {
208241 if ((int ) $ job ['operationParams ' ]['workspaceId ' ] === $ workspace ['id ' ]) {
209242 $ actualJob = $ job ;
210243 }
@@ -224,7 +257,7 @@ public function testCloneMultipleTables(): void
224257 * @dataProvider aliasSettingsProvider
225258 * @param array $aliasSettings
226259 */
227- public function testCloneOtherAliasesNotAllowed (array $ aliasSettings ): void
260+ public function testCloneOtherAliasesNotAllowed (array $ aliasSettings, string $ method , array $ extraInput ): void
228261 {
229262 $ sourceBucketId = $ this ->getTestBucketId ();
230263 $ sourceTableId = $ this ->createTableFromFile (
@@ -244,17 +277,21 @@ public function testCloneOtherAliasesNotAllowed(array $aliasSettings): void
244277 $ workspace = $ this ->initTestWorkspace ();
245278
246279 $ this ->expectException (Exception::class);
247- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
280+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
248281 'input ' => [
249282 [
250283 'source ' => $ aliasTableId ,
251284 'destination ' => 'languagesDetails ' ,
285+ ...$ extraInput ,
252286 ],
253287 ],
254288 ]);
255289 }
256290
257- public function testClonePreserveOffByDefault (): void
291+ /**
292+ * @dataProvider cloneEndpointProvider
293+ */
294+ public function testClonePreserveOffByDefault (string $ method , array $ extraInput ): void
258295 {
259296 $ sourceBucketId = $ this ->getTestBucketId ();
260297 $ sourceTableId = $ this ->createTableFromFile (
@@ -267,21 +304,23 @@ public function testClonePreserveOffByDefault(): void
267304 $ workspace = $ this ->initTestWorkspace ();
268305
269306 // first load
270- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
307+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
271308 'input ' => [
272309 [
273310 'source ' => $ sourceTableId ,
274311 'destination ' => 'languagesDetails ' ,
312+ ...$ extraInput ,
275313 ],
276314 ],
277315 ]);
278316
279317 // second load will overwrite
280- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
318+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
281319 'input ' => [
282320 [
283321 'source ' => $ sourceTableId ,
284322 'destination ' => 'languages-2 ' ,
323+ ...$ extraInput ,
285324 ],
286325 ],
287326 ]);
@@ -291,7 +330,10 @@ public function testClonePreserveOffByDefault(): void
291330 $ this ->assertEquals (['languages-2 ' ], $ backendTables );
292331 }
293332
294- public function testClonePreserve (): void
333+ /**
334+ * @dataProvider cloneEndpointProvider
335+ */
336+ public function testClonePreserve (string $ method , array $ extraInput ): void
295337 {
296338 $ sourceBucketId = $ this ->getTestBucketId ();
297339 $ sourceTableId = $ this ->createTableFromFile (
@@ -304,21 +346,23 @@ public function testClonePreserve(): void
304346 $ workspace = $ this ->initTestWorkspace ();
305347
306348 // first load
307- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
349+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
308350 'input ' => [
309351 [
310352 'source ' => $ sourceTableId ,
311353 'destination ' => 'languagesDetails ' ,
354+ ...$ extraInput ,
312355 ],
313356 ],
314357 ]);
315358
316359 // second load with preserve
317- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
360+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
318361 'input ' => [
319362 [
320363 'source ' => $ sourceTableId ,
321364 'destination ' => 'languages-2 ' ,
365+ ...$ extraInput ,
322366 ],
323367 ],
324368 'preserve ' => true ,
@@ -335,7 +379,10 @@ public function testClonePreserve(): void
335379 );
336380 }
337381
338- public function testTableAlreadyExistsAndOverwrite (): void
382+ /**
383+ * @dataProvider cloneEndpointProvider
384+ */
385+ public function testTableAlreadyExistsAndOverwrite (string $ method , array $ extraInput ): void
339386 {
340387 $ description = $ this ->generateDescriptionForTestObject ();
341388 $ workspaces = new Workspaces ($ this ->workspaceSapiClient );
@@ -384,13 +431,14 @@ public function testTableAlreadyExistsAndOverwrite(): void
384431 );
385432
386433 // first load
387- $ workspaces ->cloneIntoWorkspace (
434+ $ workspaces ->{ $ method } (
388435 $ workspace ['id ' ],
389436 [
390437 'input ' => [
391438 [
392439 'source ' => $ tableId ,
393440 'destination ' => 'Langs ' ,
441+ ...$ extraInput ,
394442 ],
395443 ],
396444 ],
@@ -402,13 +450,14 @@ public function testTableAlreadyExistsAndOverwrite(): void
402450
403451 // second load of same table with preserve
404452 try {
405- $ workspaces ->cloneIntoWorkspace (
453+ $ workspaces ->{ $ method } (
406454 $ workspace ['id ' ],
407455 [
408456 'input ' => [
409457 [
410458 'source ' => $ tableId ,
411459 'destination ' => 'Langs ' ,
460+ ...$ extraInput ,
412461 ],
413462 ],
414463 'preserve ' => true ,
@@ -421,12 +470,13 @@ public function testTableAlreadyExistsAndOverwrite(): void
421470
422471 try {
423472 // Invalid option combination
424- $ workspaces ->cloneIntoWorkspace ($ workspace ['id ' ], [
473+ $ workspaces ->{ $ method } ($ workspace ['id ' ], [
425474 'input ' => [
426475 [
427476 'source ' => $ tableId ,
428477 'destination ' => 'Langs ' ,
429478 'overwrite ' => true ,
479+ ...$ extraInput ,
430480 ],
431481 ],
432482 'preserve ' => false ,
@@ -437,12 +487,13 @@ public function testTableAlreadyExistsAndOverwrite(): void
437487 }
438488
439489 // third load table with more rows, preserve and overwrite
440- $ workspaces ->cloneIntoWorkspace ($ workspace ['id ' ], [
490+ $ workspaces ->{ $ method } ($ workspace ['id ' ], [
441491 'input ' => [
442492 [
443493 'source ' => $ linkedBucketId . '.languagesDetails2 ' ,
444494 'destination ' => 'Langs ' ,
445495 'overwrite ' => true ,
496+ ...$ extraInput ,
446497 ],
447498 ],
448499 'preserve ' => true ,
@@ -452,13 +503,16 @@ public function testTableAlreadyExistsAndOverwrite(): void
452503 $ this ->assertCount (6 , $ workspaceTableData );
453504 }
454505
455- public function testCloneWithWrongInput (): void
506+ /**
507+ * @dataProvider cloneEndpointProvider
508+ */
509+ public function testCloneWithWrongInput (string $ method ): void
456510 {
457511 $ workspacesClient = new Workspaces ($ this ->workspaceSapiClient );
458512 $ workspace = $ this ->initTestWorkspace ();
459513
460514 try {
461- $ workspacesClient ->cloneIntoWorkspace ($ workspace ['id ' ], [
515+ $ workspacesClient ->{ $ method } ($ workspace ['id ' ], [
462516 'input ' => 'this is not array ' ,
463517 ]);
464518 $ this ->fail ('Test should not reach this line ' );
@@ -472,25 +526,29 @@ public function testCloneWithWrongInput(): void
472526 }
473527 }
474528
475- public function aliasSettingsProvider ()
529+ public function aliasSettingsProvider (): Generator
476530 {
477- return [
478- ' filtered alias ' => [
531+ foreach ( $ this -> cloneEndpointProvider () as $ name => $ data ) {
532+ yield $ name . ' - filtered alias ' => [
479533 [
480534 'aliasFilter ' => [
481535 'column ' => 'id ' ,
482536 'values ' => [26 ],
483537 ],
484538 ],
485- ],
486- 'selected columns ' => [
539+ $ data ['method ' ],
540+ $ data ['extraInputsOptions ' ],
541+ ];
542+ yield $ name . ' - selected columns ' => [
487543 [
488544 'aliasColumns ' => [
489545 'id ' ,
490546 ],
491547 ],
492- ],
493- ];
548+ $ data ['method ' ],
549+ $ data ['extraInputsOptions ' ],
550+ ];
551+ }
494552 }
495553
496554 public function testQueueWorkspaceCloneInto (): void
0 commit comments