Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e tests: use HaveKey() and HaveLen() when possible #12482

Merged
merged 7 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var _ = Describe("Podman build", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
// Check for two layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2))
Expect(strings.Fields(session.OutputToString())).To(HaveLen(2))

session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-b", "--squash", "-t", "test-squash-b:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expand All @@ -149,7 +149,7 @@ var _ = Describe("Podman build", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
// Check for three layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(3))
Expect(strings.Fields(session.OutputToString())).To(HaveLen(3))

session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-c", "--squash", "-t", "test-squash-c:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expand All @@ -159,7 +159,7 @@ var _ = Describe("Podman build", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
// Check for two layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2))
Expect(strings.Fields(session.OutputToString())).To(HaveLen(2))

session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-c", "--squash-all", "-t", "test-squash-d:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expand All @@ -169,7 +169,7 @@ var _ = Describe("Podman build", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
// Check for one layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(1))
Expect(strings.Fields(session.OutputToString())).To(HaveLen(1))

session = podmanTest.Podman([]string{"rm", "-a"})
session.WaitWithDefaultTimeout()
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(result.OutputToString()).To(ContainSubstring("C /etc"))
Expect(result.OutputToString()).To(ContainSubstring("A /test.output"))
Expect(result.OutputToString()).To(ContainSubstring("D /etc/motd"))
Expect(len(result.OutputToStringArray())).To(Equal(3))
Expect(result.OutputToStringArray()).To(HaveLen(3))

// Checkpoint the container
result = podmanTest.Podman([]string{"container", "checkpoint", cid, "-e", fileName})
Expand Down Expand Up @@ -599,7 +599,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(result.OutputToString()).To(ContainSubstring("C /etc"))
Expect(result.OutputToString()).To(ContainSubstring("A /test.output"))
Expect(result.OutputToString()).To(ContainSubstring("D /etc/motd"))
Expect(len(result.OutputToStringArray())).To(Equal(3))
Expect(result.OutputToStringArray()).To(HaveLen(3))

// Remove exported checkpoint
os.Remove(fileName)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ var _ = Describe("Podman checkpoint", func() {
err := json.Unmarshal([]byte(result.OutputToString()), cS)
Expect(err).ShouldNot(HaveOccurred())

Expect(len(cS.ContainerStatistics)).To(Equal(2))
Expect(cS.ContainerStatistics).To(HaveLen(2))
Expect(cS.PodmanDuration).To(BeNumerically(">", cS.ContainerStatistics[0].RuntimeDuration))
Expect(cS.PodmanDuration).To(BeNumerically(">", cS.ContainerStatistics[1].RuntimeDuration))
Expect(cS.ContainerStatistics[0].RuntimeDuration).To(
Expand Down Expand Up @@ -1322,7 +1322,7 @@ var _ = Describe("Podman checkpoint", func() {
err = json.Unmarshal([]byte(result.OutputToString()), rS)
Expect(err).ShouldNot(HaveOccurred())

Expect(len(cS.ContainerStatistics)).To(Equal(2))
Expect(cS.ContainerStatistics).To(HaveLen(2))
Expect(cS.PodmanDuration).To(BeNumerically(">", cS.ContainerStatistics[0].RuntimeDuration))
Expect(cS.PodmanDuration).To(BeNumerically(">", cS.ContainerStatistics[1].RuntimeDuration))
Expect(cS.ContainerStatistics[0].RuntimeDuration).To(
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ var _ = Describe("Podman commit", func() {
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
check.WaitWithDefaultTimeout()
data := check.InspectImageJSON()
Expect(len(data)).To(Equal(1))
Expect(len(data[0].Config.Entrypoint)).To(Equal(2))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Entrypoint).To(HaveLen(2))
Expect(data[0].Config.Entrypoint[0]).To(Equal("foo"))
Expect(data[0].Config.Entrypoint[1]).To(Equal("bar=baz"))
})
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/container_create_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ func checkDataVolumeContainer(pTest *PodmanTestIntegration, image, cont, dest, d
Expect(create).Should(Exit(0))

inspect := pTest.InspectContainer(cont)
Expect(len(inspect)).To(Equal(1))
Expect(len(inspect[0].Mounts)).To(Equal(1))
Expect(inspect).To(HaveLen(1))
Expect(inspect[0].Mounts).To(HaveLen(1))
Expect(inspect[0].Mounts[0].Destination).To(Equal(dest))

mntName, mntSource := inspect[0].Mounts[0].Name, inspect[0].Mounts[0].Source

volList := pTest.Podman([]string{"volume", "list", "--quiet"})
volList.WaitWithDefaultTimeout()
Expect(volList).Should(Exit(0))
Expect(len(volList.OutputToStringArray())).To(Equal(1))
Expect(volList.OutputToStringArray()).To(HaveLen(1))
Expect(volList.OutputToStringArray()[0]).To(Equal(mntName))

// Check the mount source directory
files, err := ioutil.ReadDir(mntSource)
Expect(err).To(BeNil())

if data == "" {
Expect(len(files)).To(Equal(0))
Expect(files).To(BeEmpty())
} else {
Expect(len(files)).To(Equal(1))
Expect(files).To(HaveLen(1))
Expect(files[0].Name()).To(Equal(data))
}
}
Expand Down
36 changes: 18 additions & 18 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ var _ = Describe("Podman create", func() {
Expect(create).Should(Exit(0))

ctrJSON := podmanTest.InspectContainer(name)
Expect(len(ctrJSON)).To(Equal(1))
Expect(len(ctrJSON[0].Config.Cmd)).To(Equal(1))
Expect(ctrJSON).To(HaveLen(1))
Expect(ctrJSON[0].Config.Cmd).To(HaveLen(1))
Expect(ctrJSON[0].Config.Cmd[0]).To(Equal("redis-server"))
Expect(ctrJSON[0].Config.Entrypoint).To(Equal("docker-entrypoint.sh"))
})
Expand Down Expand Up @@ -382,8 +382,8 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", ctrName})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1), "len(InspectContainerToJSON)")
Expect(len(data[0].Config.Labels)).To(Equal(2))
Expect(data).To(HaveLen(1), "len(InspectContainerToJSON)")
Expect(data[0].Config.Labels).To(HaveLen(2))
Expect(data[0].Config.Labels).To(HaveKey("TESTKEY1"))
Expect(data[0].Config.Labels).To(HaveKey("TESTKEY2"))
})
Expand All @@ -398,8 +398,8 @@ 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[0].Config.Labels)).To(Equal(2))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Labels).To(HaveLen(2))
Expect(data[0].Config.Labels).To(HaveKeyWithValue("TESTKEY1", "value1"))
Expect(data[0].Config.Labels).To(HaveKeyWithValue("TESTKEY2", "bar"))
})
Expand All @@ -413,7 +413,7 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", ctrName})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.RestartPolicy.Name).To(Equal("on-failure"))
Expect(data[0].HostConfig.RestartPolicy.MaximumRetryCount).To(Equal(uint(5)))
})
Expand All @@ -434,7 +434,7 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", ctrName})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.RestartPolicy.Name).To(Equal(unlessStopped))
})

