Skip to content

Commit

Permalink
Merge pull request #72 from keboola/ujovlado-CM-371
Browse files Browse the repository at this point in the history
Fix check for sqls in log file
  • Loading branch information
ujovlado authored Nov 22, 2022
2 parents 1832fd4 + de882b8 commit 5e03719
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Helper/ParseLogFileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getSqls(): Generator
}

foreach ($logs as $log) {
if ($log && array_key_exists('sql', $log['data'])) {
if ($log && isset($log['data']['sql'])) {
yield $this->queryExcerpt(trim(preg_replace('!/\*.*?\*/!s', '', $log['data']['sql'])));
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/Helper/ParseLogFileHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace DbtTransformation\Tests\Helper;

use DbtTransformation\Helper\ParseLogFileHelper;
use Keboola\Temp\Temp;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

class ParseLogFileHelperTest extends TestCase
{
Expand All @@ -20,6 +22,31 @@ public function testGetSqlsFromDbtLogFile(): void
}
}

public function testMissingLogData(): void
{
$temp = new Temp('missing-log-data');
$fs = new Filesystem();
$fileName = $temp->getTmpFolder() . '/dbt.log';
$content = <<<LOG
"some string"
{"data":{"sql": "SELECT 1"}}
"another string"
{"data":{"sql": "SELECT 2"}}
LOG;
$fs->dumpFile($fileName, $content);

$expected = [
'SELECT 1',
'SELECT 2',
];

$sqls = (new ParseLogFileHelper($fileName))->getSqls();

foreach ($sqls as $key => $sql) {
$this->assertEquals($expected[$key], $sql);
}
}

/**
* @return string[]
*/
Expand Down

0 comments on commit 5e03719

Please sign in to comment.