2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-05-19 20:05:25 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
2015-12-16 15:35:35 +00:00
|
|
|
|
2018-04-17 20:50:28 +00:00
|
|
|
volumemounts "github.com/docker/docker/volume/mounts"
|
2015-09-10 02:23:06 +00:00
|
|
|
)
|
2015-05-19 20:05:25 +00:00
|
|
|
|
2015-08-31 02:48:34 +00:00
|
|
|
func TestParseVolumesFrom(t *testing.T) {
|
2015-05-19 20:05:25 +00:00
|
|
|
cases := []struct {
|
|
|
|
spec string
|
2015-07-30 21:01:53 +00:00
|
|
|
expID string
|
2015-05-19 20:05:25 +00:00
|
|
|
expMode string
|
|
|
|
fail bool
|
|
|
|
}{
|
|
|
|
{"", "", "", true},
|
|
|
|
{"foobar", "foobar", "rw", false},
|
|
|
|
{"foobar:rw", "foobar", "rw", false},
|
|
|
|
{"foobar:ro", "foobar", "ro", false},
|
|
|
|
{"foobar:baz", "", "", true},
|
|
|
|
}
|
|
|
|
|
2021-06-11 19:01:18 +00:00
|
|
|
parser := volumemounts.NewParser()
|
2017-08-01 17:32:44 +00:00
|
|
|
|
2015-05-19 20:05:25 +00:00
|
|
|
for _, c := range cases {
|
2017-08-01 17:32:44 +00:00
|
|
|
id, mode, err := parser.ParseVolumesFrom(c.spec)
|
2015-05-19 20:05:25 +00:00
|
|
|
if c.fail {
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected error, was nil, for spec %s\n", c.spec)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
if id != c.expID {
|
|
|
|
t.Fatalf("Expected id %s, was %s, for spec %s\n", c.expID, id, c.spec)
|
2015-05-19 20:05:25 +00:00
|
|
|
}
|
|
|
|
if mode != c.expMode {
|
|
|
|
t.Fatalf("Expected mode %s, was %s for spec %s\n", c.expMode, mode, c.spec)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|