Skip to content

Commit acec942

Browse files
jirkasemmlerthemark147
authored andcommitted
test copy and clone
1 parent 9593d27 commit acec942

1 file changed

Lines changed: 85 additions & 2 deletions

File tree

tests/Backend/Snowflake/WorkspacesReaderTest.php

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Backend\Snowflake;
44

55
use Keboola\Csv\CsvFile;
6+
use Keboola\StorageApi\Components;
7+
use Keboola\StorageApi\Options\Components\Configuration;
8+
use Keboola\StorageApi\Options\Components\ListComponentsOptions;
69
use Keboola\StorageApi\Workspaces;
710
use Keboola\Test\Backend\WorkspaceConnectionTrait;
811
use Keboola\Test\Backend\WorkspaceCredentialsAssertTrait;
@@ -21,15 +24,41 @@ public function setUp(): void
2124
{
2225
parent::setUp();
2326
$this->initEmptyTestBucketsForParallelTests();
27+
28+
$components = new Components($this->_client);
29+
foreach ($components->listComponents() as $component) {
30+
foreach ($component['configurations'] as $configuration) {
31+
$components->deleteConfiguration($component['id'], $configuration['id']);
32+
}
33+
}
34+
35+
// erase all deleted configurations
36+
foreach ($components->listComponents((new ListComponentsOptions())->setIsDeleted(true)) as $component) {
37+
foreach ($component['configurations'] as $configuration) {
38+
$components->deleteConfiguration($component['id'], $configuration['id']);
39+
}
40+
}
2441
}
2542

2643
public function testLoadToReaderAccount(): void
2744
{
45+
$componentId = 'wr-db';
46+
$configurationId = 'main-1';
2847
$defaultBranchId = $this->getDefaultBranchId($this);
2948
$branchClient = $this->getBranchAwareDefaultClient($defaultBranchId);
49+
// create configuration
50+
$components = new Components($branchClient);
51+
$components->addConfiguration((new Configuration())
52+
->setComponentId('wr-db')
53+
->setConfigurationId('main-1')
54+
->setName('TMP_RA jirka')
55+
->setDescription('some desc'));
56+
57+
$components = new Components($branchClient);
3058
$workspaces = new Workspaces($branchClient);
3159

32-
$workspace = $workspaces->createWorkspace(['async' => false, 'useCase' => 'reader']);
60+
$workspace = $components->createConfigurationWorkspace($componentId, $configurationId, ['async' => false], false);
61+
// $workspace = $components->createConfigurationWorkspace($componentId, $configurationId, ['async' => false, 'useCase' => 'reader'], false);
3362

3463
//setup test tables
3564
$tableId = $this->_client->createTableAsync(
@@ -39,6 +68,58 @@ public function testLoadToReaderAccount(): void
3968
);
4069

4170
$workspaces->loadWorkspaceData($workspace['id'], [
71+
'input' => [
72+
[
73+
'source' => $tableId,
74+
'destination' => 'languages',
75+
],
76+
[
77+
'source' => $tableId,
78+
'destination' => 'languagesfiltered',
79+
'overwrite' => false,
80+
'whereColumn' => 'id',
81+
'whereValues' => [1],
82+
'whereOperator' => 'eq',
83+
],
84+
],
85+
]);
86+
// create the connection after LOAD!! because the schema will be created by LOAD
87+
$db = WorkspaceBackendFactory::createWorkspaceBackend($workspace);
88+
89+
$data = $db->fetchAll('languages');
90+
$this->assertCount(5, $data);
91+
92+
$data = $db->fetchAll('languagesfiltered');
93+
$this->assertCount(1, $data);
94+
}
95+
96+
public function testLoadCloneToReaderAccount(): void
97+
{
98+
$componentId = 'wr-db';
99+
$configurationId = 'main-1';
100+
$defaultBranchId = $this->getDefaultBranchId($this);
101+
$branchClient = $this->getBranchAwareDefaultClient($defaultBranchId);
102+
// create configuration
103+
$components = new Components($branchClient);
104+
$components->addConfiguration((new Configuration())
105+
->setComponentId('wr-db')
106+
->setConfigurationId('main-1')
107+
->setName('TMP_RA jirka')
108+
->setDescription('some desc'));
109+
110+
$components = new Components($branchClient);
111+
$workspaces = new Workspaces($branchClient);
112+
113+
$workspace = $components->createConfigurationWorkspace($componentId, $configurationId, ['async' => false], false);
114+
115+
//setup test tables
116+
$tableId = $this->_client->createTableAsync(
117+
$this->getTestBucketId(self::STAGE_IN),
118+
'languages',
119+
new CsvFile(__DIR__ . '/../../_data/languages.csv'),
120+
);
121+
122+
$workspaces->cloneIntoWorkspace($workspace['id'], [
42123
'input' => [
43124
[
44125
'source' => $tableId,
@@ -52,9 +133,11 @@ public function testLoadToReaderAccount(): void
52133
]);
53134
// create the connection after LOAD!! because the schema will be created by LOAD
54135
$db = WorkspaceBackendFactory::createWorkspaceBackend($workspace);
55-
$db->executeQuery('select 1');
136+
56137
$data = $db->fetchAll('languages');
138+
$this->assertCount(5, $data);
57139

140+
$data = $db->fetchAll('langs');
58141
$this->assertCount(5, $data);
59142
}
60143
}

0 commit comments

Comments
 (0)