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/run_selinux_test.go | 51 +++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) (limited to 'test/e2e/run_selinux_test.go') diff --git a/test/e2e/run_selinux_test.go b/test/e2e/run_selinux_test.go index 3cb0663e0..cf63760cc 100644 --- a/test/e2e/run_selinux_test.go +++ b/test/e2e/run_selinux_test.go @@ -42,24 +42,21 @@ var _ = Describe("Podman run", func() { session := podmanTest.Podman([]string{"run", ALPINE, "cat", "/proc/self/attr/current"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_t")) }) It("podman run selinux grep test", func() { session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "label=level:s0:c1,c2", ALPINE, "cat", "/proc/self/attr/current"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("s0:c1,c2") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("s0:c1,c2")) }) It("podman run selinux disable test", func() { session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "label=disable", ALPINE, "cat", "/proc/self/attr/current"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("spc_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("spc_t")) }) It("podman run selinux type check test", func() { @@ -75,88 +72,77 @@ var _ = Describe("Podman run", func() { session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "label=type:spc_t", ALPINE, "cat", "/proc/self/attr/current"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("spc_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("spc_t")) }) It("podman privileged selinux", func() { session := podmanTest.Podman([]string{"run", "--privileged", ALPINE, "cat", "/proc/self/attr/current"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("spc_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("spc_t")) }) It("podman test selinux label resolv.conf", func() { session := podmanTest.Podman([]string{"run", fedoraMinimal, "ls", "-Z", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux label hosts", func() { session := podmanTest.Podman([]string{"run", fedoraMinimal, "ls", "-Z", "/etc/hosts"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux label hostname", func() { session := podmanTest.Podman([]string{"run", fedoraMinimal, "ls", "-Z", "/etc/hostname"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux label /run/secrets", func() { session := podmanTest.Podman([]string{"run", fedoraMinimal, "ls", "-dZ", "/run/secrets"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux --privileged label resolv.conf", func() { session := podmanTest.Podman([]string{"run", "--privileged", fedoraMinimal, "ls", "-Z", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux --privileged label hosts", func() { session := podmanTest.Podman([]string{"run", "--privileged", fedoraMinimal, "ls", "-Z", "/etc/hosts"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux --privileged label hostname", func() { session := podmanTest.Podman([]string{"run", "--privileged", fedoraMinimal, "ls", "-Z", "/etc/hostname"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman test selinux --privileged label /run/secrets", func() { session := podmanTest.Podman([]string{"run", "--privileged", fedoraMinimal, "ls", "-dZ", "/run/secrets"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_file_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_file_t")) }) It("podman run selinux file type setup test", func() { session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "label=type:spc_t", "--security-opt", "label=filetype:container_var_lib_t", fedoraMinimal, "ls", "-Z", "/dev"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("container_var_lib_t") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("container_var_lib_t")) session = podmanTest.Podman([]string{"run", "-it", "--security-opt", "label=type:spc_t", "--security-opt", "label=filetype:foobar", fedoraMinimal, "ls", "-Z", "/dev"}) session.WaitWithDefaultTimeout() @@ -179,10 +165,8 @@ var _ = Describe("Podman run", func() { session := podmanTest.Podman([]string{"run", "-it", "--privileged", "--security-opt", "label=type:spc_t", "--security-opt", "label=level:s0:c1,c2", ALPINE, "cat", "/proc/self/attr/current"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("spc_t") - Expect(match).To(BeTrue()) - match2, _ := session.GrepString("s0:c1,c2") - Expect(match2).To(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring("spc_t")) + Expect(session.OutputToString()).To(ContainSubstring("s0:c1,c2")) }) It("podman pod container share SELinux labels", func() { @@ -349,7 +333,6 @@ var _ = Describe("Podman run", func() { session := podmanTest.Podman([]string{"run", "-v", "testvol:/test1/test:Z", fedoraMinimal, "ls", "-alZ", "/test1"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString(":s0:") - Expect(match).Should(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring(":s0:")) }) }) -- cgit v1.2.3-54-g00ecf