|
5 | 5 | "io" |
6 | 6 | "math/rand" |
7 | 7 | "os/exec" |
| 8 | + "path/filepath" |
8 | 9 | "strings" |
9 | 10 | "syscall" |
10 | 11 | "testing" |
@@ -160,6 +161,36 @@ func TestMountSubvolume(t *testing.T) { |
160 | 161 | } |
161 | 162 | } |
162 | 163 |
|
| 164 | +func TestMountBindCreateMountpoint(t *testing.T) { |
| 165 | + environment.SkipIfDaemonNotLinux(t) |
| 166 | + |
| 167 | + for _, tc := range []struct { |
| 168 | + name string |
| 169 | + value string |
| 170 | + expectSuccess bool |
| 171 | + }{ |
| 172 | + {name: "flag only", value: "bind-create-src", expectSuccess: true}, |
| 173 | + {name: "true", value: "bind-create-src=true", expectSuccess: true}, |
| 174 | + {name: "1", value: "bind-create-src=1", expectSuccess: true}, |
| 175 | + {name: "false", value: "bind-create-src=false", expectSuccess: false}, |
| 176 | + {name: "0", value: "bind-create-src=0", expectSuccess: false}, |
| 177 | + } { |
| 178 | + t.Run(tc.name, func(t *testing.T) { |
| 179 | + srcPath := filepath.Join("/tmp", t.Name(), "does", "not", "exist") |
| 180 | + result := icmd.RunCommand("docker", "run", "--rm", |
| 181 | + "--mount", "type=bind,src="+srcPath+",dst=/mnt,"+tc.value, |
| 182 | + fixtures.AlpineImage, "cat", "/proc/mounts") |
| 183 | + if tc.expectSuccess { |
| 184 | + result.Assert(t, icmd.Success) |
| 185 | + assert.Check(t, is.Contains(result.Stdout(), "/mnt")) |
| 186 | + } else { |
| 187 | + result.Assert(t, icmd.Expected{ExitCode: 125}) |
| 188 | + assert.Check(t, is.Contains(result.Stderr(), srcPath)) |
| 189 | + } |
| 190 | + }) |
| 191 | + } |
| 192 | +} |
| 193 | + |
163 | 194 | func TestProcessTermination(t *testing.T) { |
164 | 195 | var out bytes.Buffer |
165 | 196 | cmd := icmd.Command("docker", "run", "--rm", "-i", fixtures.AlpineImage, |
|
0 commit comments