docker_cli_plugins_test.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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, Network)
  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, Network)
  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) TestPluginActive(c *check.C) {
  48. testRequires(c, DaemonIsLinux, ExperimentalDaemon, Network)
  49. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  50. c.Assert(err, checker.IsNil)
  51. out, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag)
  52. c.Assert(err, checker.IsNil)
  53. vID := strings.TrimSpace(out)
  54. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  55. c.Assert(out, checker.Contains, "is in use")
  56. _, _, err = dockerCmdWithError("volume", "rm", vID)
  57. c.Assert(err, checker.IsNil)
  58. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  59. c.Assert(out, checker.Contains, "is enabled")
  60. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  61. c.Assert(err, checker.IsNil)
  62. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  63. c.Assert(err, checker.IsNil)
  64. c.Assert(out, checker.Contains, pNameWithTag)
  65. }
  66. func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
  67. testRequires(c, DaemonIsLinux, ExperimentalDaemon, Network)
  68. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  69. c.Assert(err, checker.IsNil)
  70. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  71. out, _, err = dockerCmdWithError("plugin", "ls")
  72. c.Assert(err, checker.IsNil)
  73. c.Assert(out, checker.Contains, "false")
  74. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  75. c.Assert(err, checker.IsNil)
  76. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  77. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  78. c.Assert(err, checker.IsNil)
  79. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  80. out, _, err = dockerCmdWithError("plugin", "remove", pName)
  81. c.Assert(err, checker.IsNil)
  82. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  83. }
  84. func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
  85. testRequires(c, DaemonIsLinux, ExperimentalDaemon)
  86. out, _, err := dockerCmdWithError("plugin", "install", "redis")
  87. c.Assert(err, checker.NotNil)
  88. c.Assert(out, checker.Contains, "content is not a plugin")
  89. }
  90. func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
  91. testRequires(c, DaemonIsLinux, ExperimentalDaemon, Network)
  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. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  96. c.Assert(err, checker.NotNil)
  97. c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
  98. _, _, err = dockerCmdWithError("plugin", "disable", pName)
  99. c.Assert(err, checker.IsNil)
  100. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  101. c.Assert(err, checker.NotNil)
  102. c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
  103. _, _, err = dockerCmdWithError("plugin", "remove", pName)
  104. c.Assert(err, checker.IsNil)
  105. }