-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolumes_linux_unit_test.go
85 lines (71 loc) · 2.35 KB
/
volumes_linux_unit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// +build experimental
package daemon
import (
"testing"
"github.com/docker/docker/volume"
"github.com/docker/docker/volume/drivers"
)
type fakeDriver struct{}
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 }
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())
}
}
func TestParseBindMount(t *testing.T) {
cases := []struct {
bind string
driver string
expDest string
expSource string
expName string
expDriver string
expRW bool
fail bool
}{
{"/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},
{"/tmp:tmp", "", "", "", "", "", true, true},
}
for _, c := range cases {
m, err := parseBindMount(c.bind, c.driver)
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)
}
}
}