Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add skipRegionValidation parameter #57

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ public function shouldMigrateStructureOnly(): bool
{
return $this->getValue(['parameters', 'migrateStructureOnly']);
}

public function shouldSkipRegionValidation(): bool
{
return $this->getValue(['parameters', 'skipRegionValidation']);
}
}
1 change: 1 addition & 0 deletions src/ConfigDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function getParametersDefinition(): ArrayNodeDefinition
->booleanNode('migrateNotifications')->defaultTrue()->end()
->booleanNode('migrateStructureOnly')->defaultFalse()->end()
->booleanNode('migrateSecrets')->defaultFalse()->end()
->booleanNode('skipRegionValidation')->defaultFalse()->end()
->enumNode('dataMode')->values(['sapi', 'database'])->defaultValue('sapi')->end()
->arrayNode('db')
->children()
Expand Down
4 changes: 4 additions & 0 deletions src/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Migrate

private bool $migrateStructureOnly;

private bool $skipRegionValidation;

public const OBSOLETE_COMPONENTS = [
'orchestrator',
'gooddata-writer',
Expand Down Expand Up @@ -99,6 +101,7 @@ public function __construct(
$this->migrateTriggers = $config->shouldMigrateTriggers();
$this->migrateNotifications = $config->shouldMigrateNotifications();
$this->migrateStructureOnly = $config->shouldMigrateStructureOnly();
$this->skipRegionValidation = $config->shouldSkipRegionValidation();
$this->logger = $logger;
$this->migrateDataMode = $config->getMigrateDataMode();
$this->db = $config->getDb();
Expand Down Expand Up @@ -162,6 +165,7 @@ private function backupSourceProject(string $backupId): void
'parameters' => [
'backupId' => $backupId,
'exportStructureOnly' => $this->directDataMigration || $this->migrateStructureOnly,
'skipRegionValidation' => $this->skipRegionValidation,
],
],
);
Expand Down
31 changes: 31 additions & 0 deletions tests/phpunit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,35 @@ public function testDisabledMigratePermanentFiles(): void

$this->assertFalse($config->shouldMigratePermanentFiles());
}

public function testSkipRegionValidation(): void
{
$config = new Config(
[
'parameters' => [
'sourceKbcUrl' => 'https://connection.keboola.com',
'#sourceKbcToken' => 'token',
'skipRegionValidation' => true,
],
],
new ConfigDefinition()
);

$this->assertTrue($config->shouldSkipRegionValidation());
}

