github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/plugin/manager_linux_test.go (about) 1 package plugin 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/docker/docker/api/types" 10 "github.com/docker/docker/pkg/mount" 11 "github.com/docker/docker/pkg/system" 12 "github.com/docker/docker/plugin/v2" 13 ) 14 15 func TestManagerWithPluginMounts(t *testing.T) { 16 root, err := ioutil.TempDir("", "test-store-with-plugin-mounts") 17 if err != nil { 18 t.Fatal(err) 19 } 20 defer system.EnsureRemoveAll(root) 21 22 s := NewStore() 23 managerRoot := filepath.Join(root, "manager") 24 p1 := newTestPlugin(t, "test1", "testcap", managerRoot) 25 26 p2 := newTestPlugin(t, "test2", "testcap", managerRoot) 27 p2.PluginObj.Enabled = true 28 29 m, err := NewManager( 30 ManagerConfig{ 31 Store: s, 32 Root: managerRoot, 33 ExecRoot: filepath.Join(root, "exec"), 34 CreateExecutor: func(*Manager) (Executor, error) { return nil, nil }, 35 LogPluginEvent: func(_, _, _ string) {}, 36 }) 37 if err != nil { 38 t.Fatal(err) 39 } 40 41 if err := s.Add(p1); err != nil { 42 t.Fatal(err) 43 } 44 if err := s.Add(p2); err != nil { 45 t.Fatal(err) 46 } 47 48 // Create a mount to simulate a plugin that has created it's own mounts 49 p2Mount := filepath.Join(p2.Rootfs, "testmount") 50 if err := os.MkdirAll(p2Mount, 0755); err != nil { 51 t.Fatal(err) 52 } 53 if err := mount.Mount("tmpfs", p2Mount, "tmpfs", ""); err != nil { 54 t.Fatal(err) 55 } 56 57 if err := m.Remove(p1.Name(), &types.PluginRmConfig{ForceRemove: true}); err != nil { 58 t.Fatal(err) 59 } 60 if mounted, err := mount.Mounted(p2Mount); !mounted || err != nil { 61 t.Fatalf("expected %s to be mounted, err: %v", p2Mount, err) 62 } 63 } 64 65 func newTestPlugin(t *testing.T, name, cap, root string) *v2.Plugin { 66 rootfs := filepath.Join(root, name) 67 if err := os.MkdirAll(rootfs, 0755); err != nil { 68 t.Fatal(err) 69 } 70 71 p := v2.Plugin{PluginObj: types.Plugin{Name: name}} 72 p.Rootfs = rootfs 73 iType := types.PluginInterfaceType{Capability: cap, Prefix: "docker", Version: "1.0"} 74 i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}} 75 p.PluginObj.Config.Interface = i 76 p.PluginObj.ID = name 77 78 return &p 79 }