File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
packages/testcontainers/src/wait-strategies/utils Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff 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` , {
You can’t perform that action at this time.
0 commit comments