Implement WaitForExec using new Client library. Add BaseWait to avoid some code duplication. Adjust Postgres test

This commit is contained in:
Sergei Shitikov
2024-09-01 18:23:21 +02:00
parent 3dd4d2525a
commit ea07a96091
6 changed files with 94 additions and 45 deletions
+15 -5
View File
@@ -8,11 +8,18 @@ use Testcontainers\Wait\WaitForExec;
class PostgresContainer extends GenericContainer
{
public function __construct(string $version = 'latest', string $rootPassword = 'root')
{
public function __construct(
string $version = 'latest',
public readonly string $username = 'test',
public readonly string $password = 'test',
public readonly string $database = 'test'
) {
parent::__construct('postgres:' . $version);
$this->withEnvironment('POSTGRES_PASSWORD', $rootPassword);
$this->withWait(new WaitForExec(["pg_isready", "-h", "127.0.0.1"]));
$this->withExposedPorts(5432);
$this->withEnvironment('POSTGRES_USER', $this->username);
$this->withEnvironment('POSTGRES_PASSWORD', $this->password);
$this->withEnvironment('POSTGRES_DB', $this->database);
$this->withWait(new WaitForExec(["pg_isready", "-h", "127.0.0.1", "-U", $this->username]));
}
/**
@@ -21,7 +28,10 @@ class PostgresContainer extends GenericContainer
*/
public static function make(string $version = 'latest', string $dbPassword = 'root'): self
{
return new self($version, $dbPassword);
return new self(
version: $version,
password: $dbPassword
);
}
public function withPostgresUser(string $username): self