Skip to content

Commit 69751ea

Browse files
committed
add check for error 127
1 parent 5fd01d1 commit 69751ea

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/testcontainers/src/wait-strategies/utils/port-check.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,20 @@ describe("PortCheck", () => {
163163
],
164164
]);
165165
});
166+
167+
it.for([126, 127])("should error log the distroless image when exit code is %i", async (code) => {
168+
mockContainerExec.mockReturnValueOnce(Promise.resolve({ output: "ERROR 1", exitCode: code }));
169+
mockContainerExec.mockReturnValueOnce(Promise.resolve({ output: "ERROR 2", exitCode: code }));
170+
mockContainerExec.mockReturnValueOnce(Promise.resolve({ output: "ERROR 3", exitCode: code }));
171+
172+
await portCheck.isBound(8080);
173+
174+
expect(mockLogger.error.mock.calls).toEqual([
175+
[
176+
"The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy",
177+
{ containerId: "containerId" },
178+
],
179+
]);
180+
});
166181
});
167182
});

packages/testcontainers/src/wait-strategies/utils/port-check.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export class InternalPortCheck implements PortCheck {
5353
);
5454
const isBound = commandResults.some((result) => result.exitCode === 0);
5555

56-
const shellExists = commandResults.some((result) => result.exitCode !== 126);
56+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
57+
// If a command is not found, the child process created to execute it returns a status of 127.
58+
// If a command is found but is not executable, the return status is 126.
59+
const shellExists = commandResults.some((result) => result.exitCode !== 126 && result.exitCode !== 127);
5760
if (!isBound && !shellExists && !this.isDistroless) {
5861
this.isDistroless = true;
5962
log.error(`The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy`, {

0 commit comments

Comments
 (0)