Skip to content

Commit

Permalink
CT-1386 - backend configuration provider
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtabiberle committed Apr 24, 2024
1 parent 5d6ffe4 commit bbf1302
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
19 changes: 19 additions & 0 deletions tests/BackendConfigurationProviderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace Keboola\ManageApiTest;

trait BackendConfigurationProviderTrait
{
public function getSnowflakeBackendCreateOptions(): array
{
return [
'backend' => 'snowflake',
'host' => getenv('KBC_TEST_SNOWFLAKE_HOST'),
'warehouse' => getenv('KBC_TEST_SNOWFLAKE_WAREHOUSE'),
'username' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_NAME'),
'password' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_PASSWORD'),
'region' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_REGION'),
'owner' => 'keboola',
];
}
}
17 changes: 3 additions & 14 deletions tests/ProjectStorageBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class ProjectStorageBackendTest extends ClientTestCase
{
use BackendConfigurationProviderTrait;

public function supportedNonDefaultBackends(): array
{
return [
Expand Down Expand Up @@ -127,7 +129,7 @@ public function testProjectStorageAssignBackendFailedWithNonNumericBackendId():
}

$this->client->removeProjectStorageBackend($project['id'], $project['backends']['snowflake']['id']);
$backend = $this->client->createStorageBackend($this->getBackendCreateOptions());
$backend = $this->client->createStorageBackend($this->getSnowflakeBackendCreateOptions());

// ensure, that backend ID is passed as string into body
$requestOptions['body'] = '{"storageBackendId": "'.$backend['id'].'"}';
Expand All @@ -138,19 +140,6 @@ public function testProjectStorageAssignBackendFailedWithNonNumericBackendId():
$this->client->purgeDeletedProject($project['id']);
}

public function getBackendCreateOptions(): array
{
return [
'backend' => 'snowflake',
'host' => getenv('KBC_TEST_SNOWFLAKE_HOST'),
'warehouse' => getenv('KBC_TEST_SNOWFLAKE_WAREHOUSE'),
'username' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_NAME'),
'password' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_PASSWORD'),
'region' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_REGION'),
'owner' => 'keboola',
];
}

public function testStorageBackendRemove()
{
$name = 'My org';
Expand Down
23 changes: 6 additions & 17 deletions tests/StorageBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

class StorageBackendTest extends ClientTestCase
{
use BackendConfigurationProviderTrait;

public function testOnlySuperadminCanRegisterStorageBackend(): void
{
$newBackend = $this->client->createStorageBackend($this->getBackendCreateOptions());
$newBackend = $this->client->createStorageBackend($this->getSnowflakeBackendCreateOptions());
$this->assertSame($newBackend['backend'], 'snowflake');
$this->assertBackendExist($newBackend['id']);
$this->client->removeStorageBackend($newBackend['id']);

$newBackend = $this->normalUserClient->createStorageBackend($this->getBackendCreateOptions());
$newBackend = $this->normalUserClient->createStorageBackend($this->getSnowflakeBackendCreateOptions());
$this->assertSame($newBackend['backend'], 'snowflake');
$this->assertBackendExist($newBackend['id']);
$this->client->removeStorageBackend($newBackend['id']);
Expand Down Expand Up @@ -127,7 +129,7 @@ public function testCreateStorageBackend(array $options)
public function storageBackendOptionsProvider(): iterable
{
yield 'snowflake' => [
$this->getBackendCreateOptions(),
$this->getSnowflakeBackendCreateOptions(),
];
yield 'snowflake with dynamic backends' => [
$this->getBackendCreateOptionsWithDynamicBackends(),
Expand All @@ -136,7 +138,7 @@ public function storageBackendOptionsProvider(): iterable

public function storageBackendOptionsProviderForUpdate(): iterable
{
$create = $this->getBackendCreateOptions();
$create = $this->getSnowflakeBackendCreateOptions();
yield 'snowflake update password' => [
$create,
[
Expand Down Expand Up @@ -273,19 +275,6 @@ private function assertBackendNotExist(int $backendId): void
$this->assertFalse($hasBackend);
}

public function getBackendCreateOptions(): array
{
return [
'backend' => 'snowflake',
'host' => getenv('KBC_TEST_SNOWFLAKE_HOST'),
'warehouse' => getenv('KBC_TEST_SNOWFLAKE_WAREHOUSE'),
'username' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_NAME'),
'password' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_PASSWORD'),
'region' => getenv('KBC_TEST_SNOWFLAKE_BACKEND_REGION'),
'owner' => 'keboola',
];
}

public function getBackendCreateOptionsWithDynamicBackends(): array
{
return [
Expand Down

0 comments on commit bbf1302

Please sign in to comment.