MCPcopy Create free account
hub / github.com/docker/cli / TestParseWithVolumes

Function TestParseWithVolumes

cli/command/container/opts_test.go:256–324  ·  view source on GitHub ↗

nolint:gocyclo

(t *testing.T)

Source from the content-addressed store, hash-verified

254
255//nolint:gocyclo
256func TestParseWithVolumes(t *testing.T) {
257 // A single volume
258 arr, tryit := setupPlatformVolume([]string{`/tmp`}, []string{`c:\tmp`})
259 if config, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds != nil {
260 t.Fatalf("Error parsing volume flags, %q should not mount-bind anything. Received %v", tryit, hostConfig.Binds)
261 } else if _, exists := config.Volumes[arr[0]]; !exists {
262 t.Fatalf("Error parsing volume flags, %q is missing from volumes. Received %v", tryit, config.Volumes)
263 }
264
265 // Two volumes
266 arr, tryit = setupPlatformVolume([]string{`/tmp`, `/var`}, []string{`c:\tmp`, `c:\var`})
267 if config, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds != nil {
268 t.Fatalf("Error parsing volume flags, %q should not mount-bind anything. Received %v", tryit, hostConfig.Binds)
269 } else if _, exists := config.Volumes[arr[0]]; !exists {
270 t.Fatalf("Error parsing volume flags, %s is missing from volumes. Received %v", arr[0], config.Volumes)
271 } else if _, exists := config.Volumes[arr[1]]; !exists { //nolint:govet // ignore shadow-check
272 t.Fatalf("Error parsing volume flags, %s is missing from volumes. Received %v", arr[1], config.Volumes)
273 }
274
275 // A single bind mount
276 arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp`}, []string{os.Getenv("TEMP") + `:c:\containerTmp`})
277 if config, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds == nil || hostConfig.Binds[0] != arr[0] {
278 t.Fatalf("Error parsing volume flags, %q should mount-bind the path before the colon into the path after the colon. Received %v %v", arr[0], hostConfig.Binds, config.Volumes)
279 }
280
281 // Two bind mounts.
282 arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp`, `/hostVar:/containerVar`}, []string{os.Getenv("ProgramData") + `:c:\ContainerPD`, os.Getenv("TEMP") + `:c:\containerTmp`})
283 if _, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil {
284 t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds)
285 }
286
287 // Two bind mounts, first read-only, second read-write.
288 // TODO Windows: The Windows version uses read-write as that's the only mode it supports. Can change this post TP4
289 arr, tryit = setupPlatformVolume(
290 []string{`/hostTmp:/containerTmp:ro`, `/hostVar:/containerVar:rw`},
291 []string{os.Getenv("TEMP") + `:c:\containerTmp:rw`, os.Getenv("ProgramData") + `:c:\ContainerPD:rw`})
292 if _, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil {
293 t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds)
294 }
295
296 // Similar to previous test but with alternate modes which are only supported by Linux
297 if runtime.GOOS != "windows" {
298 arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp:ro,Z`, `/hostVar:/containerVar:rw,Z`}, []string{})
299 if _, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil {
300 t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds)
301 }
302
303 arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp:Z`, `/hostVar:/containerVar:z`}, []string{})
304 if _, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil {
305 t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds)
306 }
307 }
308
309 // One bind mount and one volume
310 arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp`, `/containerVar`}, []string{os.Getenv("TEMP") + `:c:\containerTmp`, `c:\containerTmp`})
311 if config, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds == nil || len(hostConfig.Binds) > 1 || hostConfig.Binds[0] != arr[0] {
312 t.Fatalf("Error parsing volume flags, %s and %s should only one and only one bind mount %s. Received %s", arr[0], arr[1], arr[0], hostConfig.Binds)
313 } else if _, exists := config.Volumes[arr[1]]; !exists {

Callers

nothing calls this directly

Calls 3

setupPlatformVolumeFunction · 0.85
mustParseFunction · 0.85
compareRandomizedStringsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…