github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/daemon/volumes_linux_test.go (about) 1 package daemon 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/docker/docker/api/types/mount" 8 ) 9 10 func TestBindDaemonRoot(t *testing.T) { 11 t.Parallel() 12 d := &Daemon{root: "/a/b/c/daemon"} 13 for _, test := range []struct { 14 desc string 15 opts *mount.BindOptions 16 needsProp bool 17 err bool 18 }{ 19 {desc: "nil propagation settings", opts: nil, needsProp: true, err: false}, 20 {desc: "empty propagation settings", opts: &mount.BindOptions{}, needsProp: true, err: false}, 21 {desc: "private propagation", opts: &mount.BindOptions{Propagation: mount.PropagationPrivate}, err: true}, 22 {desc: "rprivate propagation", opts: &mount.BindOptions{Propagation: mount.PropagationRPrivate}, err: true}, 23 {desc: "slave propagation", opts: &mount.BindOptions{Propagation: mount.PropagationSlave}, err: true}, 24 {desc: "rslave propagation", opts: &mount.BindOptions{Propagation: mount.PropagationRSlave}, err: false, needsProp: false}, 25 {desc: "shared propagation", opts: &mount.BindOptions{Propagation: mount.PropagationShared}, err: true}, 26 {desc: "rshared propagation", opts: &mount.BindOptions{Propagation: mount.PropagationRSlave}, err: false, needsProp: false}, 27 } { 28 t.Run(test.desc, func(t *testing.T) { 29 test := test 30 for desc, source := range map[string]string{ 31 "source is root": d.root, 32 "source is subpath": filepath.Join(d.root, "a", "b"), 33 "source is parent": filepath.Dir(d.root), 34 "source is /": "/", 35 } { 36 t.Run(desc, func(t *testing.T) { 37 mount := mount.Mount{ 38 Type: mount.TypeBind, 39 Source: source, 40 BindOptions: test.opts, 41 } 42 needsProp, err := d.validateBindDaemonRoot(mount) 43 if (err != nil) != test.err { 44 t.Fatalf("expected err=%v, got: %v", test.err, err) 45 } 46 if test.err { 47 return 48 } 49 if test.needsProp != needsProp { 50 t.Fatalf("expected needsProp=%v, got: %v", test.needsProp, needsProp) 51 } 52 }) 53 } 54 }) 55 } 56 }