docker_cli_plugins_test.go 3.7 KB

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