Skip to content

Commit 0f1d707

Browse files
committed
Add normal table
1 parent 66da233 commit 0f1d707

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

tests/Backend/ReaderWorkspaces/WorkspacesReaderSharingTest.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
use Keboola\StorageApi\Components;
99
use Keboola\StorageApi\Options\Components\Configuration;
1010
use Keboola\StorageApi\Options\Components\ListComponentsOptions;
11-
use Keboola\StorageApi\Tokens;
1211
use Keboola\StorageApi\WorkspaceLoginType;
1312
use Keboola\StorageApi\Workspaces;
1413
use Keboola\TableBackendUtils\Escaping\Snowflake\SnowflakeQuote;
1514
use Keboola\Test\Backend\WorkspaceConnectionTrait;
1615
use Keboola\Test\Backend\WorkspaceCredentialsAssertTrait;
1716
use Keboola\Test\Backend\Workspaces\Backend\WorkspaceBackendFactory;
18-
use Keboola\Test\Backend\Workspaces\WorkspacesTestCase;
17+
use Keboola\Test\StorageApiTestCase;
1918
use Keboola\Test\Utils\PemKeyCertificateGenerator;
2019
use Keboola\Test\Utils\SnowflakeConnectionUtils;
2120

22-
class WorkspacesReaderSharingTest extends WorkspacesTestCase
21+
class WorkspacesReaderSharingTest extends StorageApiTestCase
2322
{
2423
use WorkspaceConnectionTrait;
2524
use WorkspaceCredentialsAssertTrait;
@@ -31,9 +30,7 @@ class WorkspacesReaderSharingTest extends WorkspacesTestCase
3130

3231
public function setUp(): void
3332
{
34-
$this->_client = $this->getDefaultClient();
35-
$this->tokens = new Tokens($this->_client);
36-
33+
parent::setUp();
3734
$linkClient = $this->getClient([
3835
'token' => STORAGE_API_LINKING_TOKEN,
3936
'url' => STORAGE_API_URL,
@@ -78,7 +75,7 @@ public function setUp(): void
7875
// unlink buckets
7976
$linkedBuckets = $linkClient->listBuckets();
8077
foreach ($linkedBuckets as $bucket) {
81-
$linkClient->dropBucket($bucket['id']);
78+
$linkClient->dropBucket($bucket['id'], ['force' => true]);
8279
}
8380

8481
$shareClient = $this->getClient([
@@ -133,14 +130,26 @@ public function testShareLinkAndLoadTableToReaderWorkspace(): void
133130
false,
134131
);
135132

133+
// Step 3.1: Create another table in the linked project that is not linked
134+
$nativeBucketInLinkedProject = $linkClient->createBucket($this->getTestBucketName($this->generateDescriptionForTestObject()), self::STAGE_IN);
135+
$notLinkedTable = $linkClient->createTableAsync(
136+
$nativeBucketInLinkedProject,
137+
'not-linked-table',
138+
new CsvFile(__DIR__ . '/../../_data/languages.csv'),
139+
);
140+
136141
// Step 4: Create a reader workspace
137142
$workspaces = new Workspaces($linkClient);
138-
$workspace = $this->prepareWorkspace(null, $linkClient);
143+
$workspace = $this->prepareWorkspace($linkClient);
139144

140145
// Step 5: Load the linked table into the reader workspace
141146
$linkedTableId = $linkedBucketId . '.languages';
142147
$workspaces->loadWorkspaceData($workspace['id'], [
143148
'input' => [
149+
[
150+
'source' => $notLinkedTable,
151+
'destination' => 'not-linked-table',
152+
],
144153
[
145154
'source' => $linkedTableId,
146155
'destination' => 'languages',
@@ -152,9 +161,11 @@ public function testShareLinkAndLoadTableToReaderWorkspace(): void
152161
$db = WorkspaceBackendFactory::createWorkspaceForSnowflakeDbal($workspace);
153162
$data = $db->fetchAll('languages');
154163
$this->assertCount(5, $data); // languages.csv has 5 rows
164+
$data = $db->fetchAll('not-linked-table');
165+
$this->assertCount(5, $data); // languages.csv has 5 rows
155166
}
156167

157-
private function prepareWorkspace(?array $options = null, $client): array
168+
private function prepareWorkspace(Client $client): array
158169
{
159170
$componentId = 'wr-db';
160171
$configurationId = 'main-1';
@@ -174,11 +185,11 @@ private function prepareWorkspace(?array $options = null, $client): array
174185
$workspace = $components->createConfigurationWorkspace(
175186
$componentId,
176187
$configurationId,
177-
$options ?? [
178-
'useCase' => 'reader',
179-
'backend' => 'snowflake',
180-
'loginType' => WorkspaceLoginType::SNOWFLAKE_SERVICE_KEYPAIR,
181-
'publicKey' => $key->getPublicKey(),
188+
[
189+
'useCase' => 'reader',
190+
'backend' => 'snowflake',
191+
'loginType' => WorkspaceLoginType::SNOWFLAKE_SERVICE_KEYPAIR,
192+
'publicKey' => $key->getPublicKey(),
182193
],
183194
);
184195

@@ -187,14 +198,6 @@ private function prepareWorkspace(?array $options = null, $client): array
187198
return $workspace;
188199
}
189200

190-
private function createWorkspaces(): Workspaces
191-
{
192-
$defaultBranchId = $this->getDefaultBranchId($this);
193-
$branchClient = $this->getBranchAwareDefaultClient($defaultBranchId);
194-
195-
return new Workspaces($branchClient);
196-
}
197-
198201
private static function dropReaderAccounts(): void
199202
{
200203
$accounts = self::fetchReadersAccountsForCurrentOrganization();

0 commit comments

Comments
 (0)