2015-05-20 17:53:53 -04:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-05-21 13:57:59 -04:00
|
|
|
"github.com/docker/docker/runconfig"
|
2015-05-20 17:53:53 -04:00
|
|
|
"github.com/docker/docker/volume"
|
|
|
|
"github.com/docker/docker/volume/drivers"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fakeDriver struct{}
|
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
func (fakeDriver) Name() string { return "fake" }
|
|
|
|
func (fakeDriver) Create(name string, opts map[string]string) (volume.Volume, error) { return nil, nil }
|
|
|
|
func (fakeDriver) Remove(v volume.Volume) error { return nil }
|
2015-05-20 17:53:53 -04:00
|
|
|
|
|
|
|
func TestGetVolumeDriver(t *testing.T) {
|
|
|
|
_, err := getVolumeDriver("missing")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error, was nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
volumedrivers.Register(fakeDriver{}, "fake")
|
|
|
|
d, err := getVolumeDriver("fake")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if d.Name() != "fake" {
|
|
|
|
t.Fatalf("Expected fake driver, got %s\n", d.Name())
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 13:57:59 -04:00
|
|
|
|
|
|
|
func TestParseBindMount(t *testing.T) {
|
|
|
|
cases := []struct {
|
2015-05-24 21:39:31 -04:00
|
|
|
bind string
|
|
|
|
driver string
|
|
|
|
expDest string
|
|
|
|
expSource string
|
|
|
|
expName string
|
|
|
|
expDriver string
|
|
|
|
mountLabel string
|
|
|
|
expRW bool
|
|
|
|
fail bool
|
2015-05-21 13:57:59 -04:00
|
|
|
}{
|
2015-05-24 21:39:31 -04:00
|
|
|
{"/tmp:/tmp", "", "/tmp", "/tmp", "", "", "", true, false},
|
|
|
|
{"/tmp:/tmp:ro", "", "/tmp", "/tmp", "", "", "", false, false},
|
|
|
|
{"/tmp:/tmp:rw", "", "/tmp", "/tmp", "", "", "", true, false},
|
|
|
|
{"/tmp:/tmp:foo", "", "/tmp", "/tmp", "", "", "", false, true},
|
|
|
|
{"name:/tmp", "", "/tmp", "", "name", "local", "", true, false},
|
|
|
|
{"name:/tmp", "external", "/tmp", "", "name", "external", "", true, false},
|
|
|
|
{"name:/tmp:ro", "local", "/tmp", "", "name", "local", "", false, false},
|
|
|
|
{"local/name:/tmp:rw", "", "/tmp", "", "local/name", "local", "", true, false},
|
2015-08-30 22:48:34 -04:00
|
|
|
{"/tmp:tmp", "", "", "", "", "", "", true, true},
|
2015-05-21 13:57:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
conf := &runconfig.Config{VolumeDriver: c.driver}
|
2015-05-24 21:39:31 -04:00
|
|
|
m, err := parseBindMount(c.bind, c.mountLabel, conf)
|
2015-05-21 13:57:59 -04:00
|
|
|
if c.fail {
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected error, was nil, for spec %s\n", c.bind)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Destination != c.expDest {
|
|
|
|
t.Fatalf("Expected destination %s, was %s, for spec %s\n", c.expDest, m.Destination, c.bind)
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Source != c.expSource {
|
|
|
|
t.Fatalf("Expected source %s, was %s, for spec %s\n", c.expSource, m.Source, c.bind)
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Name != c.expName {
|
|
|
|
t.Fatalf("Expected name %s, was %s for spec %s\n", c.expName, m.Name, c.bind)
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Driver != c.expDriver {
|
|
|
|
t.Fatalf("Expected driver %s, was %s, for spec %s\n", c.expDriver, m.Driver, c.bind)
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.RW != c.expRW {
|
|
|
|
t.Fatalf("Expected RW %v, was %v for spec %s\n", c.expRW, m.RW, c.bind)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|