2015-05-20 21:53:53 +00:00
|
|
|
// +build !experimental
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2015-05-21 17:57:59 +00:00
|
|
|
"github.com/docker/docker/runconfig"
|
2015-05-20 21:53:53 +00:00
|
|
|
"github.com/docker/docker/volume"
|
|
|
|
"github.com/docker/docker/volume/drivers"
|
|
|
|
"github.com/docker/docker/volume/local"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetVolumeDefaultDriver(t *testing.T) {
|
|
|
|
tmp, err := ioutil.TempDir("", "volume-test-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmp)
|
|
|
|
|
|
|
|
l, err := local.New(tmp)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
volumedrivers.Register(l, volume.DefaultDriverName)
|
|
|
|
d, err := getVolumeDriver("missing")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.Name() != volume.DefaultDriverName {
|
|
|
|
t.Fatalf("Expected local driver, was %s\n", d.Name)
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 17:57:59 +00:00
|
|
|
|
|
|
|
func TestParseBindMount(t *testing.T) {
|
|
|
|
cases := []struct {
|
2015-05-25 01:39:31 +00:00
|
|
|
bind string
|
|
|
|
expDest string
|
|
|
|
expSource string
|
|
|
|
expName string
|
|
|
|
mountLabel string
|
|
|
|
expRW bool
|
|
|
|
fail bool
|
2015-05-21 17:57:59 +00:00
|
|
|
}{
|
2015-05-25 01:39:31 +00: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", "", "", "", "", false, true},
|
|
|
|
{"local/name:/tmp:rw", "", "", "", "", true, true},
|
2015-05-21 17:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
conf := &runconfig.Config{}
|
2015-05-25 01:39:31 +00:00
|
|
|
m, err := parseBindMount(c.bind, c.mountLabel, conf)
|
2015-05-21 17:57:59 +00: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.RW != c.expRW {
|
|
|
|
t.Fatalf("Expected RW %v, was %v for spec %s\n", c.expRW, m.RW, c.bind)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|