Skip to content

Commit 5b2dcd8

Browse files
committed
fix: test container setup with SigningKey
Locally (MacBook M1) the `EsdbClient` testsuite currently fails for me with: > 1) Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testVerifiesTheSignature > RuntimeException: Failed to get mapped port ‘’ for container > > 2) Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testThrowsAnErrorIfTheSignatureVerificationFails > RuntimeException: Failed to get mapped port ‘’ for container > > 3) Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testThrowsAnErrorIfTheHashVerificationFails > RuntimeException: Failed to get mapped port ‘’ for container With this change, tests are green again.
1 parent f6fa24a commit 5b2dcd8

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/Container.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,28 @@ public function start(): void
5757
'--http-enabled',
5858
'--https-enabled=false',
5959
];
60-
$content = [];
60+
61+
$container = (new GenericContainer("{$this->imageName}:{$this->imageTag}"))
62+
->withExposedPorts($this->internalPort)
63+
->withCommand($command);
6164

6265
if ($this->signingKey instanceof SigningKey) {
66+
// Create a temporary file with the signing key
67+
$tempFile = tempnam(sys_get_temp_dir(), 'esdb_signing_key_');
68+
if ($tempFile === false) {
69+
throw new RuntimeException('Failed to create temporary file for signing key.');
70+
}
71+
file_put_contents($tempFile, $this->signingKey->privateKeyPem);
72+
73+
// Mount the temp file into the container
6374
$command[] = '--signing-key-file';
64-
$command[] = '/etc/esdb/signing-key.pem';
65-
66-
$content[] = [
67-
'content' => $this->signingKey->privateKeyPem,
68-
'target' => '/etc/esdb/signing-key.pem',
69-
'mode' => 0o777,
70-
];
75+
$command[] = '/tmp/signing-key.pem';
76+
$container = $container
77+
->withCommand($command)
78+
->withMount($tempFile, '/tmp/signing-key.pem');
7179
}
7280

73-
$container =
74-
(new GenericContainer("{$this->imageName}:{$this->imageTag}"))
75-
->withExposedPorts($this->internalPort)
76-
->withCommand($command)
77-
->withCopyContentToContainer($content)
78-
->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'))
79-
;
81+
$container = $container->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'));
8082

8183
try {
8284
$this->container = $container->start();

0 commit comments

Comments
 (0)