github.com/dpiddy/docker@v1.12.2-rc1/integration-cli/docker_cli_plugins_test.go (about) 1 package main 2 3 import ( 4 "github.com/docker/docker/pkg/integration/checker" 5 "github.com/go-check/check" 6 7 "io/ioutil" 8 "os" 9 "os/exec" 10 "path/filepath" 11 "strings" 12 ) 13 14 var ( 15 pName = "tiborvass/no-remove" 16 pTag = "latest" 17 pNameWithTag = pName + ":" + pTag 18 ) 19 20 func (s *DockerSuite) TestPluginBasicOps(c *check.C) { 21 testRequires(c, DaemonIsLinux, ExperimentalDaemon) 22 _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) 23 c.Assert(err, checker.IsNil) 24 25 out, _, err := dockerCmdWithError("plugin", "ls") 26 c.Assert(err, checker.IsNil) 27 c.Assert(out, checker.Contains, pName) 28 c.Assert(out, checker.Contains, pTag) 29 c.Assert(out, checker.Contains, "true") 30 31 out, _, err = dockerCmdWithError("plugin", "inspect", pNameWithTag) 32 c.Assert(err, checker.IsNil) 33 tmpFile, err := ioutil.TempFile("", "inspect.json") 34 c.Assert(err, checker.IsNil) 35 defer tmpFile.Close() 36 37 if _, err := tmpFile.Write([]byte(out)); err != nil { 38 c.Fatal(err) 39 } 40 // FIXME: When `docker plugin inspect` takes a format as input, jq can be replaced. 41 id, err := exec.Command("jq", ".Id", "--raw-output", tmpFile.Name()).CombinedOutput() 42 c.Assert(err, checker.IsNil) 43 44 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 45 c.Assert(out, checker.Contains, "is active") 46 47 _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) 48 c.Assert(err, checker.IsNil) 49 50 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 51 c.Assert(err, checker.IsNil) 52 c.Assert(out, checker.Contains, pNameWithTag) 53 54 _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", string(id))) 55 if !os.IsNotExist(err) { 56 c.Fatal(err) 57 } 58 } 59 60 func (s *DockerSuite) TestPluginInstallDisable(c *check.C) { 61 testRequires(c, DaemonIsLinux, ExperimentalDaemon) 62 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName) 63 c.Assert(err, checker.IsNil) 64 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 65 66 out, _, err = dockerCmdWithError("plugin", "ls") 67 c.Assert(err, checker.IsNil) 68 c.Assert(out, checker.Contains, "false") 69 70 out, _, err = dockerCmdWithError("plugin", "enable", pName) 71 c.Assert(err, checker.IsNil) 72 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 73 74 out, _, err = dockerCmdWithError("plugin", "disable", pName) 75 c.Assert(err, checker.IsNil) 76 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 77 78 out, _, err = dockerCmdWithError("plugin", "remove", pName) 79 c.Assert(err, checker.IsNil) 80 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 81 } 82 83 func (s *DockerSuite) TestPluginInstallImage(c *check.C) { 84 testRequires(c, DaemonIsLinux, ExperimentalDaemon) 85 out, _, err := dockerCmdWithError("plugin", "install", "redis") 86 c.Assert(err, checker.NotNil) 87 c.Assert(out, checker.Contains, "content is not a plugin") 88 } 89 90 func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) { 91 testRequires(c, DaemonIsLinux, ExperimentalDaemon) 92 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName) 93 c.Assert(err, checker.IsNil) 94 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 95 96 out, _, err = dockerCmdWithError("plugin", "enable", pName) 97 c.Assert(err, checker.NotNil) 98 c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled") 99 100 _, _, err = dockerCmdWithError("plugin", "disable", pName) 101 c.Assert(err, checker.IsNil) 102 103 out, _, err = dockerCmdWithError("plugin", "disable", pName) 104 c.Assert(err, checker.NotNil) 105 c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled") 106 107 _, _, err = dockerCmdWithError("plugin", "remove", pName) 108 c.Assert(err, checker.IsNil) 109 }