docker_cli_search_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package main
  2. import (
  3. "strings"
  4. "github.com/go-check/check"
  5. )
  6. // search for repos named "registry" on the central registry
  7. func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
  8. testRequires(c, Network, DaemonIsLinux)
  9. out, exitCode := dockerCmd(c, "search", "busybox")
  10. if exitCode != 0 {
  11. c.Fatalf("failed to search on the central registry: %s", out)
  12. }
  13. if !strings.Contains(out, "Busybox base image.") {
  14. c.Fatal("couldn't find any repository named (or containing) 'Busybox base image.'")
  15. }
  16. }
  17. func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
  18. out, exitCode, err := dockerCmdWithError("search", "--stars=a", "busybox")
  19. if err == nil || exitCode == 0 {
  20. c.Fatalf("Should not get right information: %s, %v", out, err)
  21. }
  22. if !strings.Contains(out, "invalid value") {
  23. c.Fatal("couldn't find the invalid value warning")
  24. }
  25. out, exitCode, err = dockerCmdWithError("search", "-s=-1", "busybox")
  26. if err == nil || exitCode == 0 {
  27. c.Fatalf("Should not get right information: %s, %v", out, err)
  28. }
  29. if !strings.Contains(out, "invalid value") {
  30. c.Fatal("couldn't find the invalid value warning")
  31. }
  32. }
  33. func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
  34. testRequires(c, Network)
  35. out, exitCode := dockerCmd(c, "search", "--help")
  36. if exitCode != 0 {
  37. c.Fatalf("failed to get search help information: %s", out)
  38. }
  39. if !strings.Contains(out, "Usage:\tdocker search [OPTIONS] TERM") {
  40. c.Fatalf("failed to show docker search usage: %s", out)
  41. }
  42. outSearchCmd, exitCode := dockerCmd(c, "search", "busybox")
  43. if exitCode != 0 {
  44. c.Fatalf("failed to search on the central registry: %s", outSearchCmd)
  45. }
  46. outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox")
  47. if len(outSearchCmd) > len(outSearchCmdNotrunc) {
  48. c.Fatalf("The no-trunc option can't take effect.")
  49. }
  50. outSearchCmdautomated, exitCode := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
  51. if exitCode != 0 {
  52. c.Fatalf("failed to search with automated=true on the central registry: %s", outSearchCmdautomated)
  53. }
  54. outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
  55. for i := range outSearchCmdautomatedSlice {
  56. if strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox ") {
  57. c.Fatalf("The busybox is not an AUTOMATED image: %s", out)
  58. }
  59. }
  60. outSearchCmdStars, exitCode := dockerCmd(c, "search", "-s=2", "busybox")
  61. if exitCode != 0 {
  62. c.Fatalf("failed to search with stars=2 on the central registry: %s", outSearchCmdStars)
  63. }
  64. if strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]") {
  65. c.Fatalf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars)
  66. }
  67. out, exitCode = dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
  68. if exitCode != 0 {
  69. c.Fatalf("failed to search with stars&automated&no-trunc options on the central registry: %s", out)
  70. }
  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. out, exitCode := dockerCmd(c, "search", "ubuntu-")
  76. c.Assert(exitCode, check.Equals, 0, check.Commentf("failed to search on the central registry: %s", out))
  77. }