Преглед изворни кода

Merge pull request #12018 from sunyuan3/search

If docker search with --starts=${negative number}, it would show the war...
Doug Davis пре 10 година
родитељ
комит
2c5da7d1ac
2 измењених фајлова са 27 додато и 3 уклоњено
  1. 3 3
      api/client/search.go
  2. 24 0
      integration-cli/docker_cli_search_test.go

+ 3 - 3
api/client/search.go

@@ -21,7 +21,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
 	noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
 	noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
 	trusted := cmd.Bool([]string{"#t", "#trusted", "#-trusted"}, false, "Only show trusted builds")
 	trusted := cmd.Bool([]string{"#t", "#trusted", "#-trusted"}, false, "Only show trusted builds")
 	automated := cmd.Bool([]string{"-automated"}, false, "Only show automated builds")
 	automated := cmd.Bool([]string{"-automated"}, false, "Only show automated builds")
-	stars := cmd.Int([]string{"s", "#stars", "-stars"}, 0, "Only displays with at least x stars")
+	stars := cmd.Uint([]string{"s", "#stars", "-stars"}, 0, "Only displays with at least x stars")
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
 	cmd.ParseFlags(args, true)
 	cmd.ParseFlags(args, true)
@@ -53,7 +53,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
 	w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0)
 	w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0)
 	fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n")
 	fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n")
 	for _, out := range outs.Data {
 	for _, out := range outs.Data {
-		if ((*automated || *trusted) && (!out.GetBool("is_trusted") && !out.GetBool("is_automated"))) || (*stars > out.GetInt("star_count")) {
+		if ((*automated || *trusted) && (!out.GetBool("is_trusted") && !out.GetBool("is_automated"))) || (*stars > uint(out.GetInt("star_count"))) {
 			continue
 			continue
 		}
 		}
 		desc := strings.Replace(out.Get("description"), "\n", " ", -1)
 		desc := strings.Replace(out.Get("description"), "\n", " ", -1)
@@ -61,7 +61,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
 		if !*noTrunc && len(desc) > 45 {
 		if !*noTrunc && len(desc) > 45 {
 			desc = utils.Trunc(desc, 42) + "..."
 			desc = utils.Trunc(desc, 42) + "..."
 		}
 		}
-		fmt.Fprintf(w, "%s\t%s\t%d\t", out.Get("name"), desc, out.GetInt("star_count"))
+		fmt.Fprintf(w, "%s\t%s\t%d\t", out.Get("name"), desc, uint(out.GetInt("star_count")))
 		if out.GetBool("is_official") {
 		if out.GetBool("is_official") {
 			fmt.Fprint(w, "[OK]")
 			fmt.Fprint(w, "[OK]")
 
 

+ 24 - 0
integration-cli/docker_cli_search_test.go

@@ -21,3 +21,27 @@ func TestSearchOnCentralRegistry(t *testing.T) {
 
 
 	logDone("search - search for repositories named (or containing) 'Busybox base image.'")
 	logDone("search - search for repositories named (or containing) 'Busybox base image.'")
 }
 }
+
+func TestSearchStarsOptionWithWrongParameter(t *testing.T) {
+	searchCmdStarsChars := exec.Command(dockerBinary, "search", "--stars=a", "busybox")
+	out, exitCode, err := runCommandWithOutput(searchCmdStarsChars)
+	if err == nil || exitCode == 0 {
+		t.Fatalf("Should not get right information: %s, %v", out, err)
+	}
+
+	if !strings.Contains(out, "invalid value") {
+		t.Fatal("couldn't find the invalid value warning")
+	}
+
+	searchCmdStarsNegativeNumber := exec.Command(dockerBinary, "search", "-s=-1", "busybox")
+	out, exitCode, err = runCommandWithOutput(searchCmdStarsNegativeNumber)
+	if err == nil || exitCode == 0 {
+		t.Fatalf("Should not get right information: %s, %v", out, err)
+	}
+
+	if !strings.Contains(out, "invalid value") {
+		t.Fatal("couldn't find the invalid value warning")
+	}
+
+	logDone("search - Verify search with wrong parameter.")
+}