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

Commit 5890458

Browse files
committed
TestSearchWithLimit: slight refactor and improve boundary checks
Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 2ac55d5c9aa1255a9c9ec4a8b8eaea004fe0c418) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 3c63d7fd9bd101019c45643a3edf1d9ac29550d2 Component: engine
1 parent 3db0549 commit 5890458

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

components/engine/integration-cli/docker_cli_search_test.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,15 @@ func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
7474
func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
7575
testRequires(c, Network, DaemonIsLinux)
7676

77-
limit := 10
78-
out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
79-
assert.NilError(c, err)
80-
outSlice := strings.Split(out, "\n")
81-
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
82-
83-
limit = 50
84-
out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
85-
assert.NilError(c, err)
86-
outSlice = strings.Split(out, "\n")
87-
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
88-
89-
limit = 100
90-
out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
91-
assert.NilError(c, err)
92-
outSlice = strings.Split(out, "\n")
93-
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
94-
95-
limit = 0
96-
_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
97-
assert.ErrorContains(c, err, "")
98-
99-
limit = 200
100-
_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
101-
assert.ErrorContains(c, err, "")
77+
for _, limit := range []int{10, 50, 100} {
78+
out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
79+
assert.NilError(c, err)
80+
outSlice := strings.Split(out, "\n")
81+
assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return
82+
}
83+
84+
for _, limit := range []int{-1, 0, 101} {
85+
_, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
86+
assert.ErrorContains(c, err, "")
87+
}
10288
}

0 commit comments

Comments
 (0)