Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 2144efc

Browse files
authored
Merge pull request #354 from thaJeztah/19.03_backport_revert_remove_TestSearchCmdOptions
[19.03 backport] Revert "Remove TestSearchCmdOptions test" Upstream-commit: ff3dc8a7c421493f90a422d45a9bbd70210835f5 Component: engine
2 parents 6167038 + dc5a22b commit 2144efc

1 file changed

Lines changed: 36 additions & 39 deletions

File tree

components/engine/integration-cli/docker_cli_search_test.go

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010

1111
// search for repos named "registry" on the central registry
1212
func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
13-
testRequires(c, Network, DaemonIsLinux)
14-
1513
out, _ := dockerCmd(c, "search", "busybox")
1614
assert.Assert(c, strings.Contains(out, "Busybox base image."), "couldn't find any repository named (or containing) 'Busybox base image.'")
1715
}
@@ -32,52 +30,51 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
3230
out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox")
3331
assert.ErrorContains(c, err, "", out)
3432
assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning")
33+
}
3534

36-
// -s --stars deprecated since Docker 1.13
37-
out, _, err = dockerCmdWithError("search", "--stars=a", "busybox")
38-
assert.ErrorContains(c, err, "", out)
39-
assert.Assert(c, strings.Contains(out, "invalid syntax"), "couldn't find the invalid value warning")
35+
func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
36+
outSearchCmd, _ := dockerCmd(c, "search", "busybox")
37+
assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd)
4038

41-
// -s --stars deprecated since Docker 1.13
42-
out, _, err = dockerCmdWithError("search", "-s=-1", "busybox")
43-
assert.ErrorContains(c, err, "", out)
44-
assert.Assert(c, strings.Contains(out, "invalid syntax"), "couldn't find the invalid value warning")
39+
outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
40+
outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
41+
for i := range outSearchCmdautomatedSlice {
42+
assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated)
43+
}
44+
45+
outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") //The busybox is a busybox base image, official image.
46+
outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n")
47+
for i := range outSearchCmdNotOfficialSlice {
48+
assert.Assert(c, !strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), "The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial)
49+
}
50+
51+
outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") //The busybox is a busybox base image, official image.
52+
outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n")
53+
assert.Equal(c, len(outSearchCmdOfficialSlice), 3) // 1 header, 1 line, 1 carriage return
54+
assert.Assert(c, strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), "The busybox is an OFFICIAL image: %s", outSearchCmdOfficial)
55+
56+
outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=10", "busybox")
57+
assert.Assert(c, strings.Count(outSearchCmdStars, "\n") <= strings.Count(outSearchCmd, "\n"), "Number of images with 10+ stars should be less than that of all images:\noutSearchCmdStars: %s\noutSearch: %s\n", outSearchCmdStars, outSearchCmd)
58+
59+
dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox")
4560
}
4661

4762
// search for repos which start with "ubuntu-" on the central registry
4863
func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
49-
testRequires(c, Network, DaemonIsLinux)
50-
5164
dockerCmd(c, "search", "ubuntu-")
5265
}
5366

5467
// test case for #23055
5568
func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
56-
testRequires(c, Network, DaemonIsLinux)
57-
58-
limit := 10
59-
out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
60-
assert.NilError(c, err)
61-
outSlice := strings.Split(out, "\n")
62-
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
63-
64-
limit = 50
65-
out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
66-
assert.NilError(c, err)
67-
outSlice = strings.Split(out, "\n")
68-
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
69-
70-
limit = 100
71-
out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
72-
assert.NilError(c, err)
73-
outSlice = strings.Split(out, "\n")
74-
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
75-
76-
limit = 0
77-
_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
78-
assert.ErrorContains(c, err, "")
79-
80-
limit = 200
81-
_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
82-
assert.ErrorContains(c, err, "")
69+
for _, limit := range []int{10, 50, 100} {
70+
out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
71+
assert.NilError(c, err)
72+
outSlice := strings.Split(out, "\n")
73+
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
74+
}
75+
76+
for _, limit := range []int{-1, 0, 101} {
77+
_, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
78+
assert.ErrorContains(c, err, "")
79+
}
8380
}

0 commit comments

Comments
 (0)