Signed-off-by: Anusha Ragunathan <anusha.ragunathan@docker.com>
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package plugin // import "github.com/docker/docker/plugin" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "io" |
|
| 4 | 5 |
"io/ioutil" |
| 5 | 6 |
"os" |
| 6 | 7 |
"path/filepath" |
| ... | ... |
@@ -10,6 +11,8 @@ import ( |
| 10 | 10 |
"github.com/docker/docker/pkg/mount" |
| 11 | 11 |
"github.com/docker/docker/pkg/system" |
| 12 | 12 |
"github.com/docker/docker/plugin/v2" |
| 13 |
+ specs "github.com/opencontainers/runtime-spec/specs-go" |
|
| 14 |
+ "github.com/pkg/errors" |
|
| 13 | 15 |
) |
| 14 | 16 |
|
| 15 | 17 |
func TestManagerWithPluginMounts(t *testing.T) {
|
| ... | ... |
@@ -77,3 +80,58 @@ func newTestPlugin(t *testing.T, name, cap, root string) *v2.Plugin {
|
| 77 | 77 |
|
| 78 | 78 |
return &p |
| 79 | 79 |
} |
| 80 |
+ |
|
| 81 |
+type simpleExecutor struct {
|
|
| 82 |
+} |
|
| 83 |
+ |
|
| 84 |
+func (e *simpleExecutor) Create(id string, spec specs.Spec, stdout, stderr io.WriteCloser) error {
|
|
| 85 |
+ return errors.New("Create failed")
|
|
| 86 |
+} |
|
| 87 |
+ |
|
| 88 |
+func (e *simpleExecutor) Restore(id string, stdout, stderr io.WriteCloser) error {
|
|
| 89 |
+ return nil |
|
| 90 |
+} |
|
| 91 |
+ |
|
| 92 |
+func (e *simpleExecutor) IsRunning(id string) (bool, error) {
|
|
| 93 |
+ return false, nil |
|
| 94 |
+} |
|
| 95 |
+ |
|
| 96 |
+func (e *simpleExecutor) Signal(id string, signal int) error {
|
|
| 97 |
+ return nil |
|
| 98 |
+} |
|
| 99 |
+ |
|
| 100 |
+func TestCreateFailed(t *testing.T) {
|
|
| 101 |
+ root, err := ioutil.TempDir("", "test-create-failed")
|
|
| 102 |
+ if err != nil {
|
|
| 103 |
+ t.Fatal(err) |
|
| 104 |
+ } |
|
| 105 |
+ defer system.EnsureRemoveAll(root) |
|
| 106 |
+ |
|
| 107 |
+ s := NewStore() |
|
| 108 |
+ managerRoot := filepath.Join(root, "manager") |
|
| 109 |
+ p := newTestPlugin(t, "create", "testcreate", managerRoot) |
|
| 110 |
+ |
|
| 111 |
+ m, err := NewManager( |
|
| 112 |
+ ManagerConfig{
|
|
| 113 |
+ Store: s, |
|
| 114 |
+ Root: managerRoot, |
|
| 115 |
+ ExecRoot: filepath.Join(root, "exec"), |
|
| 116 |
+ CreateExecutor: func(*Manager) (Executor, error) { return &simpleExecutor{}, nil },
|
|
| 117 |
+ LogPluginEvent: func(_, _, _ string) {},
|
|
| 118 |
+ }) |
|
| 119 |
+ if err != nil {
|
|
| 120 |
+ t.Fatal(err) |
|
| 121 |
+ } |
|
| 122 |
+ |
|
| 123 |
+ if err := s.Add(p); err != nil {
|
|
| 124 |
+ t.Fatal(err) |
|
| 125 |
+ } |
|
| 126 |
+ |
|
| 127 |
+ if err := m.enable(p, &controller{}, false); err == nil {
|
|
| 128 |
+ t.Fatalf("expected Create failed error, got %v", err)
|
|
| 129 |
+ } |
|
| 130 |
+ |
|
| 131 |
+ if err := m.Remove(p.Name(), &types.PluginRmConfig{ForceRemove: true}); err != nil {
|
|
| 132 |
+ t.Fatal(err) |
|
| 133 |
+ } |
|
| 134 |
+} |