File tree Expand file tree Collapse file tree
packages/testcontainers/src/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { ContainerInspectInfo } from "dockerode" ;
2+ import { mapInspectResult } from "./map-inspect-result" ;
3+
4+ const inspectResult = ( health ?: { Status : string } ) : ContainerInspectInfo =>
5+ ( {
6+ Name : "container" ,
7+ Config : {
8+ Hostname : "hostname" ,
9+ Labels : { } ,
10+ } ,
11+ State : {
12+ Status : "running" ,
13+ Running : true ,
14+ StartedAt : "2026-05-14T10:00:00.000Z" ,
15+ FinishedAt : "0001-01-01T00:00:00.000Z" ,
16+ Health : health ,
17+ } ,
18+ NetworkSettings : {
19+ Ports : { } ,
20+ Networks : { } ,
21+ } ,
22+ } ) as unknown as ContainerInspectInfo ;
23+
24+ describe ( "mapInspectResult" , ( ) => {
25+ it ( "should map missing health status to none" , ( ) => {
26+ expect ( mapInspectResult ( inspectResult ( ) ) . healthCheckStatus ) . toBe ( "none" ) ;
27+ } ) ;
28+
29+ it ( "should map empty health status to none" , ( ) => {
30+ expect ( mapInspectResult ( inspectResult ( { Status : "" } ) ) . healthCheckStatus ) . toBe ( "none" ) ;
31+ } ) ;
32+
33+ it ( "should map health status" , ( ) => {
34+ expect ( mapInspectResult ( inspectResult ( { Status : "healthy" } ) ) . healthCheckStatus ) . toBe ( "healthy" ) ;
35+ } ) ;
36+ } ) ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ function mapPorts(inspectInfo: ContainerInspectInfo): Ports {
3939function mapHealthCheckStatus ( inspectResult : ContainerInspectInfo ) : HealthCheckStatus {
4040 const health = inspectResult . State . Health ;
4141
42- if ( health === undefined ) {
42+ if ( health === undefined || health . Status === "" ) {
4343 return "none" ;
4444 } else {
4545 return health . Status as HealthCheckStatus ;
Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ export const checkContainerIsHealthy = async (container: StartedTestContainer):
2929export const getHealthCheckStatus = async ( container : StartedTestContainer ) : Promise < HealthCheckStatus | undefined > => {
3030 const client = await getContainerRuntimeClient ( ) ;
3131 const dockerContainer = client . container . getById ( container . getId ( ) ) ;
32- return ( await client . container . inspect ( dockerContainer ) ) . State . Health ?. Status as HealthCheckStatus | undefined ;
32+ const status = ( await client . container . inspect ( dockerContainer ) ) . State . Health ?. Status ;
33+
34+ return status === undefined || status === "" ? undefined : ( status as HealthCheckStatus ) ;
3335} ;
3436
3537export const checkContainerIsHealthyTls = async ( container : StartedTestContainer ) : Promise < void > => {
You can’t perform that action at this time.
0 commit comments