@@ -18,6 +18,7 @@ type MockDockerChild = EventEmitter & {
1818const spawnState = vi . hoisted ( ( ) => ( {
1919 calls : [ ] as SpawnCall [ ] ,
2020 imageExists : true ,
21+ inspectError : "" ,
2122} ) ) ;
2223
2324function createMockDockerChild ( ) : MockDockerChild {
@@ -40,7 +41,9 @@ function spawnDockerProcess(command: string, args: string[]) {
4041 stderr = `unexpected command: ${ command } ` ;
4142 } else if ( args [ 0 ] === "image" && args [ 1 ] === "inspect" ) {
4243 code = spawnState . imageExists ? 0 : 1 ;
43- stderr = spawnState . imageExists ? "" : `Error response from daemon: No such image: ${ args [ 2 ] } ` ;
44+ stderr = spawnState . imageExists
45+ ? ""
46+ : spawnState . inspectError || `Error response from daemon: No such image: ${ args [ 2 ] } ` ;
4447 } else if ( args [ 0 ] === "pull" || args [ 0 ] === "tag" ) {
4548 code = 0 ;
4649 } else {
@@ -79,6 +82,7 @@ describe("ensureDockerImage", () => {
7982 beforeEach ( async ( ) => {
8083 spawnState . calls . length = 0 ;
8184 spawnState . imageExists = true ;
85+ spawnState . inspectError = "" ;
8286 await loadFreshDockerModuleForTest ( ) ;
8387 } ) ;
8488
@@ -113,4 +117,19 @@ describe("ensureDockerImage", () => {
113117 } ,
114118 ] ) ;
115119 } ) ;
120+
121+ it ( "returns when the Docker daemon is unavailable during image inspection" , async ( ) => {
122+ spawnState . imageExists = false ;
123+ spawnState . inspectError =
124+ "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" ;
125+
126+ await ensureDockerImage ( DEFAULT_SANDBOX_IMAGE ) ;
127+
128+ expect ( spawnState . calls ) . toEqual ( [
129+ {
130+ command : "docker" ,
131+ args : [ "image" , "inspect" , DEFAULT_SANDBOX_IMAGE ] ,
132+ } ,
133+ ] ) ;
134+ } ) ;
116135} ) ;
0 commit comments