MCPcopy
hub / github.com/nektos/act / TestParseWithVolumes

Function TestParseWithVolumes

pkg/container/docker_cli_test.go:264–332  ·  view source on GitHub ↗

nolint:gocyclo

(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

setupPlatformVolumeFunction · 0.85
mustParseFunction · 0.85
compareRandomizedStringsFunction · 0.85
GetenvMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…