Skip to content

Commit

Permalink
Convert strings.Contains() to Expect(ContainSubstring)
Browse files Browse the repository at this point in the history
...done manually, not via sed, because some of the inner
expressions include nested commas.

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Nov 30, 2021
1 parent 1278796 commit f7cbb1d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions test/e2e/pod_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var _ = Describe("Podman pod create", func() {
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/hosts"})
podResolvConf.WaitWithDefaultTimeout()
Expect(podResolvConf).Should(Exit(0))
Expect(strings.Contains(podResolvConf.OutputToString(), "12.34.56.78 test.example.com")).To(BeTrue())
Expect(podResolvConf.OutputToString()).To(ContainSubstring("12.34.56.78 test.example.com"))
})

It("podman create pod with --add-host and no infra should fail", func() {
Expand All @@ -193,7 +193,7 @@ var _ = Describe("Podman pod create", func() {
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"})
podResolvConf.WaitWithDefaultTimeout()
Expect(podResolvConf).Should(Exit(0))
Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("nameserver %s", server))).To(BeTrue())
Expect(podResolvConf.OutputToString()).To(ContainSubstring("nameserver %s", server))
})

It("podman create pod with DNS server set and no infra should fail", func() {
Expand All @@ -214,7 +214,7 @@ var _ = Describe("Podman pod create", func() {
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"})
podResolvConf.WaitWithDefaultTimeout()
Expect(podResolvConf).Should(Exit(0))
Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("options %s", option))).To(BeTrue())
Expect(podResolvConf.OutputToString()).To(ContainSubstring(fmt.Sprintf("options %s", option)))
})

It("podman create pod with DNS option set and no infra should fail", func() {
Expand All @@ -235,7 +235,7 @@ var _ = Describe("Podman pod create", func() {
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"})
podResolvConf.WaitWithDefaultTimeout()
Expect(podResolvConf).Should(Exit(0))
Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("search %s", search))).To(BeTrue())
Expect(podResolvConf.OutputToString()).To(ContainSubstring(fmt.Sprintf("search %s", search)))
})

It("podman create pod with DNS search domain set and no infra should fail", func() {
Expand All @@ -259,7 +259,7 @@ var _ = Describe("Podman pod create", func() {
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "ip", "addr"})
podResolvConf.WaitWithDefaultTimeout()
Expect(podResolvConf).Should(Exit(0))
Expect(strings.Contains(podResolvConf.OutputToString(), ip)).To(BeTrue())
Expect(podResolvConf.OutputToString()).To(ContainSubstring(ip))
}
})

Expand Down Expand Up @@ -302,7 +302,7 @@ var _ = Describe("Podman pod create", func() {
podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "ip", "addr"})
podResolvConf.WaitWithDefaultTimeout()
Expect(podResolvConf).Should(Exit(0))
Expect(strings.Contains(podResolvConf.OutputToString(), mac)).To(BeTrue())
Expect(podResolvConf.OutputToString()).To(ContainSubstring(mac))
}
})

Expand Down Expand Up @@ -474,7 +474,7 @@ entrypoint ["/fromimage"]
status1 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName})
status1.WaitWithDefaultTimeout()
Expect(status1).Should(Exit(0))
Expect(strings.Contains(status1.OutputToString(), "Created")).To(BeTrue())
Expect(status1.OutputToString()).To(ContainSubstring("Created"))

ctr1 := podmanTest.Podman([]string{"run", "--pod", podName, "-d", ALPINE, "top"})
ctr1.WaitWithDefaultTimeout()
Expand All @@ -483,7 +483,7 @@ entrypoint ["/fromimage"]
status2 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName})
status2.WaitWithDefaultTimeout()
Expect(status2).Should(Exit(0))
Expect(strings.Contains(status2.OutputToString(), "Running")).To(BeTrue())
Expect(status2.OutputToString()).To(ContainSubstring("Running"))

ctr2 := podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
ctr2.WaitWithDefaultTimeout()
Expand All @@ -492,7 +492,7 @@ entrypoint ["/fromimage"]
status3 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName})
status3.WaitWithDefaultTimeout()
Expect(status3).Should(Exit(0))
Expect(strings.Contains(status3.OutputToString(), "Degraded")).To(BeTrue())
Expect(status3.OutputToString()).To(ContainSubstring("Degraded"))
})

It("podman create with unsupported network options", func() {
Expand Down Expand Up @@ -725,7 +725,7 @@ ENTRYPOINT ["sleep","99999"]
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
l := session.OutputToString()
Expect(strings.Contains(l, "1024")).To(BeTrue())
Expect(l).To(ContainSubstring("1024"))
m[l] = l
}
// check for no duplicates
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/run_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,23 +758,23 @@ EXPOSE 2004-2005/tcp`, ALPINE)
run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"})
run.WaitWithDefaultTimeout()
Expect(run).Should(Exit(0))
Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue())
Expect(run.OutputToString()).To(ContainSubstring(hostname))
})

It("podman run with --net=none sets hostname", func() {
hostname := "testctr"
run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "hostname"})
run.WaitWithDefaultTimeout()
Expect(run).Should(Exit(0))
Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue())
Expect(run.OutputToString()).To(ContainSubstring(hostname))
})

It("podman run with --net=none adds hostname to /etc/hosts", func() {
hostname := "testctr"
run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "cat", "/etc/hosts"})
run.WaitWithDefaultTimeout()
Expect(run).Should(Exit(0))
Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue())
Expect(run.OutputToString()).To(ContainSubstring(hostname))
})

It("podman run with pod does not add extra 127 entry to /etc/hosts", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ USER mail`, BB)
session := podmanTest.Podman([]string{"run", "-t", "-i", "--group-add", groupName, "--privileged", fedoraMinimal, "groups"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(strings.Contains(session.OutputToString(), groupName)).To(BeTrue())
Expect(session.OutputToString()).To(ContainSubstring(groupName))
})

