Skip to content

Commit

Permalink
Merge pull request #3 from keboola/ondra-use-component-id-over-stack-…
Browse files Browse the repository at this point in the history
…parameters

use componentId over stack parameters
  • Loading branch information
ondrajodas committed Oct 26, 2020
2 parents 48e70aa + 2844720 commit de8cab0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/Component.php
Expand Up @@ -44,14 +44,17 @@ public function run(): void

$sourceProjectComponentsApi = new Components($sourceProjectClient);

$componentId = $config->getImageParameters()['componentId'];

$migrate = new MigrateWriter(
$sourceProjectComponentsApi,
new Components($destProjectClient),
new Workspaces($destProjectClient)
new Workspaces($destProjectClient),
$componentId
);
$writers = $sourceProjectComponentsApi->listComponentConfigurations(
(new ListComponentConfigurationsOptions())
->setComponentId(MigrateWriter::COMPONENT_ID)
->setComponentId($componentId)
);
foreach ($writers as $writer) {
$logger->info(sprintf(
Expand Down
13 changes: 9 additions & 4 deletions src/MigrateWriter.php
Expand Up @@ -15,7 +15,10 @@ class MigrateWriter
'keboola.snowflakecomputing.com',
];

public const COMPONENT_ID = 'keboola.wr-db-snowflake';
public const DEFAULT_COMPONENT_ID = 'keboola.wr-db-snowflake';

/** @var string $componentId */
private $componentId;

/** @var Components */
private $sourceComponentsApi;
Expand All @@ -29,17 +32,19 @@ class MigrateWriter
public function __construct(
Components $sourceComponentsApi,
Components $destComponentsApi,
Workspaces $destWorkspacesApi
Workspaces $destWorkspacesApi,
string $componentId = self::DEFAULT_COMPONENT_ID
) {
$this->sourceComponentsApi = $sourceComponentsApi;
$this->destComponentsApi = $destComponentsApi;
$this->destWorkspacesApi = $destWorkspacesApi;
$this->componentId = $componentId;
}

public function migrate(string $configurationId): void
{
$configuration = $this->sourceComponentsApi->getConfiguration(
self::COMPONENT_ID,
$this->componentId,
$configurationId
);

Expand All @@ -53,7 +58,7 @@ public function migrate(string $configurationId): void

$newConfiguration = new Configuration();
$newConfiguration
->setComponentId(self::COMPONENT_ID)
->setComponentId($this->componentId)
->setConfigurationId($configuration['id'])
->setDescription($configuration['description'])
->setName($configuration['name'])
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/MigrateWriterTest.php
Expand Up @@ -62,7 +62,7 @@ public function testMigrateNonKeboolaWriter(): void
$sourceComponentsApi->expects($this->once())
->method('getConfiguration')
->with(
MigrateWriter::COMPONENT_ID,
MigrateWriter::DEFAULT_COMPONENT_ID,
'12'
)
->willReturn($sourceConfiguration);
Expand All @@ -74,7 +74,7 @@ public function testMigrateNonKeboolaWriter(): void
->method('addConfiguration')
->with($this->callback(function (Configuration $configuration) use ($sourceConfiguration) {
$this->assertEquals($sourceConfiguration['id'], $configuration->getConfigurationId());
$this->assertEquals(MigrateWriter::COMPONENT_ID, $configuration->getComponentId());
$this->assertEquals(MigrateWriter::DEFAULT_COMPONENT_ID, $configuration->getComponentId());
$this->assertEquals($sourceConfiguration['name'], $configuration->getName());
$this->assertEquals($sourceConfiguration['description'], $configuration->getDescription());
$this->assertEquals($sourceConfiguration['configuration'], $configuration->getConfiguration());
Expand Down Expand Up @@ -134,7 +134,7 @@ public function testMigrateKeboolaSnowflakeWriter(): void
$sourceComponentsApi->expects($this->once())
->method('getConfiguration')
->with(
MigrateWriter::COMPONENT_ID,
MigrateWriter::DEFAULT_COMPONENT_ID,
'12'
)
->willReturn($sourceConfiguration);
Expand Down Expand Up @@ -190,7 +190,7 @@ public function testMigrateKeboolaSnowflakeWriter(): void
$expectedNewConfigurationData
) {
$this->assertEquals($sourceConfiguration['id'], $configuration->getConfigurationId());
$this->assertEquals(MigrateWriter::COMPONENT_ID, $configuration->getComponentId());
$this->assertEquals(MigrateWriter::DEFAULT_COMPONENT_ID, $configuration->getComponentId());
$this->assertEquals($sourceConfiguration['name'], $configuration->getName());
$this->assertEquals($sourceConfiguration['description'], $configuration->getDescription());
$this->assertEquals($expectedNewConfigurationData, $configuration->getConfiguration());
Expand Down

0 comments on commit de8cab0

Please sign in to comment.