docker_cli_plugins_test.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, 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. id = strings.TrimSpace(id)
  25. c.Assert(err, checker.IsNil)
  26. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  27. c.Assert(out, checker.Contains, "is enabled")
  28. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  29. c.Assert(err, checker.IsNil)
  30. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  31. c.Assert(err, checker.IsNil)
  32. c.Assert(out, checker.Contains, pNameWithTag)
  33. _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id))
  34. if !os.IsNotExist(err) {
  35. c.Fatal(err)
  36. }
  37. }
  38. func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
  39. testRequires(c, DaemonIsLinux, Network)
  40. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  41. c.Assert(err, checker.IsNil)
  42. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  43. c.Assert(out, checker.Contains, "is enabled")
  44. out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
  45. c.Assert(err, checker.IsNil)
  46. c.Assert(out, checker.Contains, pNameWithTag)
  47. }
  48. func (s *DockerSuite) TestPluginActive(c *check.C) {
  49. testRequires(c, DaemonIsLinux, Network, IsAmd64)
  50. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  51. c.Assert(err, checker.IsNil)
  52. out, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag)
  53. c.Assert(err, checker.IsNil)
  54. vID := strings.TrimSpace(out)
  55. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  56. c.Assert(out, checker.Contains, "is in use")
  57. _, _, err = dockerCmdWithError("volume", "rm", vID)
  58. c.Assert(err, checker.IsNil)
  59. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  60. c.Assert(out, checker.Contains, "is enabled")
  61. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  62. c.Assert(err, checker.IsNil)
  63. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  64. c.Assert(err, checker.IsNil)
  65. c.Assert(out, checker.Contains, pNameWithTag)
  66. }
  67. func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
  68. testRequires(c, DaemonIsLinux, Network)
  69. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  70. c.Assert(err, checker.IsNil)
  71. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  72. out, _, err = dockerCmdWithError("plugin", "ls")
  73. c.Assert(err, checker.IsNil)
  74. c.Assert(out, checker.Contains, "false")
  75. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  76. c.Assert(err, checker.IsNil)
  77. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  78. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  79. c.Assert(err, checker.IsNil)
  80. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  81. out, _, err = dockerCmdWithError("plugin", "remove", pName)
  82. c.Assert(err, checker.IsNil)
  83. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  84. }
  85. func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
  86. testRequires(c, DaemonIsLinux, Network)
  87. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  88. c.Assert(err, checker.IsNil)
  89. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  90. dockerCmd(c, "volume", "ls")
  91. }
  92. func (s *DockerSuite) TestPluginSet(c *check.C) {
  93. testRequires(c, DaemonIsLinux, Network)
  94. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName)
  95. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  96. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  97. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
  98. dockerCmd(c, "plugin", "set", pName, "DEBUG=1")
  99. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  100. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  101. }
  102. func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
  103. testRequires(c, DaemonIsLinux, Network)
  104. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
  105. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  106. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  107. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  108. }
  109. func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
  110. testRequires(c, DaemonIsLinux)
  111. out, _, err := dockerCmdWithError("plugin", "install", "redis")
  112. c.Assert(err, checker.NotNil)
  113. c.Assert(out, checker.Contains, "content is not a plugin")
  114. }
  115. func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
  116. testRequires(c, DaemonIsLinux, Network)
  117. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
  118. c.Assert(err, checker.IsNil)
  119. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  120. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  121. c.Assert(err, checker.NotNil)
  122. c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
  123. _, _, err = dockerCmdWithError("plugin", "disable", pName)
  124. c.Assert(err, checker.IsNil)
  125. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  126. c.Assert(err, checker.NotNil)
  127. c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
  128. _, _, err = dockerCmdWithError("plugin", "remove", pName)
  129. c.Assert(err, checker.IsNil)
  130. }