From 6752cc9f2f8350ce4759353faee13556e948d62a Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 21 May 2019 01:33:15 -0700 Subject: [PATCH 1/2] int-cli/TestSearchCmdOptions: fail earlier Sometimes this test fails (allegedly due to problems with Docker Hub), but it fails later than it should, for example: > 01:20:34.845 assertion failed: expression is false: strings.Count(outSearchCmdStars, "[OK]") <= strings.Count(outSearchCmd, "[OK]"): The quantity of images with stars should be less than that of all images: <...> This, with non-empty list of images following, means that the initial `docker search busybox` command returned not enough results. So, add a check that `docker search busybox` returns something. While at it, * raise the number of stars to 10; * simplify check for number of lines (no need to count [OK]'s); * improve error message. Signed-off-by: Kir Kolyshkin (cherry picked from commit 4f80a1953d66265d9a1cbf4e172b8fa58e3e403a) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 8a369c735b2bf07da53275fe9fe61d429320f233 Component: engine --- components/engine/integration-cli/docker_cli_search_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/engine/integration-cli/docker_cli_search_test.go b/components/engine/integration-cli/docker_cli_search_test.go index 2f811d4b96..13870a8fce 100644 --- a/components/engine/integration-cli/docker_cli_search_test.go +++ b/components/engine/integration-cli/docker_cli_search_test.go @@ -51,8 +51,8 @@ func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { 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. @@ -72,8 +72,8 @@ func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { 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=2", "busybox") - assert.Assert(c, strings.Count(outSearchCmdStars, "[OK]") <= strings.Count(outSearchCmd, "[OK]"), "The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars) + 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") From 9a388b1aa0e7da978fc4028a4eebd69473f11817 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 22 May 2019 14:47:40 +0200 Subject: [PATCH 2/2] Remove TestSearchCmdOptions test This test is dependent on the search results returned by Docker Hub, which can change at any moment, and causes this test to be unpredictable. Removing this test instead of trying to catch up with Docker Hub any time the results change, because it's effectively testing Docker Hub, and not the daemon. Unit tests are already in place to test the core functionality of the daemon, so it should be safe to remove this test. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 21e662c77468d1e3fc4efaa049021e2ad0e49b4d) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 0d052bc40e908f1f596b0f16840b4e93fc6a9ec2 Component: engine --- .../integration-cli/docker_cli_search_test.go | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/components/engine/integration-cli/docker_cli_search_test.go b/components/engine/integration-cli/docker_cli_search_test.go index 13870a8fce..95ad9ce1b2 100644 --- a/components/engine/integration-cli/docker_cli_search_test.go +++ b/components/engine/integration-cli/docker_cli_search_test.go @@ -44,54 +44,6 @@ 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)