github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/daemon/volumes_unit_test.go (about) 1 package daemon 2 3 import ( 4 "runtime" 5 "testing" 6 7 "github.com/docker/docker/volume" 8 ) 9 10 func TestParseVolumesFrom(t *testing.T) { 11 cases := []struct { 12 spec string 13 expID string 14 expMode string 15 fail bool 16 }{ 17 {"", "", "", true}, 18 {"foobar", "foobar", "rw", false}, 19 {"foobar:rw", "foobar", "rw", false}, 20 {"foobar:ro", "foobar", "ro", false}, 21 {"foobar:baz", "", "", true}, 22 } 23 24 parser := volume.NewParser(runtime.GOOS) 25 26 for _, c := range cases { 27 id, mode, err := parser.ParseVolumesFrom(c.spec) 28 if c.fail { 29 if err == nil { 30 t.Fatalf("Expected error, was nil, for spec %s\n", c.spec) 31 } 32 continue 33 } 34 35 if id != c.expID { 36 t.Fatalf("Expected id %s, was %s, for spec %s\n", c.expID, id, c.spec) 37 } 38 if mode != c.expMode { 39 t.Fatalf("Expected mode %s, was %s for spec %s\n", c.expMode, mode, c.spec) 40 } 41 } 42 }