2015-05-19 16:05:25 -04:00
|
|
|
package daemon
|
|
|
|
|
2015-05-21 13:57:59 -04:00
|
|
|
import "testing"
|
2015-05-19 16:05:25 -04:00
|
|
|
|
|
|
|
func TestParseVolumeFrom(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
spec string
|
|
|
|
expId string
|
|
|
|
expMode string
|
|
|
|
fail bool
|
|
|
|
}{
|
|
|
|
{"", "", "", true},
|
|
|
|
{"foobar", "foobar", "rw", false},
|
|
|
|
{"foobar:rw", "foobar", "rw", false},
|
|
|
|
{"foobar:ro", "foobar", "ro", false},
|
|
|
|
{"foobar:baz", "", "", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
id, mode, err := parseVolumesFrom(c.spec)
|
|
|
|
if c.fail {
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected error, was nil, for spec %s\n", c.spec)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if id != c.expId {
|
|
|
|
t.Fatalf("Expected id %s, was %s, for spec %s\n", c.expId, id, c.spec)
|
|
|
|
}
|
|
|
|
if mode != c.expMode {
|
|
|
|
t.Fatalf("Expected mode %s, was %s for spec %s\n", c.expMode, mode, c.spec)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|