It("podman run --tz", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run_userns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var _ = Describe("Podman UserNS support", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
l := session.OutputToString()
Expect(strings.Contains(l, "1024")).To(BeTrue())
Expect(l).To(ContainSubstring("1024"))
m[l] = l
}
// check for no duplicates
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ var _ = Describe("Podman run with volumes", func() {
os.Stderr.Sync()
mountOut1 := strings.Join(strings.Fields(string(mountCmd1.Out.Contents())), " ")
fmt.Printf("Output: %s", mountOut1)
Expect(strings.Contains(mountOut1, volName)).To(BeFalse())
Expect(mountOut1).To(Not(ContainSubstring(volName)))

ctrName := "testctr"
podmanSession := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, "-v", fmt.Sprintf("%s:/testvol", volName), ALPINE, "top"})
Expand All @@ -303,7 +303,7 @@ var _ = Describe("Podman run with volumes", func() {
os.Stderr.Sync()
mountOut2 := strings.Join(strings.Fields(string(mountCmd2.Out.Contents())), " ")
fmt.Printf("Output: %s", mountOut2)
Expect(strings.Contains(mountOut2, volName)).To(BeTrue())
Expect(mountOut2).To(ContainSubstring(volName))

// Stop the container to unmount
podmanStopSession := podmanTest.Podman([]string{"stop", "--time", "0", ctrName})
Expand All @@ -324,7 +324,7 @@ var _ = Describe("Podman run with volumes", func() {
os.Stderr.Sync()
mountOut3 := strings.Join(strings.Fields(string(mountCmd3.Out.Contents())), " ")
fmt.Printf("Output: %s", mountOut3)
Expect(strings.Contains(mountOut3, volName)).To(BeFalse())
Expect(mountOut3).To(Not(ContainSubstring(volName)))
})

It("podman named volume copyup", func() {
Expand Down Expand Up @@ -516,7 +516,7 @@ RUN sh -c "cd /etc/apk && ln -s ../../testfile"`, ALPINE)
Expect(runLs).Should(Exit(0))
outputArr := runLs.OutputToStringArray()
Expect(len(outputArr)).To(Equal(1))
Expect(strings.Contains(outputArr[0], fileName)).To(BeTrue())
Expect(outputArr[0]).To(ContainSubstring(fileName))
})

It("Podman mount over image volume with trailing /", func() {
Expand Down Expand Up @@ -752,7 +752,7 @@ USER testuser`, fedoraMinimal)
test1 := podmanTest.Podman([]string{"run", "-v", "testvol1:/test", imgName, "bash", "-c", "ls -al /test | grep -v root | grep -v total"})
test1.WaitWithDefaultTimeout()
Expect(test1).Should(Exit(0))
Expect(strings.Contains(test1.OutputToString(), testString)).To(BeTrue())
Expect(test1.OutputToString()).To(ContainSubstring(testString))

volName := "testvol2"
vol := podmanTest.Podman([]string{"volume", "create", volName})
Expand All @@ -762,7 +762,7 @@ USER testuser`, fedoraMinimal)
test2 := podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:/test", volName), imgName, "bash", "-c", "ls -al /test | grep -v root | grep -v total"})
test2.WaitWithDefaultTimeout()
Expect(test2).Should(Exit(0))
Expect(strings.Contains(test2.OutputToString(), testString)).To(BeTrue())
Expect(test2.OutputToString()).To(ContainSubstring(testString))

})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ WantedBy=default.target
systemctl := podmanTest.Podman([]string{"exec", "-t", "-i", ctrName, "systemctl", "status", "--no-pager"})
systemctl.WaitWithDefaultTimeout()
Expect(systemctl).Should(Exit(0))
Expect(strings.Contains(systemctl.OutputToString(), "State:")).To(BeTrue())
Expect(systemctl.OutputToString()).To(ContainSubstring("State:"))

result := podmanTest.Podman([]string{"inspect", ctrName})
result.WaitWithDefaultTimeout()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/volume_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ var _ = Describe("Podman volume inspect", func() {
inspect := podmanTest.Podman([]string{"volume", "inspect", volName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(strings.Contains(inspect.OutputToString(), "tmpfs")).To(BeTrue())
Expect(inspect.OutputToString()).To(ContainSubstring("tmpfs"))
})
})

0 comments on commit f7cbb1d

Please sign in to comment.