docker_cli_search_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "strings"
  4. "github.com/docker/docker/pkg/integration/checker"
  5. "github.com/go-check/check"
  6. )
  7. // search for repos named "registry" on the central registry
  8. func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
  9. testRequires(c, Network, DaemonIsLinux)
  10. out, _ := dockerCmd(c, "search", "busybox")
  11. c.Assert(out, checker.Contains, "Busybox base image.", check.Commentf("couldn't find any repository named (or containing) 'Busybox base image.'"))
  12. }
  13. func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
  14. out, _, err := dockerCmdWithError("search", "--stars=a", "busybox")
  15. c.Assert(err, check.NotNil, check.Commentf(out))
  16. c.Assert(out, checker.Contains, "invalid value", check.Commentf("couldn't find the invalid value warning"))
  17. out, _, err = dockerCmdWithError("search", "-s=-1", "busybox")
  18. c.Assert(err, check.NotNil, check.Commentf(out))
  19. c.Assert(out, checker.Contains, "invalid value", check.Commentf("couldn't find the invalid value warning"))
  20. }
  21. func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
  22. testRequires(c, Network)
  23. out, _ := dockerCmd(c, "search", "--help")
  24. c.Assert(out, checker.Contains, "Usage:\tdocker search [OPTIONS] TERM")
  25. outSearchCmd, _ := dockerCmd(c, "search", "busybox")
  26. outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox")
  27. c.Assert(len(outSearchCmd) > len(outSearchCmdNotrunc), check.Equals, false, check.Commentf("The no-trunc option can't take effect."))
  28. outSearchCmdautomated, _ := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
  29. outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
  30. for i := range outSearchCmdautomatedSlice {
  31. c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", out))
  32. }
  33. outSearchCmdStars, _ := dockerCmd(c, "search", "-s=2", "busybox")
  34. 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))
  35. dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
  36. }
  37. // search for repos which start with "ubuntu-" on the central registry
  38. func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
  39. testRequires(c, Network, DaemonIsLinux)
  40. dockerCmd(c, "search", "ubuntu-")
  41. }