Skip to content

Commit

Permalink
SShTunnel test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Nov 20, 2023
1 parent e66397a commit 85c3fa4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
"Keboola\\DbWriter\\Traits\\": "tests/traits/",
"Keboola\\DbWriter\\TestsTraits\\": "tests/traits/",
"Keboola\\DbWriter\\TestsFunctional\\": "tests/functional/",
"Keboola\\DbWriter\\Tests\\": "tests/phpunit/"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/DatadirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Keboola\Csv\InvalidArgumentException;
use Keboola\DatadirTests\DatadirTestCase;
use Keboola\DatadirTests\DatadirTestSpecificationInterface;
use Keboola\DbWriter\Traits\CloseSshTunnelsTrait;
use Keboola\DbWriter\Traits\DropAllTablesTrait;
use Keboola\DbWriter\TestsTraits\CloseSshTunnelsTrait;
use Keboola\DbWriter\TestsTraits\DropAllTablesTrait;
use Keboola\DbWriterAdapter\PDO\PdoConnection;
use RuntimeException;

Expand Down
56 changes: 56 additions & 0 deletions tests/phpunit/SshTunnelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Keboola\DbWriter\Tests;

use Keboola\DbWriter\TestsTraits\CloseSshTunnelsTrait;
use Keboola\DbWriter\Writer\SshTunnel;
use Keboola\DbWriterConfig\Configuration\ValueObject\DatabaseConfig;
use PHPUnit\Framework\TestCase;
use Psr\Log\Test\TestLogger;

class SshTunnelTest extends TestCase
{
use CloseSshTunnelsTrait;

public function tearDown(): void
{
parent::tearDown();
$this->closeSshTunnels();
}

public function testOpenTunnel(): void
{
$logger = new TestLogger();

$sshTunnel = new SshTunnel($logger);

$databaseConfig = DatabaseConfig::fromArray(self::getDatabaseConfig());

$newConfig = $sshTunnel->createSshTunnel($databaseConfig);

self::assertEquals('127.0.0.1', $newConfig->getHost());
self::assertEquals('33006', $newConfig->getPort());
}

private static function getDatabaseConfig(): array
{
return [
'host' => (string) getenv('COMMON_DB_HOST'),
'port' => (string) getenv('COMMON_DB_PORT'),
'database' => (string) getenv('COMMON_DB_DATABASE'),
'user' => (string) getenv('COMMON_DB_USER'),
'#password' => (string) getenv('COMMON_DB_PASSWORD'),
'schema' => (string) getenv('COMMON_DB_SCHEMA'),
'ssh' => [
'enabled' => true,
'keys' => [
'#private' => (string) file_get_contents('/root/.ssh/id_rsa'),
'public' => (string) file_get_contents('/root/.ssh/id_rsa.pub'),
],
'sshHost' => 'sshproxy',
],
];
}
}
2 changes: 1 addition & 1 deletion tests/traits/CloseSshTunnelsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Keboola\DbWriter\Traits;
namespace Keboola\DbWriter\TestsTraits;

use Symfony\Component\Process\Process;

Expand Down
2 changes: 1 addition & 1 deletion tests/traits/DropAllTablesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Keboola\DbWriter\Traits;
namespace Keboola\DbWriter\TestsTraits;

use Keboola\DbWriterAdapter\PDO\PdoConnection;

Expand Down

0 comments on commit 85c3fa4

Please sign in to comment.