Code reuse on working with docker networks

This commit is contained in:
Nikola Petkanski
2024-07-16 05:07:39 +03:00
parent ed18c0b8f8
commit 11c3e21e92
5 changed files with 73 additions and 14 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ class WaitForHttp implements WaitInterface
public function wait(string $id): void
{
$containerAddress = $this->getContainerAddress(containerId: $id);
$containerAddress = self::dockerContainerAddress(containerId: $id);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d%s', $containerAddress, $this->port, $this->path));
+4 -4
View File
@@ -13,13 +13,13 @@ final class WaitForTcpPortOpen implements WaitInterface
{
use DockerContainerAwareTrait;
public function __construct(private readonly int $port)
public function __construct(private readonly int $port, private readonly ?string $network = null)
{
}
public static function make(int $port): self
public static function make(int $port, ?string $network = null): self
{
return new self($port);
return new self($port, $network);
}
/**
@@ -27,7 +27,7 @@ final class WaitForTcpPortOpen implements WaitInterface
*/
public function wait(string $id): void
{
if (@fsockopen($this->getContainerAddress($id), $this->port) === false) {
if (@fsockopen(self::dockerContainerAddress(containerId: $id, networkName: $this->network), $this->port) === false) {
throw new ContainerNotReadyException($id, new RuntimeException('Unable to connect to container TCP port'));
}
}