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

Fix compile no zip sync action #99

Merged
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
4 changes: 2 additions & 2 deletions src/Helper/DbtCompileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public static function getCompiledSqlFilesContent(string $directory): array
{
$filePaths = self::getCompiledSqlPaths($directory);

$filenames = array_map(fn($sqlFile) => (string) $sqlFile->getFilename(), $filePaths);
$filenames = array_map(fn($sqlFile) => $sqlFile->getFilename(), $filePaths);
reset($filePaths);

$contents = array_map(fn($sqlFile) => trim(
(string) file_get_contents($sqlFile->getPathname()),
), $filePaths);

$combineArray = (array) array_combine($filenames, $contents);
$combineArray = array_combine($filenames, $contents);
ksort($combineArray);

return $combineArray;
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ArtifactsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function writeResults(string $projectPath, string $step): void

switch ($stepDir) {
case 'dbt run':
$compiledSqlContent = DbtCompileHelper::getCompiledSqlFilesContent($targetPath);
$compiledSqlContent = json_encode(DbtCompileHelper::getCompiledSqlFilesContent($targetPath));
file_put_contents($artifactsPath . '/compiled_sql.json', $compiledSqlContent);

$manifestJson = (string) file_get_contents($targetPath . '/manifest.json');
Expand Down
70 changes: 54 additions & 16 deletions tests/functionalSyncActionsNoZip/DatadirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use DbtTransformation\Component;
use DbtTransformation\Service\ArtifactsService;
use Keboola\DatadirTests\DatadirTestCase;
use Keboola\DatadirTests\DatadirTestSpecificationInterface;
use Keboola\DatadirTests\Exception\DatadirTestsException;
use Keboola\StorageApi\Client as StorageClient;
use Keboola\StorageApi\Options\FileUploadOptions;
use Keboola\Temp\Temp;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Process;
use Throwable;

class DatadirTest extends DatadirTestCase
{
Expand Down Expand Up @@ -46,22 +48,13 @@ public function setUp(): void
$projectPath = __DIR__ . '/../phpunit/data';
$artifacts->writeResults($projectPath, 'dbt run');

self::assertFileExists($tmpFolder . '/artifacts/out/current/manifest.json');
self::assertFileExists($tmpFolder . '/artifacts/out/current/run_results.json');
self::assertFileExists($tmpFolder . '/artifacts/out/current/model_timing.json');

$storageClient->uploadFile(
$tmpFolder . '/artifacts/out/current/manifest.json',
$options,
);
$storageClient->uploadFile(
$tmpFolder . '/artifacts/out/current/run_results.json',
$options,
);
$storageClient->uploadFile(
$tmpFolder . '/artifacts/out/current/model_timing.json',
$options,
);
$files = ['manifest.json', 'run_results.json', 'model_timing.json', 'compiled_sql.json'];

foreach ($files as $file) {
$filePath = sprintf('%s/artifacts/out/current/%s', $tmpFolder, $file);
self::assertFileExists($filePath);
$storageClient->uploadFile($filePath, $options);
}

sleep(1);
}
Expand Down Expand Up @@ -100,4 +93,49 @@ public function tearDown(): void
$finder = new Finder();
$fs->remove($finder->in(__DIR__ . '/../../data'));
}

protected function assertMatchesSpecification(
DatadirTestSpecificationInterface $specification,
Process $runProcess,
string $tempDatadir,
): void {
if ($specification->getExpectedReturnCode() !== null) {
$this->assertProcessReturnCode($specification->getExpectedReturnCode(), $runProcess);
} else {
$this->assertNotSame(0, $runProcess->getExitCode(), 'Exit code should have been non-zero');
}
if ($specification->getExpectedStdout() !== null) {
try {
$this->assertStringMatchesFormat(
trim($specification->getExpectedStdout()),
trim($runProcess->getOutput()),
'Failed asserting stdout output',
);
} catch (Throwable $e) {
//dbt-compile output json is too large to be compared with assertStringMatchesFormat
if (str_contains($e->getMessage(), 'regular expression is too large')) {
self::assertEquals(
trim($specification->getExpectedStdout()),
trim($runProcess->getOutput()),
'Failed asserting stdout output',
);
} else {
throw $e;
}
}
}
if ($specification->getExpectedStderr() !== null) {
$this->assertStringMatchesFormat(
trim($specification->getExpectedStderr()),
trim($runProcess->getErrorOutput()),
'Failed asserting stderr output',
);
}
if ($specification->getExpectedOutDirectory() !== null) {
$this->assertDirectoryContentsSame(
$specification->getExpectedOutDirectory(),
$tempDatadir . '/out',
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"componentId": "keboola.dbt-transformation",
"action": "dbtCompile",
"artifacts": {
"options": {
"zip": false
}
},
"parameters": {
"configId": "12345"
}
}
Loading