docker_cli_search_test.go 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. searchCmdautomated := exec.Command(dockerBinary, "search", "--automated=true", "busybox")
  53. outSearchCmdautomated, exitCode, err := runCommandWithOutput(searchCmdautomated) //The busybox is a busybox base image, not an AUTOMATED image.
  54. if err != nil || exitCode != 0 {
  55. c.Fatalf("failed to search with automated=true on the central registry: %s, %v", outSearchCmdautomated, err)
  56. }
  57. outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
  58. for i := range outSearchCmdautomatedSlice {
  59. if strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox ") {
  60. c.Fatalf("The busybox is not an AUTOMATED image: %s, %v", out, err)
  61. }
  62. }
  63. searchCmdStars := exec.Command(dockerBinary, "search", "-s=2", "busybox")
  64. outSearchCmdStars, exitCode, err := runCommandWithOutput(searchCmdStars)
  65. if err != nil || exitCode != 0 {
  66. c.Fatalf("failed to search with stars=2 on the central registry: %s, %v", outSearchCmdStars, err)
  67. }
  68. if strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]") {
  69. c.Fatalf("The quantity of images with stars should be less than that of all images: %s, %v", outSearchCmdStars, err)
  70. }
  71. searchCmdOptions := exec.Command(dockerBinary, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
  72. out, exitCode, err = runCommandWithOutput(searchCmdOptions)
  73. if err != nil || exitCode != 0 {
  74. c.Fatalf("failed to search with stars&automated&no-trunc options on the central registry: %s, %v", out, err)
  75. }
  76. }