[19.03 backport] Revert "Remove TestSearchCmdOptions test"
| ... | ... |
@@ -10,8 +10,6 @@ import ( |
| 10 | 10 |
|
| 11 | 11 |
// search for repos named "registry" on the central registry |
| 12 | 12 |
func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
|
| 13 |
- testRequires(c, Network, DaemonIsLinux) |
|
| 14 |
- |
|
| 15 | 13 |
out, _ := dockerCmd(c, "search", "busybox") |
| 16 | 14 |
assert.Assert(c, strings.Contains(out, "Busybox base image."), "couldn't find any repository named (or containing) 'Busybox base image.'") |
| 17 | 15 |
} |
| ... | ... |
@@ -32,52 +30,51 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
|
| 32 | 32 |
out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox")
|
| 33 | 33 |
assert.ErrorContains(c, err, "", out) |
| 34 | 34 |
assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning") |
| 35 |
+} |
|
| 35 | 36 |
|
| 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") |
|
| 37 |
+func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
|
|
| 38 |
+ outSearchCmd, _ := dockerCmd(c, "search", "busybox") |
|
| 39 |
+ assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd) |
|
| 40 | 40 |
|
| 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") |
|
| 41 |
+ outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. |
|
| 42 |
+ outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n") |
|
| 43 |
+ for i := range outSearchCmdautomatedSlice {
|
|
| 44 |
+ assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated) |
|
| 45 |
+ } |
|
| 46 |
+ |
|
| 47 |
+ outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") //The busybox is a busybox base image, official image. |
|
| 48 |
+ outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n") |
|
| 49 |
+ for i := range outSearchCmdNotOfficialSlice {
|
|
| 50 |
+ assert.Assert(c, !strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), "The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial) |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") //The busybox is a busybox base image, official image. |
|
| 54 |
+ outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n") |
|
| 55 |
+ assert.Equal(c, len(outSearchCmdOfficialSlice), 3) // 1 header, 1 line, 1 carriage return |
|
| 56 |
+ assert.Assert(c, strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), "The busybox is an OFFICIAL image: %s", outSearchCmdOfficial) |
|
| 57 |
+ |
|
| 58 |
+ outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=10", "busybox") |
|
| 59 |
+ 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) |
|
| 60 |
+ |
|
| 61 |
+ dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox") |
|
| 45 | 62 |
} |
| 46 | 63 |
|
| 47 | 64 |
// search for repos which start with "ubuntu-" on the central registry |
| 48 | 65 |
func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
|
| 49 |
- testRequires(c, Network, DaemonIsLinux) |
|
| 50 |
- |
|
| 51 | 66 |
dockerCmd(c, "search", "ubuntu-") |
| 52 | 67 |
} |
| 53 | 68 |
|
| 54 | 69 |
// test case for #23055 |
| 55 | 70 |
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, "") |
|
| 71 |
+ for _, limit := range []int{10, 50, 100} {
|
|
| 72 |
+ out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
|
|
| 73 |
+ assert.NilError(c, err) |
|
| 74 |
+ outSlice := strings.Split(out, "\n") |
|
| 75 |
+ assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return |
|
| 76 |
+ } |
|
| 77 |
+ |
|
| 78 |
+ for _, limit := range []int{-1, 0, 101} {
|
|
| 79 |
+ _, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
|
|
| 80 |
+ assert.ErrorContains(c, err, "") |
|
| 81 |
+ } |
|
| 83 | 82 |
} |