From 97ab9176f77c4fc9c4413afad4d2dcf5fad824b6 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Mon, 22 Nov 2021 10:54:22 -0700 Subject: e2e tests: clean up antihelpful BeTrue()s Many ginkgo tests have been written to use this evil form: GrepString("foo") Expect(that to BeTrue()) ...which yields horrible useless messages on failure: false is not true Identify those (automatically, via script) and convert to: Expect(output to ContainSubstring("foo")) ...which yields: "this output" does not contain substring "foo" There are still many BeTrue()s left. This is just a start. This is commit 1 of 2. It includes the script I used, and all changes to *.go are those computed by the script. Commit 2 will apply some manual fixes. Signed-off-by: Ed Santiago --- test/e2e/port_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/e2e/port_test.go') diff --git a/test/e2e/port_test.go b/test/e2e/port_test.go index e5c7576ae..b502fa61f 100644 --- a/test/e2e/port_test.go +++ b/test/e2e/port_test.go @@ -62,7 +62,7 @@ var _ = Describe("Podman port", func() { result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) port := strings.Split(result.OutputToStringArray()[0], ":")[1] - Expect(result.LineInOutputStartsWith(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port))).To(BeTrue()) + Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port)))) }) It("podman container port -l nginx", func() { @@ -80,7 +80,7 @@ var _ = Describe("Podman port", func() { result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) port := strings.Split(result.OutputToStringArray()[0], ":")[1] - Expect(result.LineInOutputStartsWith(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port))).To(BeTrue()) + Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port)))) }) It("podman port -l port nginx", func() { @@ -98,7 +98,7 @@ var _ = Describe("Podman port", func() { result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) port := strings.Split(result.OutputToStringArray()[0], ":")[1] - Expect(result.LineInOutputStartsWith(fmt.Sprintf("0.0.0.0:%s", port))).To(BeTrue()) + Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("0.0.0.0:%s", port)))) }) It("podman port -a nginx", func() { @@ -143,12 +143,12 @@ var _ = Describe("Podman port", func() { result1 := podmanTest.Podman([]string{"port", "test", "5000"}) result1.WaitWithDefaultTimeout() Expect(result1).Should(Exit(0)) - Expect(result1.LineInOutputStartsWith("0.0.0.0:5000")).To(BeTrue()) + Expect(result1.OutputToStringArray()).To(ContainElement(HavePrefix("0.0.0.0:5000"))) // Check that the second port was honored result2 := podmanTest.Podman([]string{"port", "test", "5001"}) result2.WaitWithDefaultTimeout() Expect(result2).Should(Exit(0)) - Expect(result2.LineInOutputStartsWith("0.0.0.0:5001")).To(BeTrue()) + Expect(result2.OutputToStringArray()).To(ContainElement(HavePrefix("0.0.0.0:5001"))) }) }) -- cgit v1.2.3-54-g00ecf From 49d63ad5c120919ff6669baae2ebbd2b81f5c11a Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Mon, 22 Nov 2021 13:28:43 -0700 Subject: Oops! Manual edits to broken tests Commit 2 of 2: there were (still are?) a bunch of string checks that didn't have a corresponding Expect(). IIUC that means they were NOPs. Try to identify and fix those. The first few were caught by Go linting, "ok is defined but not used". When I realized the problem, I looked for more using: $ ack -A2 LineInOutputStartsWith ...and tediously eyeballing the results, looking for matches in which the next line was not Expect(). If test was wrong (e.g. "server" should've been "nameserver"), fix that. Also: remove the remove-betrue script. We don't need it in the repo, I just wanted to preserve it for posterity. Signed-off-by: Ed Santiago --- test/e2e/containers_conf_test.go | 6 ++--- test/e2e/port_test.go | 2 +- test/e2e/remove-betrue | 48 ---------------------------------------- test/e2e/run_dns_test.go | 11 ++++----- test/e2e/run_userns_test.go | 6 ++--- 5 files changed, 13 insertions(+), 60 deletions(-) delete mode 100755 test/e2e/remove-betrue (limited to 'test/e2e/port_test.go') diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go index 7c3b07714..6a760da17 100644 --- a/test/e2e/containers_conf_test.go +++ b/test/e2e/containers_conf_test.go @@ -224,21 +224,21 @@ var _ = Describe("Podman run", func() { session := podmanTest.Podman([]string{"run", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("search foobar.com") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("search foobar.com"))) }) It("podman run add dns server", func() { session := podmanTest.Podman([]string{"run", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("server 1.2.3.4") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("nameserver 1.2.3.4"))) }) It("podman run add dns option", func() { session := podmanTest.Podman([]string{"run", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("options debug") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("options debug"))) }) It("podman run containers.conf remove all search domain", func() { diff --git a/test/e2e/port_test.go b/test/e2e/port_test.go index b502fa61f..776687113 100644 --- a/test/e2e/port_test.go +++ b/test/e2e/port_test.go @@ -125,7 +125,7 @@ var _ = Describe("Podman port", func() { result := podmanTest.Podman([]string{"port", "portcheck"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - result.LineInOutputStartsWith("80/tcp -> 0.0.0.0:") + Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix("80/tcp -> 0.0.0.0:"))) }) It("podman port multiple ports", func() { diff --git a/test/e2e/remove-betrue b/test/e2e/remove-betrue deleted file mode 100755 index dd56ca818..000000000 --- a/test/e2e/remove-betrue +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/perl -# -# one-shot script for #12387 -# -use warnings; -use strict; -use File::Basename qw(dirname); - -chdir(dirname($0)); - -for my $f (glob('*_test.go')) { - my ($indent, $okvar, $sessionvar, $s); - my $prev = ''; - - open my $fh_in, '<', $f or die; - open my $fh_out, '>', "$f.tmp.$$" or die; - while (<$fh_in>) { - if (/^(\s+)(\S+),\s+_\s+:?=\s+(\S+)\.GrepString\((.*)\)/) { - print { $fh_out } $prev; - $prev = $_; - ($indent, $okvar, $sessionvar, $s) = ($1, $2, $3, $4); - next; - } - elsif ($okvar && /^\s+Expect\($okvar\)\.(Should|To)\(BeTrue\(\)\)\s*$/) { - print { $fh_out} $indent, "Expect($sessionvar.OutputToString()).To(ContainSubstring($s))\n"; - $okvar = $sessionvar = $s = $prev = ''; - next; - } - else { - print { $fh_out } $prev; - $prev = $_; - $okvar = $sessionvar = $s = ''; - - # Handle other common cases - $prev =~ s{ -^ (\s+) Expect\((\S+)\.LineInOutputContains\((.*?)\)\)\.To\(BeTrue\(\)\) - }{${1}Expect($2.OutputToString()).To(ContainSubstring($3))}xx; - - $prev =~ s{ -^ (\s+) Expect\((\S+)\.LineInOutputStartsWith\((.*)\)\)\.To\(BeTrue\(\)\) - }{${1}Expect($2.OutputToStringArray()).To(ContainElement(HavePrefix($3)))}xx; - - } - } - print { $fh_out } $prev; - close $fh_out or die; - rename "$f.tmp.$$" => "$f" or die; -} diff --git a/test/e2e/run_dns_test.go b/test/e2e/run_dns_test.go index 01f40b1fc..beb6390e0 100644 --- a/test/e2e/run_dns_test.go +++ b/test/e2e/run_dns_test.go @@ -37,7 +37,7 @@ var _ = Describe("Podman run dns", func() { session := podmanTest.Podman([]string{"run", "--dns-search=foobar.com", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("search foobar.com") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("search foobar.com"))) }) It("podman run remove all search domain", func() { @@ -57,14 +57,15 @@ var _ = Describe("Podman run dns", func() { session := podmanTest.Podman([]string{"run", "--dns=1.2.3.4", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("server 1.2.3.4") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("nameserver 1.2.3.4"))) + }) It("podman run add dns option", func() { session := podmanTest.Podman([]string{"run", "--dns-opt=debug", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("options debug") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("options debug"))) }) It("podman run add bad host", func() { @@ -77,8 +78,8 @@ var _ = Describe("Podman run dns", func() { session := podmanTest.Podman([]string{"run", "--add-host=foobar:1.1.1.1", "--add-host=foobaz:2001:db8::68", ALPINE, "cat", "/etc/hosts"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session.LineInOutputStartsWith("1.1.1.1 foobar") - session.LineInOutputStartsWith("2001:db8::68 foobaz") + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("1.1.1.1 foobar"))) + Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("2001:db8::68 foobaz"))) }) It("podman run add hostname", func() { diff --git a/test/e2e/run_userns_test.go b/test/e2e/run_userns_test.go index 0d4b327b9..9b981ef72 100644 --- a/test/e2e/run_userns_test.go +++ b/test/e2e/run_userns_test.go @@ -180,17 +180,17 @@ var _ = Describe("Podman UserNS support", func() { session := podmanTest.Podman([]string{"run", "--userns=auto:size=500", "alpine", "cat", "/proc/self/uid_map"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - ok, _ := session.GrepString("500") + Expect(session.OutputToString()).To(ContainSubstring("500")) session = podmanTest.Podman([]string{"run", "--userns=auto:size=3000", "alpine", "cat", "/proc/self/uid_map"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - ok, _ = session.GrepString("3000") + Expect(session.OutputToString()).To(ContainSubstring("3000")) session = podmanTest.Podman([]string{"run", "--userns=auto", "--user=2000:3000", "alpine", "cat", "/proc/self/uid_map"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - ok, _ = session.GrepString("3001") + Expect(session.OutputToString()).To(ContainSubstring("3001")) session = podmanTest.Podman([]string{"run", "--userns=auto", "--user=4000:1000", "alpine", "cat", "/proc/self/uid_map"}) session.WaitWithDefaultTimeout() -- cgit v1.2.3-54-g00ecf