docker_cli_search_test.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/docker/docker/pkg/integration/checker"
  6. "github.com/go-check/check"
  7. )
  8. // search for repos named "registry" on the central registry
  9. func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
  10. testRequires(c, Network, DaemonIsLinux)
  11. out, _ := dockerCmd(c, "search", "busybox")
  12. c.Assert(out, checker.Contains, "Busybox base image.", check.Commentf("couldn't find any repository named (or containing) 'Busybox base image.'"))
  13. }
  14. func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
  15. out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox")
  16. c.Assert(err, check.NotNil, check.Commentf(out))
  17. c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
  18. out, _, err = dockerCmdWithError("search", "-f", "stars=a", "busybox")
  19. c.Assert(err, check.NotNil, check.Commentf(out))
  20. c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
  21. out, _, err = dockerCmdWithError("search", "-f", "is-automated=a", "busybox")
  22. c.Assert(err, check.NotNil, check.Commentf(out))
  23. c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
  24. out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox")
  25. c.Assert(err, check.NotNil, check.Commentf(out))
  26. c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
  27. // -s --stars deprecated since Docker 1.13
  28. out, _, err = dockerCmdWithError("search", "--stars=a", "busybox")
  29. c.Assert(err, check.NotNil, check.Commentf(out))
  30. c.Assert(out, checker.Contains, "invalid syntax", check.Commentf("couldn't find the invalid value warning"))
  31. // -s --stars deprecated since Docker 1.13
  32. out, _, err = dockerCmdWithError("search", "-s=-1", "busybox")
  33. c.Assert(err, check.NotNil, check.Commentf(out))
  34. c.Assert(out, checker.Contains, "invalid syntax", check.Commentf("couldn't find the invalid value warning"))
  35. }
  36. func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
  37. testRequires(c, Network, DaemonIsLinux)
  38. out, _ := dockerCmd(c, "search", "--help")
  39. c.Assert(out, checker.Contains, "Usage:\tdocker search [OPTIONS] TERM")
  40. outSearchCmd, _ := dockerCmd(c, "search", "busybox")
  41. outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox")
  42. c.Assert(len(outSearchCmd) > len(outSearchCmdNotrunc), check.Equals, false, check.Commentf("The no-trunc option can't take effect."))
  43. outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
  44. outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
  45. for i := range outSearchCmdautomatedSlice {
  46. c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", outSearchCmdautomated))
  47. }
  48. outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") //The busybox is a busybox base image, official image.
  49. outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n")
  50. for i := range outSearchCmdNotOfficialSlice {
  51. c.Assert(strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial))
  52. }
  53. outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") //The busybox is a busybox base image, official image.
  54. outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n")
  55. c.Assert(outSearchCmdOfficialSlice, checker.HasLen, 3) // 1 header, 1 line, 1 carriage return
  56. c.Assert(strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), check.Equals, true, check.Commentf("The busybox is an OFFICIAL image: %s", outSearchCmdNotOfficial))
  57. outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=2", "busybox")
  58. c.Assert(strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]"), check.Equals, false, check.Commentf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars))
  59. dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox")
  60. // --automated deprecated since Docker 1.13
  61. outSearchCmdautomated1, _ := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
  62. outSearchCmdautomatedSlice1 := strings.Split(outSearchCmdautomated1, "\n")
  63. for i := range outSearchCmdautomatedSlice1 {
  64. c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice1[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", outSearchCmdautomated))
  65. }
  66. // -s --stars deprecated since Docker 1.13
  67. outSearchCmdStars1, _ := dockerCmd(c, "search", "--stars=2", "busybox")
  68. c.Assert(strings.Count(outSearchCmdStars1, "[OK]") > strings.Count(outSearchCmd, "[OK]"), check.Equals, false, check.Commentf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars1))
  69. // -s --stars deprecated since Docker 1.13
  70. dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
  71. }
  72. // search for repos which start with "ubuntu-" on the central registry
  73. func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
  74. testRequires(c, Network, DaemonIsLinux)
  75. dockerCmd(c, "search", "ubuntu-")
  76. }
  77. // test case for #23055
  78. func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
  79. testRequires(c, Network, DaemonIsLinux)
  80. limit := 10
  81. out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  82. c.Assert(err, checker.IsNil)
  83. outSlice := strings.Split(out, "\n")
  84. c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
  85. limit = 50
  86. out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  87. c.Assert(err, checker.IsNil)
  88. outSlice = strings.Split(out, "\n")
  89. c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
  90. limit = 100
  91. out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  92. c.Assert(err, checker.IsNil)
  93. outSlice = strings.Split(out, "\n")
  94. c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
  95. limit = 0
  96. out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  97. c.Assert(err, checker.Not(checker.IsNil))
  98. limit = 200
  99. out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  100. c.Assert(err, checker.Not(checker.IsNil))
  101. }