@@ -49,6 +49,116 @@ func TestSupportsEnvVarPassthrough(t *testing.T) {
4949 }
5050}
5151
52+ func TestTranslateWindowsHostPaths (t * testing.T ) {
53+ t .Parallel ()
54+
55+ tests := []struct {
56+ name string
57+ in []string
58+ want []string
59+ }{
60+ {
61+ name : "BuildContextPositional" ,
62+ in : []string {"build" , "-t" , "foo" , `C:\Users\foo\finch-test123` },
63+ want : []string {"build" , "-t" , "foo" , "/mnt/c/Users/foo/finch-test123" },
64+ },
65+ {
66+ name : "BuildDockerfileAndContext" ,
67+ in : []string {"build" , "-f" , `D:\a\Dockerfile` , "--no-cache" , `D:\a` },
68+ want : []string {"build" , "-f" , "/mnt/d/a/Dockerfile" , "--no-cache" , "/mnt/d/a" },
69+ },
70+ {
71+ name : "BuildOutputDest" ,
72+ in : []string {"build" , "-t" , "output:tag" , "--output" , `type=tar,dest=C:\Users\foo\out.tar` , `C:\ctx` },
73+ want : []string {"build" , "-t" , "output:tag" , "--output" , "type=tar,dest=/mnt/c/Users/foo/out.tar" , "/mnt/c/ctx" },
74+ },
75+ {
76+ name : "BuildOutputEqualsForm" ,
77+ in : []string {"build" , `--output=type=docker` , `C:\ctx` },
78+ want : []string {"build" , "--output=type=docker" , "/mnt/c/ctx" },
79+ },
80+ {
81+ name : "BuildSecretSrc" ,
82+ in : []string {"build" , "--secret" , `id=mysecret,src=C:\Users\foo\secret.txt` , "-f" , `C:\Users\foo\Dockerfile` , `C:\Users\foo` },
83+ want : []string {
84+ "build" , "--secret" , "id=mysecret,src=/mnt/c/Users/foo/secret.txt" ,
85+ "-f" , "/mnt/c/Users/foo/Dockerfile" , "/mnt/c/Users/foo" ,
86+ },
87+ },
88+ {
89+ name : "SaveOutputFlag" ,
90+ in : []string {"save" , "-o" , `C:\Users\foo\test.tar` , "alpine:latest" },
91+ want : []string {"save" , "-o" , "/mnt/c/Users/foo/test.tar" , "alpine:latest" },
92+ },
93+ {
94+ name : "SaveOutputFlagBeforeImages" ,
95+ in : []string {"save" , "--output" , `C:\Users\foo\test.tar` , "alpine:latest" , "alpine:3.13" },
96+ want : []string {"save" , "--output" , "/mnt/c/Users/foo/test.tar" , "alpine:latest" , "alpine:3.13" },
97+ },
98+ {
99+ name : "LoadInputFlag" ,
100+ in : []string {"load" , "-i" , `C:\Users\foo\test.tar` },
101+ want : []string {"load" , "-i" , "/mnt/c/Users/foo/test.tar" },
102+ },
103+ {
104+ name : "ComposeFileFlag" ,
105+ in : []string {"compose" , "up" , "--file" , `C:\Users\foo\docker-compose.yml` },
106+ want : []string {"compose" , "up" , "--file" , "/mnt/c/Users/foo/docker-compose.yml" },
107+ },
108+ {
109+ name : "CpHostToContainer" ,
110+ in : []string {"cp" , `C:\Users\foo\test-file` , "finch-test-ctr:/tmp/test-file" },
111+ want : []string {"cp" , "/mnt/c/Users/foo/test-file" , "finch-test-ctr:/tmp/test-file" },
112+ },
113+ {
114+ name : "CpContainerToHost" ,
115+ in : []string {"cp" , "finch-test-ctr:/tmp/test-file" , `C:\Users\foo\test-file` },
116+ want : []string {"cp" , "finch-test-ctr:/tmp/test-file" , "/mnt/c/Users/foo/test-file" },
117+ },
118+ {
119+ name : "CpWithFollowLinkFlagAndContainerSpec" ,
120+ in : []string {"cp" , "-L" , `C:\Users\foo\symlink` , "finch-test-ctr:/tmp/test-file" },
121+ want : []string {"cp" , "-L" , "/mnt/c/Users/foo/symlink" , "finch-test-ctr:/tmp/test-file" },
122+ },
123+ {
124+ name : "RunBindMountHostPathOnly" ,
125+ in : []string {"run" , "-v" , `C:\host:/container` , "alpine:3.13" },
126+ want : []string {"run" , "-v" , "/mnt/c/host:/container" , "alpine:3.13" },
127+ },
128+ {
129+ name : "RunNamedVolumeUntouched" ,
130+ in : []string {"run" , "-v" , "foo:/usr/share" , "--name" , "ctr" , "alpine:3.13" },
131+ want : []string {"run" , "-v" , "foo:/usr/share" , "--name" , "ctr" , "alpine:3.13" },
132+ },
133+ {
134+ name : "RunAnonymousVolumeUntouched" ,
135+ in : []string {"run" , "-v" , "/usr/share" , "--name" , "ctr" , "alpine:3.13" },
136+ want : []string {"run" , "-v" , "/usr/share" , "--name" , "ctr" , "alpine:3.13" },
137+ },
138+ {
139+ name : "PullImageTagAndFlagsUntouched" ,
140+ in : []string {"pull" , "alpine:3.13" , "--platform" , "linux/amd64" },
141+ want : []string {"pull" , "alpine:3.13" , "--platform" , "linux/amd64" },
142+ },
143+ }
144+
145+ for _ , test := range tests {
146+ t .Run (test .name , func (t * testing.T ) {
147+ t .Parallel ()
148+
149+ got := translateWindowsHostPaths (test .in )
150+ if len (got ) != len (test .want ) {
151+ t .Fatalf ("length mismatch: got %v, want %v" , got , test .want )
152+ }
153+ for i := range got {
154+ if got [i ] != test .want [i ] {
155+ t .Errorf ("arg %d: got %q, want %q" , i , got [i ], test .want [i ])
156+ }
157+ }
158+ })
159+ }
160+ }
161+
52162func TestNerdctlVersion (t * testing.T ) {
53163 t .Parallel ()
54164
0 commit comments