Expand All @@ -448,7 +448,7 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", ctrName})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.MemorySwap).To(Equal(int64(2 * numMem)))
})

Expand All @@ -463,7 +463,7 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", ctrName})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.NanoCpus).To(Equal(int64(nanoCPUs)))
})

Expand Down Expand Up @@ -491,7 +491,7 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", ctrName})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.StopSignal).To(Equal(uint(15)))
})

Expand All @@ -509,15 +509,15 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", "zone"})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Timezone).To(Equal("Pacific/Honolulu"))

session = podmanTest.Podman([]string{"create", "--tz", "local", "--name", "lcl", ALPINE, "date"})
session.WaitWithDefaultTimeout()
inspect = podmanTest.Podman([]string{"inspect", "lcl"})
inspect.WaitWithDefaultTimeout()
data = inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Timezone).To(Equal("local"))
})

Expand All @@ -531,31 +531,31 @@ var _ = Describe("Podman create", func() {
inspect := podmanTest.Podman([]string{"inspect", "default"})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0022"))

session = podmanTest.Podman([]string{"create", "--umask", "0002", "--name", "umask", ALPINE})
session.WaitWithDefaultTimeout()
inspect = podmanTest.Podman([]string{"inspect", "umask"})
inspect.WaitWithDefaultTimeout()
data = inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0002"))

session = podmanTest.Podman([]string{"create", "--umask", "0077", "--name", "fedora", fedoraMinimal})
session.WaitWithDefaultTimeout()
inspect = podmanTest.Podman([]string{"inspect", "fedora"})
inspect.WaitWithDefaultTimeout()
data = inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0077"))

session = podmanTest.Podman([]string{"create", "--umask", "22", "--name", "umask-short", ALPINE})
session.WaitWithDefaultTimeout()
inspect = podmanTest.Podman([]string{"inspect", "umask-short"})
inspect.WaitWithDefaultTimeout()
data = inspect.InspectContainerToJSON()
Expect(len(data)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0022"))

session = podmanTest.Podman([]string{"create", "--umask", "9999", "--name", "bad", ALPINE})
Expand Down Expand Up @@ -689,7 +689,7 @@ var _ = Describe("Podman create", func() {
Expect(setup).Should(Exit(0))

idata := setup.InspectImageJSON() // returns []inspect.ImageData
Expect(len(idata)).To(Equal(1))
Expect(idata).To(HaveLen(1))
Expect(idata[0].Os).To(Equal(runtime.GOOS))
Expect(idata[0].Architecture).To(Equal("arm64"))
})
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ RUN echo test
session := podmanTest.Podman([]string{"image", "diff", image})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 1))
Expect(session.OutputToStringArray()).To(HaveLen(1))
Expect(session.OutputToString()).To(Equal("A " + file3))

session = podmanTest.Podman([]string{"image", "diff", image, baseImage})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 4))
Expect(session.OutputToStringArray()).To(HaveLen(4))
Expect(session.OutputToString()).To(ContainSubstring("A " + file1))
Expect(session.OutputToString()).To(ContainSubstring("A " + file2))
Expect(session.OutputToString()).To(ContainSubstring("A " + file3))
Expand All @@ -149,7 +149,7 @@ RUN echo test
session := podmanTest.Podman([]string{"image", "diff", ALPINE, ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 0))
Expect(session.OutputToStringArray()).To(BeEmpty())
})

