docker_cli_search_test.go 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "testing"
  6. "gotest.tools/assert"
  7. )
  8. // search for repos named "registry" on the central registry
  9. func (s *DockerSuite) TestSearchOnCentralRegistry(c *testing.T) {
  10. out, _ := dockerCmd(c, "search", "busybox")
  11. assert.Assert(c, strings.Contains(out, "Busybox base image."), "couldn't find any repository named (or containing) 'Busybox base image.'")
  12. }
  13. func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *testing.T) {
  14. out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox")
  15. assert.ErrorContains(c, err, "", out)
  16. assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
  17. out, _, err = dockerCmdWithError("search", "-f", "stars=a", "busybox")
  18. assert.ErrorContains(c, err, "", out)
  19. assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
  20. out, _, err = dockerCmdWithError("search", "-f", "is-automated=a", "busybox")
  21. assert.ErrorContains(c, err, "", out)
  22. assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
  23. out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox")
  24. assert.ErrorContains(c, err, "", out)
  25. assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
  26. }
  27. func (s *DockerSuite) TestSearchCmdOptions(c *testing.T) {
  28. outSearchCmd, _ := dockerCmd(c, "search", "busybox")
  29. assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd)
  30. outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") // The busybox is a busybox base image, not an AUTOMATED image.
  31. outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
  32. for i := range outSearchCmdautomatedSlice {
  33. assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated)
  34. }
  35. outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") // The busybox is a busybox base image, official image.
  36. outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n")
  37. for i := range outSearchCmdNotOfficialSlice {
  38. assert.Assert(c, !strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), "The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial)
  39. }
  40. outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") // The busybox is a busybox base image, official image.
  41. outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n")
  42. assert.Equal(c, len(outSearchCmdOfficialSlice), 3) // 1 header, 1 line, 1 carriage return
  43. assert.Assert(c, strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), "The busybox is an OFFICIAL image: %s", outSearchCmdOfficial)
  44. outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=10", "busybox")
  45. assert.Assert(c, strings.Count(outSearchCmdStars, "\n") <= strings.Count(outSearchCmd, "\n"), "Number of images with 10+ stars should be less than that of all images:\noutSearchCmdStars: %s\noutSearch: %s\n", outSearchCmdStars, outSearchCmd)
  46. dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox")
  47. }
  48. // search for repos which start with "ubuntu-" on the central registry
  49. func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *testing.T) {
  50. dockerCmd(c, "search", "ubuntu-")
  51. }
  52. // test case for #23055
  53. func (s *DockerSuite) TestSearchWithLimit(c *testing.T) {
  54. for _, limit := range []int{10, 50, 100} {
  55. out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  56. assert.NilError(c, err)
  57. outSlice := strings.Split(out, "\n")
  58. assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
  59. }
  60. for _, limit := range []int{-1, 0, 101} {
  61. _, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
  62. assert.ErrorContains(c, err, "")
  63. }
  64. }