public function testSkipRegionValidationDefaultValue(): void
{
$config = new Config(
[
'parameters' => [
'sourceKbcUrl' => 'https://connection.keboola.com',
'#sourceKbcToken' => 'token',
],
],
new ConfigDefinition()
);

$this->assertFalse($config->shouldSkipRegionValidation());
}
}
91 changes: 86 additions & 5 deletions tests/phpunit/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function testMigrateSuccess(
bool $restoreTriggers,
bool $restoreNotifications
): void {
/** @var JobRunner&MockObject $sourceJobRunnerMock */
$sourceJobRunnerMock = $this->createMock($jobRunnerClass);
/** @var JobRunner&MockObject $destJobRunnerMock */
$destJobRunnerMock = $this->createMock($jobRunnerClass);

// generate credentials
Expand Down Expand Up @@ -152,6 +154,7 @@ public function testMigrateSuccess(
$logsHandler = new TestHandler();
$logger = new Logger('tests', [$logsHandler]);

/** @var StorageClient&MockObject $sourceClientMock */
$sourceClientMock = $this->createMock(StorageClient::class);
$sourceClientMock
->method('apiGet')
Expand Down Expand Up @@ -206,8 +209,10 @@ public function testMigrateSuccess(
->willReturn('123')
;

/** @var StorageClient&MockObject $destClientMock */
$destClientMock = $this->createMock(StorageClient::class);

/** @var Migrations&MockObject $migrationsClientMock */
$migrationsClientMock = $this->createMock(Migrations::class);
$migrationsClientMock->expects(self::never())->method('migrateConfiguration');

Expand All @@ -230,7 +235,9 @@ public function testMigrateSuccess(

public function testMigrateSecretsSuccess(): void
{
/** @var JobRunner&MockObject $sourceJobRunnerMock */
$sourceJobRunnerMock = $this->createMock(QueueV2JobRunner::class);
/** @var JobRunner&MockObject $destJobRunnerMock */
$destJobRunnerMock = $this->createMock(QueueV2JobRunner::class);

// generate credentials
Expand Down Expand Up @@ -265,6 +272,7 @@ public function testMigrateSecretsSuccess(): void
$logsHandler = new TestHandler();
$logger = new Logger('tests', [$logsHandler]);

/** @var StorageClient&MockObject $sourceClientMock */
$sourceClientMock = $this->createMock(StorageClient::class);
$sourceClientMock
->method('apiGet')
Expand Down Expand Up @@ -319,8 +327,10 @@ public function testMigrateSecretsSuccess(): void
->willReturn('123')
;

/** @var StorageClient&MockObject $destClientMock */
$destClientMock = $this->createMock(StorageClient::class);

/** @var Migrations&MockObject $migrationsClientMock */
$migrationsClientMock = $this->createMock(Migrations::class);
$migrationsClientMock
->expects(self::exactly(3))
Expand Down Expand Up @@ -394,7 +404,9 @@ public function testMigrateSecretsSuccess(): void

public function testMigrateSnowflakeWritersWithSharedWorkspacesSuccess(): void
{
/** @var JobRunner&MockObject $sourceJobRunnerMock */
$sourceJobRunnerMock = $this->createMock(QueueV2JobRunner::class);
/** @var JobRunner&MockObject $destJobRunnerMock */
$destJobRunnerMock = $this->createMock(QueueV2JobRunner::class);

// generate credentials
Expand Down Expand Up @@ -492,6 +504,7 @@ public function testMigrateSnowflakeWritersWithSharedWorkspacesSuccess(): void
],
];

/** @var StorageClient&MockObject $sourceClientMock */
$sourceClientMock = $this->createMock(StorageClient::class);
$sourceClientMock
->method('apiGet')
Expand Down Expand Up @@ -526,6 +539,7 @@ public function testMigrateSnowflakeWritersWithSharedWorkspacesSuccess(): void
->willReturn('https://encryption.keboola.com')
;

/** @var StorageClient&MockObject $destClientMock */
$destClientMock = $this->createMock(StorageClient::class);
$destClientMock
->method('apiGet')
Expand All @@ -536,6 +550,7 @@ public function testMigrateSnowflakeWritersWithSharedWorkspacesSuccess(): void
})
;

/** @var Migrations&MockObject $migrationsClientMock */
$migrationsClientMock = $this->createMock(Migrations::class);
$migrationsClientMock
->expects(self::exactly(3))
Expand Down Expand Up @@ -1193,21 +1208,87 @@ private function mockAddMethodBackupProject(
MockObject $mockObject,
array $return,
bool $migrateDataOfTablesDirectly,
bool $exportStructureOnly = false
bool $exportStructureOnly = false,
bool $skipRegionValidation = false
): void {
$mockObject
$mockObject->expects($this->once())
->method('runJob')
->with(
Config::PROJECT_BACKUP_COMPONENT,
[
'parameters' => [
'backupId' => '123',
'exportStructureOnly' => $exportStructureOnly || $migrateDataOfTablesDirectly,
'exportStructureOnly' => $migrateDataOfTablesDirectly || $exportStructureOnly,
'skipRegionValidation' => $skipRegionValidation,
],
]
)
->willReturn($return)
;
->willReturn($return);
}

public function testSkipRegionValidation(): void
{
/** @var JobRunner&MockObject $sourceJobRunnerMock */
$sourceJobRunnerMock = $this->createMock(QueueV2JobRunner::class);
/** @var JobRunner&MockObject $destJobRunnerMock */
$destJobRunnerMock = $this->createMock(QueueV2JobRunner::class);

// generate credentials
$this->mockAddMethodGenerateS3ReadCredentials($sourceJobRunnerMock);
$this->mockAddMethodBackupProject(
$sourceJobRunnerMock,
[
'id' => '222',
'status' => 'success',
],
false,
false,
true
);

$destJobRunnerMock->method('runJob')
->willReturn([
'id' => '222',
'status' => 'success',
]);

$config = new Config(
[
'parameters' => [
'sourceKbcUrl' => 'https://connection.keboola.com',
'#sourceKbcToken' => 'token',
'skipRegionValidation' => true,
'directDataMigration' => false,
'migrateStructureOnly' => false,
],
],
new ConfigDefinition()
);

/** @var StorageClient&MockObject $sourceClientMock */
$sourceClientMock = $this->createMock(StorageClient::class);
$sourceClientMock->method('generateId')->willReturn('123');
$sourceClientMock->method('apiGet')->willReturn([]);
$sourceClientMock->method('getServiceUrl')->willReturn('https://encryption.keboola.com');

/** @var StorageClient&MockObject $destClientMock */
$destClientMock = $this->createMock(StorageClient::class);
/** @var Migrations&MockObject $migrationsClientMock */
$migrationsClientMock = $this->createMock(Migrations::class);

$migrate = new Migrate(
$config,
$sourceJobRunnerMock,
$destJobRunnerMock,
$sourceClientMock,
$destClientMock,
$migrationsClientMock,
'https://dest-stack/',
'dest-token',
new NullLogger(),
);

$migrate->run();
}

public function successMigrateDataProvider(): Generator
Expand Down