diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/e2e/build_test.go | 11 | ||||
-rw-r--r-- | test/e2e/checkpoint_test.go | 2 | ||||
-rw-r--r-- | test/e2e/commit_test.go | 4 | ||||
-rw-r--r-- | test/e2e/create_test.go | 22 | ||||
-rw-r--r-- | test/e2e/diff_test.go | 2 | ||||
-rw-r--r-- | test/e2e/generate_kube_test.go | 2 | ||||
-rw-r--r-- | test/e2e/generate_systemd_test.go | 2 | ||||
-rw-r--r-- | test/e2e/history_test.go | 2 | ||||
-rw-r--r-- | test/e2e/image_sign_test.go | 2 | ||||
-rw-r--r-- | test/e2e/images_test.go | 8 | ||||
-rw-r--r-- | test/e2e/inspect_test.go | 14 | ||||
-rw-r--r-- | test/e2e/mount_test.go | 4 | ||||
-rw-r--r-- | test/e2e/network_test.go | 2 | ||||
-rw-r--r-- | test/e2e/pod_inspect_test.go | 4 | ||||
-rw-r--r-- | test/e2e/pod_stats_test.go | 4 | ||||
-rw-r--r-- | test/e2e/ps_test.go | 6 | ||||
-rw-r--r-- | test/e2e/search_test.go | 4 | ||||
-rw-r--r-- | test/e2e/secret_test.go | 4 | ||||
-rw-r--r-- | test/e2e/stats_test.go | 2 | ||||
-rw-r--r-- | test/e2e/trust_test.go | 4 | ||||
-rw-r--r-- | test/e2e/volume_inspect_test.go | 2 | ||||
-rw-r--r-- | test/e2e/volume_ls_test.go | 2 | ||||
-rw-r--r-- | test/utils/matchers.go | 30 |
23 files changed, 82 insertions, 57 deletions
diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 420ed929f..1be5753f5 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -388,13 +388,10 @@ subdir**` session := podmanTest.Podman([]string{"build", "-t", "test", "."}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - ok, _ := session.GrepString("/testfilter/dummy1") - Expect(ok).NotTo(BeTrue()) - Expect(session.OutputToString()).To(ContainSubstring("/testfilter/dummy2")) - ok, _ = session.GrepString("/testfilter/subdir") - Expect(ok).NotTo(BeTrue()) //.dockerignore filters both subdir and inside subdir - ok, _ = session.GrepString("/testfilter/subdir/dummy3") - Expect(ok).NotTo(BeTrue()) + output := session.OutputToString() + Expect(output).To(ContainSubstring("/testfilter/dummy2")) + Expect(output).NotTo(ContainSubstring("/testfilter/dummy1")) + Expect(output).NotTo(ContainSubstring("/testfilter/subdir")) }) It("podman remote test context dir contains empty dirs and symlinks", func() { diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go index 318e3617e..e068a6582 100644 --- a/test/e2e/checkpoint_test.go +++ b/test/e2e/checkpoint_test.go @@ -102,7 +102,7 @@ var _ = Describe("Podman checkpoint", func() { inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) inspectOut := inspect.InspectContainerToJSON() - Expect(inspectOut[0].State.Checkpointed).To(BeTrue()) + Expect(inspectOut[0].State.Checkpointed).To(BeTrue(), ".State.Checkpointed") result = podmanTest.Podman([]string{"container", "restore", cid}) result.WaitWithDefaultTimeout() diff --git a/test/e2e/commit_test.go b/test/e2e/commit_test.go index 20e1360de..b751c338f 100644 --- a/test/e2e/commit_test.go +++ b/test/e2e/commit_test.go @@ -225,7 +225,7 @@ var _ = Describe("Podman commit", func() { Expect(inspect).Should(Exit(0)) image := inspect.InspectImageJSON() _, ok := image[0].Config.Volumes["/foo"] - Expect(ok).To(BeTrue()) + Expect(ok).To(BeTrue(), ".Config.Volumes[/foo]") r := podmanTest.Podman([]string{"run", "newimage"}) r.WaitWithDefaultTimeout() @@ -250,7 +250,7 @@ var _ = Describe("Podman commit", func() { for _, v := range image[0].Config.Env { envMap[v] = true } - Expect(envMap["TEST=1=1-01=9.01"]).To(BeTrue()) + Expect(envMap["TEST=1=1-01=9.01"]).To(BeTrue(), "envMap[TEST=1=1-01=9.01]") }) It("podman commit container and print id to external file", func() { diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index 216432216..52d439f4a 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -108,7 +108,7 @@ var _ = Describe("Podman create", func() { check.WaitWithDefaultTimeout() data := check.InspectContainerToJSON() value, ok := data[0].Config.Annotations["HELLO"] - Expect(ok).To(BeTrue()) + Expect(ok).To(BeTrue(), ".Config.Annotations[HELLO]") Expect(value).To(Equal("WORLD")) }) @@ -202,7 +202,7 @@ var _ = Describe("Podman create", func() { Expect(session).Should(Exit(0)) Expect(session.OutputToString()).To(ContainSubstring("/create/test ro")) - session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_shared", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test,shared", mountPath), ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) + session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_shared", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test,shared", mountPath), ALPINE, "awk", `$5 == "/create/test" { print $6 " " $7}`, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"start", "test_shared"}) @@ -211,10 +211,8 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"logs", "test_shared"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - found, matches := session.GrepString("/create/test") - Expect(found).Should(BeTrue()) - Expect(matches[0]).To(ContainSubstring("rw")) - Expect(matches[0]).To(ContainSubstring("shared")) + Expect(session.OutputToString()).To(ContainSubstring("rw")) + Expect(session.OutputToString()).To(ContainSubstring("shared")) mountPath = filepath.Join(podmanTest.TempDir, "scratchpad") os.Mkdir(mountPath, 0755) @@ -263,7 +261,7 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"pod", "inspect", podName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) podData := session.InspectPodToJSON() // Finally we can create a container with --pod-id-file and do @@ -386,12 +384,12 @@ var _ = Describe("Podman create", func() { inspect := podmanTest.Podman([]string{"inspect", ctrName}) inspect.WaitWithDefaultTimeout() data := inspect.InspectContainerToJSON() - Expect(len(data)).To(Equal(1)) + Expect(len(data)).To(Equal(1), "len(InspectContainerToJSON)") Expect(len(data[0].Config.Labels)).To(Equal(2)) _, ok1 := data[0].Config.Labels["TESTKEY1"] - Expect(ok1).To(BeTrue()) + Expect(ok1).To(BeTrue(), ".Config.Labels[TESTKEY1]") _, ok2 := data[0].Config.Labels["TESTKEY2"] - Expect(ok2).To(BeTrue()) + Expect(ok2).To(BeTrue(), ".Config.Labels[TESTKEY2]") }) It("podman create with set label", func() { @@ -407,10 +405,10 @@ var _ = Describe("Podman create", func() { Expect(len(data)).To(Equal(1)) Expect(len(data[0].Config.Labels)).To(Equal(2)) val1, ok1 := data[0].Config.Labels["TESTKEY1"] - Expect(ok1).To(BeTrue()) + Expect(ok1).To(BeTrue(), ".Config.Labels[TESTKEY1]") Expect(val1).To(Equal("value1")) val2, ok2 := data[0].Config.Labels["TESTKEY2"] - Expect(ok2).To(BeTrue()) + Expect(ok2).To(BeTrue(), ".Config.Labels[TESTKEY2]") Expect(val2).To(Equal("bar")) }) diff --git a/test/e2e/diff_test.go b/test/e2e/diff_test.go index 71696f5b6..80647c6f5 100644 --- a/test/e2e/diff_test.go +++ b/test/e2e/diff_test.go @@ -53,7 +53,7 @@ var _ = Describe("Podman diff", func() { session := podmanTest.Podman([]string{"diff", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman diff container and committed image", func() { diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index a148025e5..62482598a 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -607,7 +607,7 @@ var _ = Describe("Podman generate kube", func() { err = yaml.Unmarshal(b, pod) Expect(err).To(BeNil()) val, found := pod.Annotations[define.BindMountPrefix+vol1] - Expect(found).To(BeTrue()) + Expect(found).To(BeTrue(), "pod.Annotations["+vol1+"]") Expect(val).To(HaveSuffix("z")) rm := podmanTest.Podman([]string{"pod", "rm", "-t", "0", "-f", "test1"}) diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go index e93482535..1cffdc62e 100644 --- a/test/e2e/generate_systemd_test.go +++ b/test/e2e/generate_systemd_test.go @@ -420,7 +420,7 @@ var _ = Describe("Podman generate systemd", func() { session := podmanTest.Podman([]string{"generate", "systemd", "--format", "json", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman generate systemd --new create command with double curly braces", func() { diff --git a/test/e2e/history_test.go b/test/e2e/history_test.go index 0f0f6d38a..1f8faa6c2 100644 --- a/test/e2e/history_test.go +++ b/test/e2e/history_test.go @@ -89,6 +89,6 @@ var _ = Describe("Podman history", func() { session := podmanTest.Podman([]string{"history", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) }) diff --git a/test/e2e/image_sign_test.go b/test/e2e/image_sign_test.go index 6b87c9edd..09e156e02 100644 --- a/test/e2e/image_sign_test.go +++ b/test/e2e/image_sign_test.go @@ -73,6 +73,6 @@ var _ = Describe("Podman image sign", func() { Expect(session).Should(Exit(0)) fInfos, err := ioutil.ReadDir(filepath.Join(sigDir, "library")) Expect(err).To(BeNil()) - Expect(len(fInfos) > 1).To(BeTrue()) + Expect(len(fInfos)).To(BeNumerically(">", 1), "len(fInfos)") }) }) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index 3ed8ef462..8e21ca606 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -94,14 +94,14 @@ var _ = Describe("Podman images", func() { session := podmanTest.Podman([]string{"images", "--format=json", "not-existing-image"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman images in JSON format", func() { session := podmanTest.Podman([]string{"images", "--format=json"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman images in GO template format", func() { @@ -254,7 +254,7 @@ WORKDIR /test session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) imageData := session.InspectImageJSON() result := podmanTest.Podman([]string{"images", "sha256:" + imageData[0].ID}) @@ -266,7 +266,7 @@ WORKDIR /test session := podmanTest.Podman([]string{"image", "inspect", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) imageData := session.InspectImageJSON() result := podmanTest.Podman([]string{"image", "ls", fmt.Sprintf("sha256:%s", imageData[0].ID)}) diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 52726015c..0f0237adc 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -38,7 +38,7 @@ var _ = Describe("Podman inspect", func() { session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) imageData := session.InspectImageJSON() Expect(imageData[0].RepoTags[0]).To(Equal("quay.io/libpod/alpine:latest")) }) @@ -314,7 +314,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", podName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodArrToJSON() Expect(podData[0].Name).To(Equal(podName)) }) @@ -328,7 +328,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "pod", podName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodArrToJSON() Expect(podData[0].Name).To(Equal(podName)) }) @@ -343,7 +343,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "pod", "--latest"}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodArrToJSON() Expect(podData[0].Name).To(Equal(podName)) }) @@ -357,14 +357,14 @@ var _ = Describe("Podman inspect", func() { inspect1 := podmanTest.Podman([]string{"inspect", "--type", "pod", podName}) inspect1.WaitWithDefaultTimeout() Expect(inspect1).Should(Exit(0)) - Expect(inspect1.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect1.OutputToString()).To(BeValidJSON()) podData := inspect1.InspectPodArrToJSON() infra := podData[0].Containers[0].Name inspect := podmanTest.Podman([]string{"inspect", "--latest"}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) containerData := inspect.InspectContainerToJSON() Expect(containerData[0].Name).To(Equal(infra)) }) @@ -388,7 +388,7 @@ var _ = Describe("Podman inspect", func() { session = podmanTest.Podman([]string{"inspect", volName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman inspect a volume with --format", func() { diff --git a/test/e2e/mount_test.go b/test/e2e/mount_test.go index 5ecd61097..0555a0749 100644 --- a/test/e2e/mount_test.go +++ b/test/e2e/mount_test.go @@ -78,7 +78,7 @@ var _ = Describe("Podman mount", func() { j := podmanTest.Podman([]string{"mount", "--format=json"}) j.WaitWithDefaultTimeout() Expect(j).Should(Exit(0)) - Expect(j.IsJSONOutputValid()).To(BeTrue()) + Expect(j.OutputToString()).To(BeValidJSON()) j = podmanTest.Podman([]string{"mount", "--format='{{.foobar}}'"}) j.WaitWithDefaultTimeout() @@ -332,7 +332,7 @@ var _ = Describe("Podman mount", func() { j := podmanTest.Podman([]string{"image", "mount", "--format=json"}) j.WaitWithDefaultTimeout() Expect(j).Should(Exit(0)) - Expect(j.IsJSONOutputValid()).To(BeTrue()) + Expect(j.OutputToString()).To(BeValidJSON()) umount := podmanTest.Podman([]string{"image", "umount", fedoraMinimal}) umount.WaitWithDefaultTimeout() diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go index 734a45bca..aab996e02 100644 --- a/test/e2e/network_test.go +++ b/test/e2e/network_test.go @@ -234,7 +234,7 @@ var _ = Describe("Podman network", func() { session := podmanTest.Podman(append([]string{"network", "inspect"}, expectedNetworks...)) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman network inspect", func() { diff --git a/test/e2e/pod_inspect_test.go b/test/e2e/pod_inspect_test.go index 5728cf9b9..8a6f2a367 100644 --- a/test/e2e/pod_inspect_test.go +++ b/test/e2e/pod_inspect_test.go @@ -56,7 +56,7 @@ var _ = Describe("Podman pod inspect", func() { inspect := podmanTest.Podman([]string{"pod", "inspect", podid}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodToJSON() Expect(podData.ID).To(Equal(podid)) }) @@ -75,7 +75,7 @@ var _ = Describe("Podman pod inspect", func() { inspect := podmanTest.Podman([]string{"pod", "inspect", podName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodToJSON() // Let's get the last len(createCommand) items in the command. inspectCreateCommand := podData.CreateCommand diff --git a/test/e2e/pod_stats_test.go b/test/e2e/pod_stats_test.go index 5ec209034..bb145088e 100644 --- a/test/e2e/pod_stats_test.go +++ b/test/e2e/pod_stats_test.go @@ -149,7 +149,7 @@ var _ = Describe("Podman pod stats", func() { stats := podmanTest.Podman([]string{"pod", "stats", "--format", "json", "--no-stream", "-a"}) stats.WaitWithDefaultTimeout() Expect(stats).Should(Exit(0)) - Expect(stats.IsJSONOutputValid()).To(BeTrue()) + Expect(stats.OutputToString()).To(BeValidJSON()) }) It("podman pod stats with GO template", func() { _, ec, podid := podmanTest.CreatePod(nil) @@ -189,6 +189,6 @@ var _ = Describe("Podman pod stats", func() { stats := podmanTest.Podman([]string{"pod", "stats", "--format", "json", "--no-stream", podName}) stats.WaitWithDefaultTimeout() Expect(stats).Should(Exit(0)) - Expect(stats.IsJSONOutputValid()).To(BeTrue()) + Expect(stats.OutputToString()).To(BeValidJSON()) }) }) diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index c0b0e0aa6..3334250db 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -239,7 +239,7 @@ var _ = Describe("Podman ps", func() { result := podmanTest.Podman([]string{"ps", "--format", "json"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - Expect(result.IsJSONOutputValid()).To(BeTrue()) + Expect(result.OutputToString()).To(BeValidJSON()) }) It("podman ps namespace flag with json format", func() { @@ -249,7 +249,7 @@ var _ = Describe("Podman ps", func() { result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - Expect(result.IsJSONOutputValid()).To(BeTrue()) + Expect(result.OutputToString()).To(BeValidJSON()) }) It("podman ps json format Created field is int64", func() { @@ -275,7 +275,7 @@ var _ = Describe("Podman ps", func() { result := podmanTest.Podman([]string{"ps", "-a", "--format", "json"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - Expect(result.IsJSONOutputValid()).To(BeTrue()) + Expect(result.OutputToString()).To(BeValidJSON()) // must contain "Status" match, StatusLine := result.GrepString(`Status`) Expect(match).To(BeTrue()) diff --git a/test/e2e/search_test.go b/test/e2e/search_test.go index 2ea88eb5e..54bc5252e 100644 --- a/test/e2e/search_test.go +++ b/test/e2e/search_test.go @@ -134,7 +134,7 @@ registries = ['{{.Host}}:{{.Port}}']` search := podmanTest.Podman([]string{"search", "--format", "json", "alpine"}) search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) - Expect(search.IsJSONOutputValid()).To(BeTrue()) + Expect(search.OutputToString()).To(BeValidJSON()) Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine")) // Test for https://github.com/containers/podman/issues/11894 @@ -151,7 +151,7 @@ registries = ['{{.Host}}:{{.Port}}']` search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", "alpine"}) search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) - Expect(search.IsJSONOutputValid()).To(BeTrue()) + Expect(search.OutputToString()).To(BeValidJSON()) Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine")) Expect(search.OutputToString()).To(ContainSubstring("3.10")) Expect(search.OutputToString()).To(ContainSubstring("2.7")) diff --git a/test/e2e/secret_test.go b/test/e2e/secret_test.go index df0cd24d0..758ed7edc 100644 --- a/test/e2e/secret_test.go +++ b/test/e2e/secret_test.go @@ -78,7 +78,7 @@ var _ = Describe("Podman secret", func() { inspect := podmanTest.Podman([]string{"secret", "inspect", secrID}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) }) It("podman secret inspect with --format", func() { @@ -115,7 +115,7 @@ var _ = Describe("Podman secret", func() { inspect := podmanTest.Podman([]string{"secret", "inspect", secrID, secrID2}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) }) It("podman secret inspect bogus", func() { diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go index c0d56fdbc..a58e2485c 100644 --- a/test/e2e/stats_test.go +++ b/test/e2e/stats_test.go @@ -148,7 +148,7 @@ var _ = Describe("Podman stats", func() { stats := podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "json"}) stats.WaitWithDefaultTimeout() Expect(stats).Should(Exit(0)) - Expect(stats.IsJSONOutputValid()).To(BeTrue()) + Expect(stats.OutputToString()).To(BeValidJSON()) }) It("podman stats on a container with no net ns", func() { diff --git a/test/e2e/trust_test.go b/test/e2e/trust_test.go index b591e1c02..9a0d57d7a 100644 --- a/test/e2e/trust_test.go +++ b/test/e2e/trust_test.go @@ -76,7 +76,7 @@ var _ = Describe("Podman trust", func() { session := podmanTest.Podman([]string{"image", "trust", "show", "--registrypath", filepath.Join(INTEGRATION_ROOT, "test"), "--policypath", filepath.Join(INTEGRATION_ROOT, "test/policy.json"), "--json"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) var teststruct []map[string]string json.Unmarshal(session.Out.Contents(), &teststruct) Expect(len(teststruct)).To(Equal(3)) @@ -118,7 +118,7 @@ var _ = Describe("Podman trust", func() { Expect(session).Should(Exit(0)) contents, err := ioutil.ReadFile(filepath.Join(INTEGRATION_ROOT, "test/policy.json")) Expect(err).ShouldNot(HaveOccurred()) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) Expect(string(session.Out.Contents())).To(Equal(string(contents) + "\n")) }) }) diff --git a/test/e2e/volume_inspect_test.go b/test/e2e/volume_inspect_test.go index db95ba675..0389529f7 100644 --- a/test/e2e/volume_inspect_test.go +++ b/test/e2e/volume_inspect_test.go @@ -43,7 +43,7 @@ var _ = Describe("Podman volume inspect", func() { session = podmanTest.Podman([]string{"volume", "inspect", volName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman inspect volume with Go format", func() { diff --git a/test/e2e/volume_ls_test.go b/test/e2e/volume_ls_test.go index 6c4b22fa5..c1214366b 100644 --- a/test/e2e/volume_ls_test.go +++ b/test/e2e/volume_ls_test.go @@ -64,7 +64,7 @@ var _ = Describe("Podman volume ls", func() { session = podmanTest.Podman([]string{"volume", "ls", "--format", "json"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman ls volume with Go template", func() { diff --git a/test/utils/matchers.go b/test/utils/matchers.go index 69fb0cdfe..59436a3ab 100644 --- a/test/utils/matchers.go +++ b/test/utils/matchers.go @@ -1,6 +1,7 @@ package utils import ( + "encoding/json" "fmt" "net/url" @@ -166,3 +167,32 @@ func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { } return true } + +type validJSONMatcher struct { + types.GomegaMatcher +} + +func BeValidJSON() *validJSONMatcher { + return &validJSONMatcher{} +} + +func (matcher *validJSONMatcher) Match(actual interface{}) (success bool, err error) { + s, ok := actual.(string) + if !ok { + return false, fmt.Errorf("validJSONMatcher expects a string, not %q", actual) + } + + var i interface{} + if err := json.Unmarshal([]byte(s), &i); err != nil { + return false, nil + } + return true, nil +} + +func (matcher *validJSONMatcher) FailureMessage(actual interface{}) (message string) { + return format.Message(actual, "to be valid JSON") +} + +func (matcher *validJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) { + return format.Message(actual, "to _not_ be valid JSON") +} |