It("podman diff container and image with same name", func() {
Expand All @@ -172,20 +172,20 @@ RUN touch %s`, ALPINE, imagefile)
session = podmanTest.Podman([]string{"diff", name})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 2))
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring(imagefile))

session = podmanTest.Podman([]string{"image", "diff", name})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 2))
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring(imagefile))

// container diff has to show the container
session = podmanTest.Podman([]string{"container", "diff", name})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 2))
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring(confile))
})

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var _ = Describe("Podman events", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
events := result.OutputToStringArray()
Expect(len(events)).To(Equal(1), "number of events")
Expect(events).To(HaveLen(1), "number of events")
Expect(events[0]).To(ContainSubstring(cid), "event log includes CID")
Expect(events[0]).To(Not(ContainSubstring(cid2)), "event log does not include second CID")
})
Expand All @@ -86,7 +86,7 @@ var _ = Describe("Podman events", func() {
result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", fmt.Sprintf("container=%s", cid)})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(len(result.OutputToStringArray())).To(Equal(0))
Expect(result.OutputToStringArray()).To(BeEmpty())
})

It("podman events with a type", func() {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ RUN useradd -u 1000 auser`, fedoraMinimal)
Expect(ctr).Should(Exit(0))

data := podmanTest.InspectContainer(ctrName)
Expect(len(data)).To(Equal(1))
Expect(len(data[0].ExecIDs)).To(Equal(1))
Expect(data).To(HaveLen(1))
Expect(data[0].ExecIDs).To(HaveLen(1))
Expect(exec1.OutputToString()).To(ContainSubstring(data[0].ExecIDs[0]))

exec2 := podmanTest.Podman([]string{"exec", "-t", "-i", ctrName, "ps", "-a"})
Expand Down
Loading