From b13e995c7829458b949e486cd940e56aaea88d36 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 22 May 2019 14:55:14 +0200 Subject: [PATCH 1/6] Revert "Remove TestSearchCmdOptions test" This reverts commit 21e662c77468d1e3fc4efaa049021e2ad0e49b4d. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 1be7065e99989e994e43129669ebb7d732f42d10) Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_search_test.go | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index 95ad9ce1b2..13870a8fce 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -44,6 +44,54 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) { assert.Assert(c, strings.Contains(out, "invalid syntax"), "couldn't find the invalid value warning") } +func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { + testRequires(c, Network, DaemonIsLinux) + + out, _ := dockerCmd(c, "search", "--help") + assert.Assert(c, strings.Contains(out, "Usage:\tdocker search [OPTIONS] TERM")) + + outSearchCmd, _ := dockerCmd(c, "search", "busybox") + assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd) + outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox") + assert.Assert(c, len(outSearchCmd) <= len(outSearchCmdNotrunc), "The no-trunc option can't take effect.") + + outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. + outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n") + for i := range outSearchCmdautomatedSlice { + assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated) + } + + outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") //The busybox is a busybox base image, official image. + outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n") + for i := range outSearchCmdNotOfficialSlice { + assert.Assert(c, !strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), "The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial) + } + + outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") //The busybox is a busybox base image, official image. + outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n") + assert.Equal(c, len(outSearchCmdOfficialSlice), 3) // 1 header, 1 line, 1 carriage return + assert.Assert(c, strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), "The busybox is an OFFICIAL image: %s", outSearchCmdOfficial) + + outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=10", "busybox") + 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) + + dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox") + + // --automated deprecated since Docker 1.13 + outSearchCmdautomated1, _ := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. + outSearchCmdautomatedSlice1 := strings.Split(outSearchCmdautomated1, "\n") + for i := range outSearchCmdautomatedSlice1 { + assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice1[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated) + } + + // -s --stars deprecated since Docker 1.13 + outSearchCmdStars1, _ := dockerCmd(c, "search", "--stars=2", "busybox") + assert.Assert(c, strings.Count(outSearchCmdStars1, "[OK]") <= strings.Count(outSearchCmd, "[OK]"), "The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars1) + + // -s --stars deprecated since Docker 1.13 + dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox") +} + // search for repos which start with "ubuntu-" on the central registry func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) { testRequires(c, Network, DaemonIsLinux) From 9557c7be8e890351089b1c319c980adf7fe3ee09 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 17 Jul 2019 12:34:20 +0200 Subject: [PATCH 2/6] TestSearchCmdOptions: remove cli-only checks Both `--help` and `--no-trunc` are implemented in the CLI. There's no need to verify them here because the integration tests use a fixed version of the CLI. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit a78b9a372692ea034bc340df098f3ee058939ca6) Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_search_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index 13870a8fce..2d7ee1a9db 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -47,13 +47,8 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) { func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { testRequires(c, Network, DaemonIsLinux) - out, _ := dockerCmd(c, "search", "--help") - assert.Assert(c, strings.Contains(out, "Usage:\tdocker search [OPTIONS] TERM")) - outSearchCmd, _ := dockerCmd(c, "search", "busybox") assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd) - outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox") - assert.Assert(c, len(outSearchCmd) <= len(outSearchCmdNotrunc), "The no-trunc option can't take effect.") outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n") From 665c5d0c5f08cfa4febfcc415dc976b343615cbd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 17 Jul 2019 12:47:57 +0200 Subject: [PATCH 3/6] TestSearchCmdOptions: remove checks for deprecated flags The `--stars` and `--automated` flags have been deprecated, and were replaced by `--filter stars=xx` and `--filter is-automated=true`. Integration tests run with a fixed version of the CLI, and the new (`--filter`) option is already tested in this test, so there's no need to verify the old flags. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b38c71bfe06ddb663aa4919ff9c496c395311985) Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_search_test.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index 2d7ee1a9db..663a226fb7 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -71,20 +71,6 @@ func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { 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) dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox") - - // --automated deprecated since Docker 1.13 - outSearchCmdautomated1, _ := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. - outSearchCmdautomatedSlice1 := strings.Split(outSearchCmdautomated1, "\n") - for i := range outSearchCmdautomatedSlice1 { - assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice1[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated) - } - - // -s --stars deprecated since Docker 1.13 - outSearchCmdStars1, _ := dockerCmd(c, "search", "--stars=2", "busybox") - assert.Assert(c, strings.Count(outSearchCmdStars1, "[OK]") <= strings.Count(outSearchCmd, "[OK]"), "The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars1) - - // -s --stars deprecated since Docker 1.13 - dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox") } // search for repos which start with "ubuntu-" on the central registry From 96af5bfbb517b32d946eca7cb8d0e9976846abc8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 17 Jul 2019 13:07:17 +0200 Subject: [PATCH 4/6] TestSearchStarsOptionWithWrongParameter: remove checks for deprecated flags The `--stars` flag was deprecated, and was replaced by `--filter stars=xx` Integration tests run with a fixed version of the CLI, and the new (`--filter`) option is already tested in this test, so there's no need to verify the old flags. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 85d6fb888c89ff0124b32d7df5485656e2d48b8e) Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_search_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index 663a226fb7..e13b48b7a2 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -32,16 +32,6 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) { out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox") assert.ErrorContains(c, err, "", out) assert.Assert(c, strings.Contains(out, "Invalid filter"), "couldn't find the invalid filter warning") - - // -s --stars deprecated since Docker 1.13 - out, _, err = dockerCmdWithError("search", "--stars=a", "busybox") - assert.ErrorContains(c, err, "", out) - assert.Assert(c, strings.Contains(out, "invalid syntax"), "couldn't find the invalid value warning") - - // -s --stars deprecated since Docker 1.13 - out, _, err = dockerCmdWithError("search", "-s=-1", "busybox") - assert.ErrorContains(c, err, "", out) - assert.Assert(c, strings.Contains(out, "invalid syntax"), "couldn't find the invalid value warning") } func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { From 3c63d7fd9bd101019c45643a3edf1d9ac29550d2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 17 Jul 2019 13:09:17 +0200 Subject: [PATCH 5/6] TestSearchWithLimit: slight refactor and improve boundary checks Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 2ac55d5c9aa1255a9c9ec4a8b8eaea004fe0c418) Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_search_test.go | 34 +++++++---------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index e13b48b7a2..f9ec2c3017 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -74,29 +74,15 @@ func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) { func (s *DockerSuite) TestSearchWithLimit(c *check.C) { testRequires(c, Network, DaemonIsLinux) - limit := 10 - out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - assert.NilError(c, err) - outSlice := strings.Split(out, "\n") - assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return + for _, limit := range []int{10, 50, 100} { + out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") + assert.NilError(c, err) + outSlice := strings.Split(out, "\n") + assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return + } - limit = 50 - out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - assert.NilError(c, err) - outSlice = strings.Split(out, "\n") - assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return - - limit = 100 - out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - assert.NilError(c, err) - outSlice = strings.Split(out, "\n") - assert.Equal(c, len(outSlice), limit+2) // 1 header, 1 carriage return - - limit = 0 - _, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - assert.ErrorContains(c, err, "") - - limit = 200 - _, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - assert.ErrorContains(c, err, "") + for _, limit := range []int{-1, 0, 101} { + _, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") + assert.ErrorContains(c, err, "") + } } From bc5df6869845b4f14d0e8476fd2376caca935d42 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 17 Jul 2019 13:10:27 +0200 Subject: [PATCH 6/6] integration-cli: also run Docker Hub search tests on Windows The API does not filter images on platform, so searching on Windows should work as well. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 3d1850d10d7f485f7ee7488a69f165707bf51480) Signed-off-by: Sebastiaan van Stijn --- integration-cli/docker_cli_search_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index f9ec2c3017..4226453ca0 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -10,8 +10,6 @@ import ( // search for repos named "registry" on the central registry func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - out, _ := dockerCmd(c, "search", "busybox") assert.Assert(c, strings.Contains(out, "Busybox base image."), "couldn't find any repository named (or containing) 'Busybox base image.'") } @@ -35,8 +33,6 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) { } func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - outSearchCmd, _ := dockerCmd(c, "search", "busybox") assert.Assert(c, strings.Count(outSearchCmd, "\n") > 3, outSearchCmd) @@ -65,15 +61,11 @@ func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { // search for repos which start with "ubuntu-" on the central registry func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - dockerCmd(c, "search", "ubuntu-") } // test case for #23055 func (s *DockerSuite) TestSearchWithLimit(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - for _, limit := range []int{10, 50, 100} { out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") assert.NilError(c, err)