github.com/nullne/docker@v1.13.0-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 "os" 8 "path/filepath" 9 "strings" 10 ) 11 12 var ( 13 pName = "tiborvass/no-remove" 14 pTag = "latest" 15 pNameWithTag = pName + ":" + pTag 16 ) 17 18 func (s *DockerSuite) TestPluginBasicOps(c *check.C) { 19 testRequires(c, DaemonIsLinux, Network) 20 _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) 21 c.Assert(err, checker.IsNil) 22 23 out, _, err := dockerCmdWithError("plugin", "ls") 24 c.Assert(err, checker.IsNil) 25 c.Assert(out, checker.Contains, pName) 26 c.Assert(out, checker.Contains, pTag) 27 c.Assert(out, checker.Contains, "true") 28 29 id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag) 30 id = strings.TrimSpace(id) 31 c.Assert(err, checker.IsNil) 32 33 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 34 c.Assert(out, checker.Contains, "is enabled") 35 36 _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) 37 c.Assert(err, checker.IsNil) 38 39 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 40 c.Assert(err, checker.IsNil) 41 c.Assert(out, checker.Contains, pNameWithTag) 42 43 _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id)) 44 if !os.IsNotExist(err) { 45 c.Fatal(err) 46 } 47 } 48 49 func (s *DockerSuite) TestPluginForceRemove(c *check.C) { 50 testRequires(c, DaemonIsLinux, Network) 51 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) 52 c.Assert(err, checker.IsNil) 53 54 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 55 c.Assert(out, checker.Contains, "is enabled") 56 57 out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag) 58 c.Assert(err, checker.IsNil) 59 c.Assert(out, checker.Contains, pNameWithTag) 60 } 61 62 func (s *DockerSuite) TestPluginActive(c *check.C) { 63 testRequires(c, DaemonIsLinux, Network) 64 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) 65 c.Assert(err, checker.IsNil) 66 67 out, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag) 68 c.Assert(err, checker.IsNil) 69 70 vID := strings.TrimSpace(out) 71 72 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 73 c.Assert(out, checker.Contains, "is in use") 74 75 _, _, err = dockerCmdWithError("volume", "rm", vID) 76 c.Assert(err, checker.IsNil) 77 78 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 79 c.Assert(out, checker.Contains, "is enabled") 80 81 _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) 82 c.Assert(err, checker.IsNil) 83 84 out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) 85 c.Assert(err, checker.IsNil) 86 c.Assert(out, checker.Contains, pNameWithTag) 87 } 88 89 func (s *DockerSuite) TestPluginInstallDisable(c *check.C) { 90 testRequires(c, DaemonIsLinux, Network) 91 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName) 92 c.Assert(err, checker.IsNil) 93 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 94 95 out, _, err = dockerCmdWithError("plugin", "ls") 96 c.Assert(err, checker.IsNil) 97 c.Assert(out, checker.Contains, "false") 98 99 out, _, err = dockerCmdWithError("plugin", "enable", pName) 100 c.Assert(err, checker.IsNil) 101 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 102 103 out, _, err = dockerCmdWithError("plugin", "disable", pName) 104 c.Assert(err, checker.IsNil) 105 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 106 107 out, _, err = dockerCmdWithError("plugin", "remove", pName) 108 c.Assert(err, checker.IsNil) 109 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 110 } 111 112 func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) { 113 testRequires(c, DaemonIsLinux, Network) 114 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName) 115 c.Assert(err, checker.IsNil) 116 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 117 118 dockerCmd(c, "volume", "ls") 119 } 120 121 func (s *DockerSuite) TestPluginSet(c *check.C) { 122 testRequires(c, DaemonIsLinux, Network) 123 out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName) 124 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 125 126 env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName) 127 c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]") 128 129 dockerCmd(c, "plugin", "set", pName, "DEBUG=1") 130 131 env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName) 132 c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") 133 } 134 135 func (s *DockerSuite) TestPluginInstallArgs(c *check.C) { 136 testRequires(c, DaemonIsLinux, Network) 137 out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1") 138 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 139 140 env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName) 141 c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") 142 } 143 144 func (s *DockerSuite) TestPluginInstallImage(c *check.C) { 145 testRequires(c, DaemonIsLinux) 146 out, _, err := dockerCmdWithError("plugin", "install", "redis") 147 c.Assert(err, checker.NotNil) 148 c.Assert(out, checker.Contains, "content is not a plugin") 149 } 150 151 func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) { 152 testRequires(c, DaemonIsLinux, Network) 153 out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName) 154 c.Assert(err, checker.IsNil) 155 c.Assert(strings.TrimSpace(out), checker.Contains, pName) 156 157 out, _, err = dockerCmdWithError("plugin", "enable", pName) 158 c.Assert(err, checker.NotNil) 159 c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled") 160 161 _, _, err = dockerCmdWithError("plugin", "disable", pName) 162 c.Assert(err, checker.IsNil) 163 164 out, _, err = dockerCmdWithError("plugin", "disable", pName) 165 c.Assert(err, checker.NotNil) 166 c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled") 167 168 _, _, err = dockerCmdWithError("plugin", "remove", pName) 169 c.Assert(err, checker.IsNil) 170 }