@@ -6,57 +6,60 @@ const mockedDockerContextLsOutput = `{"Current":true,"Description":"Current DOCK
66
77vi . mock ( "node:child_process" ) ;
88
9- describe ( "resolveDockerHost" , ( ) => {
10- let mockExecFileSync : ReturnType < typeof vi . fn > ;
11-
12- beforeEach ( async ( ) => {
13- vi . clearAllMocks ( ) ;
14- const childProcess = await import ( "node:child_process" ) ;
15- mockExecFileSync = vi . mocked ( childProcess . execFileSync ) ;
16-
17- mockExecFileSync . mockReturnValue ( mockedDockerContextLsOutput ) ;
18- } ) ;
19-
20- afterEach ( ( ) => {
21- vi . unstubAllEnvs ( ) ;
22- } ) ;
23-
24- it ( "should return WRANGLER_DOCKER_HOST when set" , async ( ) => {
25- vi . stubEnv ( "WRANGLER_DOCKER_HOST" , "unix:///foo/wrangler/socket" ) ;
26- vi . stubEnv ( "DOCKER_HOST" , "unix:///bar/docker/socket" ) ;
27-
28- const result = await resolveDockerHost ( "/no/op/docker" ) ;
29- expect ( result ) . toBe ( "unix:///foo/wrangler/socket" ) ;
30-
31- expect ( mockExecFileSync ) . not . toHaveBeenCalled ( ) ;
32- } ) ;
33-
34- it ( "should return DOCKER_HOST when WRANGLER_DOCKER_HOST is not set" , async ( ) => {
35- expect ( process . env . WRANGLER_DOCKER_HOST ) . toBeUndefined ( ) ;
36- vi . stubEnv ( "DOCKER_HOST" , "unix:///bar/docker/socket" ) ;
37-
38- const result = await resolveDockerHost ( "/no/op/docker" ) ;
39- expect ( result ) . toBe ( "unix:///bar/docker/socket" ) ;
40-
41- expect ( mockExecFileSync ) . not . toHaveBeenCalled ( ) ;
42- } ) ;
43-
44- it ( "should use Docker context when no env vars are set" , async ( ) => {
45- const result = await resolveDockerHost ( "/no/op/docker" ) ;
46- expect ( result ) . toBe ( "unix:///current/run/docker.sock" ) ;
47- expect ( mockExecFileSync ) . toHaveBeenCalledWith (
48- "/no/op/docker" ,
49- [ "context" , "ls" , "--format" , "json" ] ,
50- { encoding : 'utf8' }
51- ) ;
52- } ) ;
53-
54- it ( "should fall back to platform default on Unix when context fails" , async ( ) => {
55- mockExecFileSync . mockImplementation ( ( ) => {
56- throw new Error ( "Docker command failed" ) ;
9+ describe . skipIf ( process . platform !== "linux" && process . env . CI === "true" ) (
10+ "resolveDockerHost" ,
11+ ( ) => {
12+ let mockExecFileSync : ReturnType < typeof vi . fn > ;
13+
14+ beforeEach ( async ( ) => {
15+ vi . clearAllMocks ( ) ;
16+ const childProcess = await import ( "node:child_process" ) ;
17+ mockExecFileSync = vi . mocked ( childProcess . execFileSync ) ;
18+
19+ mockExecFileSync . mockReturnValue ( mockedDockerContextLsOutput ) ;
20+ } ) ;
21+
22+ afterEach ( ( ) => {
23+ vi . unstubAllEnvs ( ) ;
24+ } ) ;
25+
26+ it ( "should return WRANGLER_DOCKER_HOST when set" , async ( ) => {
27+ vi . stubEnv ( "WRANGLER_DOCKER_HOST" , "unix:///foo/wrangler/socket" ) ;
28+ vi . stubEnv ( "DOCKER_HOST" , "unix:///bar/docker/socket" ) ;
29+
30+ const result = await resolveDockerHost ( "/no/op/docker" ) ;
31+ expect ( result ) . toBe ( "unix:///foo/wrangler/socket" ) ;
32+
33+ expect ( mockExecFileSync ) . not . toHaveBeenCalled ( ) ;
5734 } ) ;
5835
59- const result = await resolveDockerHost ( "/no/op/docker" ) ;
60- expect ( result ) . toBe ( "unix:///var/run/docker.sock" ) ;
61- } ) ;
62- } ) ;
36+ it ( "should return DOCKER_HOST when WRANGLER_DOCKER_HOST is not set" , async ( ) => {
37+ expect ( process . env . WRANGLER_DOCKER_HOST ) . toBeUndefined ( ) ;
38+ vi . stubEnv ( "DOCKER_HOST" , "unix:///bar/docker/socket" ) ;
39+
40+ const result = await resolveDockerHost ( "/no/op/docker" ) ;
41+ expect ( result ) . toBe ( "unix:///bar/docker/socket" ) ;
42+
43+ expect ( mockExecFileSync ) . not . toHaveBeenCalled ( ) ;
44+ } ) ;
45+
46+ it ( "should use Docker context when no env vars are set" , async ( ) => {
47+ const result = await resolveDockerHost ( "/no/op/docker" ) ;
48+ expect ( result ) . toBe ( "unix:///current/run/docker.sock" ) ;
49+ expect ( mockExecFileSync ) . toHaveBeenCalledWith (
50+ "/no/op/docker" ,
51+ [ "context" , "ls" , "--format" , "json" ] ,
52+ { encoding : "utf8" }
53+ ) ;
54+ } ) ;
55+
56+ it ( "should fall back to platform default on Unix when context fails" , async ( ) => {
57+ mockExecFileSync . mockImplementation ( ( ) => {
58+ throw new Error ( "Docker command failed" ) ;
59+ } ) ;
60+
61+ const result = await resolveDockerHost ( "/no/op/docker" ) ;
62+ expect ( result ) . toBe ( "unix:///var/run/docker.sock" ) ;
63+ } ) ;
64+ }
65+ ) ;
0 commit comments