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