docker_cli_plugins_test.go 3.5 KB

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