From ee3cf2ce35eeb93d010d2947edf7ebfd7a81da2c Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 22 Dec 2016 15:41:53 -0800 Subject: [PATCH] Tests to allow ID-based `docker plugin enable/disable/rm/set` This fix is a follow up based on comment: and a follow up to: https://github.com/docker/docker/pull/29222#issuecomment-268908937 As #28789 has been merged in, it is possible for `docker plugin inspect` to search based on Name or ID Prefix. However, ID-based `docker plugin enable/disable/rm/set` are still not possible. This fix addes test for `docker plugin enable/disable/rm/set` to search based on: - Full ID - Full Name - Partial ID (prefix) The actual fix is done in #29487. This fix is a follow up of #28789 and #29487. Signed-off-by: Yong Tang Upstream-commit: c80e74e8cc28e9b6197e68321f2402c30de3e895 Component: engine --- .../docker_cli_plugins_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/components/engine/integration-cli/docker_cli_plugins_test.go b/components/engine/integration-cli/docker_cli_plugins_test.go index a25df13731..13ded6ee81 100644 --- a/components/engine/integration-cli/docker_cli_plugins_test.go +++ b/components/engine/integration-cli/docker_cli_plugins_test.go @@ -330,3 +330,56 @@ func (s *DockerTrustSuite) TestPluginUntrustedInstall(c *check.C) { c.Assert(err, check.NotNil, check.Commentf(out)) c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) } + +func (s *DockerSuite) TestPluginIDPrefix(c *check.C) { + testRequires(c, DaemonIsLinux, Network) + _, _, err := dockerCmdWithError("plugin", "install", "--disable", "--grant-all-permissions", pNameWithTag) + c.Assert(err, checker.IsNil) + + // Find ID first + id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag) + id = strings.TrimSpace(id) + c.Assert(err, checker.IsNil) + + // List current state + out, _, err := dockerCmdWithError("plugin", "ls") + c.Assert(err, checker.IsNil) + c.Assert(out, checker.Contains, pName) + c.Assert(out, checker.Contains, pTag) + c.Assert(out, checker.Contains, "false") + + env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5]) + c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]") + + dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1") + + env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5]) + c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") + + // Enable + _, _, err = dockerCmdWithError("plugin", "enable", id[:5]) + c.Assert(err, checker.IsNil) + out, _, err = dockerCmdWithError("plugin", "ls") + c.Assert(err, checker.IsNil) + c.Assert(out, checker.Contains, pName) + c.Assert(out, checker.Contains, pTag) + c.Assert(out, checker.Contains, "true") + + // Disable + _, _, err = dockerCmdWithError("plugin", "disable", id[:5]) + c.Assert(err, checker.IsNil) + out, _, err = dockerCmdWithError("plugin", "ls") + c.Assert(err, checker.IsNil) + c.Assert(out, checker.Contains, pName) + c.Assert(out, checker.Contains, pTag) + c.Assert(out, checker.Contains, "false") + + // Remove + out, _, err = dockerCmdWithError("plugin", "remove", id[:5]) + c.Assert(err, checker.IsNil) + // List returns none + out, _, err = dockerCmdWithError("plugin", "ls") + c.Assert(err, checker.IsNil) + c.Assert(out, checker.Not(checker.Contains), pName) + c.Assert(out, checker.Not(checker.Contains), pTag) +}