-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5811506
commit f29a9e2
Showing
52 changed files
with
443 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\DbWriter\TestsFunctional; | ||
|
||
use Keboola\DatadirTests\DatadirTestCase; | ||
use Keboola\DbWriter\Traits\CloseSshTunnelsTrait; | ||
use Keboola\DbWriter\Traits\DropAllTablesTrait; | ||
use Keboola\DbWriterAdapter\PDO\PdoConnection; | ||
use RuntimeException; | ||
|
||
class DatadirTest extends DatadirTestCase | ||
{ | ||
use CloseSshTunnelsTrait; | ||
use DropAllTablesTrait; | ||
|
||
public PdoConnection $connection; | ||
|
||
protected function getScript(): string | ||
{ | ||
return $this->getTestFileDir() . '/../../tests/Fixtures/run.php'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
putenv('KBC_COMPONENT_RUN_MODE=run'); | ||
|
||
// Test dir, eg. "/code/tests/functional/full-load-ok" | ||
$this->testProjectDir = $this->getTestFileDir() . '/' . $this->dataName(); | ||
$this->testTempDir = $this->temp->getTmpFolder(); | ||
|
||
$isSsl = str_starts_with((string) $this->dataName(), 'ssl-'); | ||
$this->connection = PdoTestConnection::createConnection(); | ||
$this->closeSshTunnels(); | ||
$this->dropAllTables($this->connection); | ||
|
||
// Load setUp.php file - used to init database state | ||
$setUpPhpFile = $this->testProjectDir . '/setUp.php'; | ||
if (file_exists($setUpPhpFile)) { | ||
// Get callback from file and check it | ||
$initCallback = require $setUpPhpFile; | ||
if (!is_callable($initCallback)) { | ||
throw new RuntimeException(sprintf('File "%s" must return callback!', $setUpPhpFile)); | ||
} | ||
|
||
// Invoke callback | ||
$initCallback($this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\DbWriter\TestsFunctional; | ||
|
||
use Keboola\Component\UserException; | ||
use Keboola\DbWriterAdapter\PDO\PdoConnection; | ||
use Psr\Log\NullLogger; | ||
|
||
class PdoTestConnection | ||
{ | ||
public static function getDbConfigArray(bool $ssl = false): array | ||
{ | ||
$config = [ | ||
'host' => getenv('COMMON_DB_HOST', true) ?: (string) getenv('COMMON_DB_HOST'), | ||
'port' => (string) getenv('COMMON_DB_PORT'), | ||
'user' => (string) getenv('COMMON_DB_USER'), | ||
'#password' => (string) getenv('COMMON_DB_PASSWORD'), | ||
'database' => (string) getenv('COMMON_DB_DATABASE'), | ||
]; | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* @throws UserException | ||
*/ | ||
public static function createConnection(): PdoConnection | ||
{ | ||
return new PdoConnection( | ||
new NullLogger(), | ||
sprintf( | ||
'mysql:host=%s;port=%s;dbname=%s;charset=utf8', | ||
self::getDbConfigArray()['host'], | ||
self::getDbConfigArray()['port'], | ||
self::getDbConfigArray()['database'], | ||
), | ||
self::getDbConfigArray()['user'], | ||
self::getDbConfigArray()['#password'], | ||
[], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"status":"success","tables":{"simple":[{"Field":"id","Type":"int(11)","Null":"NO","Key":"PRI","Default":null,"Extra":"auto_increment"},{"Field":"name","Type":"varchar(255)","Null":"NO","Key":"","Default":null,"Extra":""},{"Field":"value","Type":"int(11)","Null":"NO","Key":"","Default":null,"Extra":""}]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Keboola\DbWriter\TestsFunctional\DatadirTest; | ||
|
||
return function (DatadirTest $test): void { | ||
$sql = <<<SQL | ||
CREATE TABLE `simple` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`name` varchar(255) NOT NULL, | ||
`value` int(11) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | ||
SQL; | ||
|
||
$test->connection->exec($sql); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"action": "getTablesInfo", | ||
"parameters": { | ||
"writer_class": "Common", | ||
"data_dir": "/data", | ||
"db": { | ||
"driver": "mysql", | ||
"host": "%env(string:COMMON_DB_HOST)%", | ||
"port": "%env(string:COMMON_DB_PORT)%", | ||
"database": "%env(string:COMMON_DB_DATABASE)%", | ||
"user": "%env(string:COMMON_DB_USER)%", | ||
"#password": "%env(string:COMMON_DB_PASSWORD)%" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Creating PDO connection to "mysql:host=mysql;port=3306;dbname=testdb;charset=utf8". | ||
Table "encoding" created | ||
Data written to table "encoding". | ||
Temporary Table "%s" created | ||
Data written to table "%s". | ||
Table "simple" created | ||
Data upserted to table "simple". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"parameters": { | ||
"writer_class": "Common", | ||
"data_dir": "/data", | ||
"db": { | ||
"driver": "mysql", | ||
"host": "%env(string:COMMON_DB_HOST)%", | ||
"port": "%env(string:COMMON_DB_PORT)%", | ||
"database": "%env(string:COMMON_DB_DATABASE)%", | ||
"user": "%env(string:COMMON_DB_USER)%", | ||
"#password": "%env(string:COMMON_DB_PASSWORD)%" | ||
}, | ||
"tables": [ | ||
{ | ||
"tableId": "encoding", | ||
"dbName": "encoding", | ||
"export": true, | ||
"incremental": false, | ||
"primaryKey": [], | ||
"items": [ | ||
{ | ||
"name": "col1", | ||
"dbName": "col1", | ||
"type": "VARCHAR", | ||
"size": 255, | ||
"nullable": null, | ||
"default": null | ||
}, | ||
{ | ||
"name": "col2", | ||
"dbName": "col2", | ||
"type": "VARCHAR", | ||
"size": 255, | ||
"nullable": null, | ||
"default": null | ||
} | ||
] | ||
}, | ||
{ | ||
"tableId": "simple", | ||
"dbName": "simple", | ||
"export": true, | ||
"incremental": true, | ||
"primaryKey": [ | ||
"id" | ||
], | ||
"items": [ | ||
{ | ||
"name": "id", | ||
"dbName": "id", | ||
"type": "int", | ||
"size": null, | ||
"nullable": null, | ||
"default": null | ||
}, | ||
{ | ||
"name": "name", | ||
"dbName": "name", | ||
"type": "VARCHAR", | ||
"size": 255, | ||
"nullable": null, | ||
"default": null | ||
}, | ||
{ | ||
"name": "glasses", | ||
"dbName": "glasses", | ||
"type": "VARCHAR", | ||
"size": 20, | ||
"nullable": null, | ||
"default": null | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"storage": { | ||
"input": { | ||
"tables": [ | ||
{ | ||
"source": "encoding", | ||
"destination": "encoding.csv", | ||
"columns": [ | ||
"id", | ||
"name", | ||
"glasses", | ||
"age" | ||
] | ||
}, | ||
{ | ||
"source": "simple", | ||
"destination": "simple.csv", | ||
"columns": [ | ||
"id", | ||
"name", | ||
"glasses", | ||
"age" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\DbWriter\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
class Base extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->closeSshTunnels(); | ||
parent::setUp(); | ||
} | ||
|
||
protected function closeSshTunnels(): void | ||
{ | ||
# Close SSH tunnel if created | ||
$process = new Process(['sh', '-c', 'pgrep ssh | xargs -r kill']); | ||
$process->mustRun(); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"id","name","glasses" | ||
"7","Jakub Matejka","no" | ||
"8","Ondrej Popelka","no" | ||
"9","Pavel Dolezal","yes" | ||
"10","Klara Koudelova","yes" |
7 changes: 7 additions & 0 deletions
7
tests/phpunit/data/deprecated/in/tables/simple_increment.csv.manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"columns": [ | ||
"id", | ||
"name", | ||
"glasses" | ||
] | ||
} |
Oops, something went wrong.