docker_cli_search_test.go 3.9 KB

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