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