Skip to content

Commit

Permalink
Merge pull request containers#14040 from edsantiago/gomega_havefield
Browse files Browse the repository at this point in the history
e2e tests: use HaveField() for better error checking
  • Loading branch information
openshift-merge-robot authored Apr 28, 2022
2 parents d0b96a5 + a5aea8e commit 87454cf
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 197 deletions.
8 changes: 4 additions & 4 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ var _ = Describe("Podman build", func() {
inspect := podmanTest.Podman([]string{"inspect", iid})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectImageJSON()
Expect(data[0].Os).To(Equal(runtime.GOOS))
Expect(data[0].Architecture).To(Equal(runtime.GOARCH))
Expect(data[0]).To(HaveField("Os", runtime.GOOS))
Expect(data[0]).To(HaveField("Architecture", runtime.GOARCH))

session = podmanTest.Podman([]string{"rmi", ALPINE})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -110,8 +110,8 @@ var _ = Describe("Podman build", func() {
inspect := podmanTest.Podman([]string{"inspect", "test"})
inspect.WaitWithDefaultTimeout()
data := inspect.InspectImageJSON()
Expect(data[0].Os).To(Equal(runtime.GOOS))
Expect(data[0].Architecture).To(Equal(runtime.GOARCH))
Expect(data[0]).To(HaveField("Os", runtime.GOOS))
Expect(data[0]).To(HaveField("Architecture", runtime.GOARCH))

st, err := os.Stat(logfile)
Expect(err).To(BeNil())
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/checkpoint_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ var _ = Describe("Podman checkpoint", func() {
inspectOut := inspect.InspectContainerToJSON()
Expect(inspectOut[0].State.Checkpointed).To(BeFalse(), ".State.Checkpointed")
Expect(inspectOut[0].State.Restored).To(BeFalse(), ".State.Restored")
Expect(inspectOut[0].State.CheckpointPath).To(Equal(""))
Expect(inspectOut[0].State.CheckpointLog).To(Equal(""))
Expect(inspectOut[0].State.RestoreLog).To(Equal(""))
Expect(inspectOut[0].State).To(HaveField("CheckpointPath", ""))
Expect(inspectOut[0].State).To(HaveField("CheckpointLog", ""))
Expect(inspectOut[0].State).To(HaveField("RestoreLog", ""))

result := podmanTest.Podman([]string{"container", "checkpoint", "--create-image", checkpointImage, "--keep", containerID})
result.WaitWithDefaultTimeout()
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ var _ = Describe("Podman checkpoint", func() {
inspectOut := inspect.InspectContainerToJSON()
Expect(inspectOut[0].State.Checkpointed).To(BeFalse(), ".State.Checkpointed")
Expect(inspectOut[0].State.Restored).To(BeFalse(), ".State.Restored")
Expect(inspectOut[0].State.CheckpointPath).To(Equal(""))
Expect(inspectOut[0].State.CheckpointLog).To(Equal(""))
Expect(inspectOut[0].State.RestoreLog).To(Equal(""))
Expect(inspectOut[0].State).To(HaveField("CheckpointPath", ""))
Expect(inspectOut[0].State).To(HaveField("CheckpointLog", ""))
Expect(inspectOut[0].State).To(HaveField("RestoreLog", ""))

result := podmanTest.Podman([]string{
"container",
Expand All @@ -125,7 +125,7 @@ var _ = Describe("Podman checkpoint", func() {
Expect(inspectOut[0].State.Restored).To(BeFalse(), ".State.Restored")
Expect(inspectOut[0].State.CheckpointPath).To(ContainSubstring("userdata/checkpoint"))
Expect(inspectOut[0].State.CheckpointLog).To(ContainSubstring("userdata/dump.log"))
Expect(inspectOut[0].State.RestoreLog).To(Equal(""))
Expect(inspectOut[0].State).To(HaveField("RestoreLog", ""))

result = podmanTest.Podman([]string{
"container",
Expand Down Expand Up @@ -179,9 +179,9 @@ var _ = Describe("Podman checkpoint", func() {
inspectOut = inspect.InspectContainerToJSON()
Expect(inspectOut[0].State.Checkpointed).To(BeFalse(), ".State.Checkpointed")
Expect(inspectOut[0].State.Restored).To(BeFalse(), ".State.Restored")
Expect(inspectOut[0].State.CheckpointPath).To(Equal(""))
Expect(inspectOut[0].State.CheckpointLog).To(Equal(""))
Expect(inspectOut[0].State.RestoreLog).To(Equal(""))
Expect(inspectOut[0].State).To(HaveField("CheckpointPath", ""))
Expect(inspectOut[0].State).To(HaveField("CheckpointLog", ""))
Expect(inspectOut[0].State).To(HaveField("RestoreLog", ""))
})

It("podman checkpoint a running container by name", func() {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("Podman commit", func() {
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
check.WaitWithDefaultTimeout()
data := check.InspectImageJSON()
Expect(data[0].Comment).To(Equal("testing-commit"))
Expect(data[0]).To(HaveField("Comment", "testing-commit"))
})

It("podman commit container with author", func() {
Expand All @@ -107,7 +107,7 @@ var _ = Describe("Podman commit", func() {
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
check.WaitWithDefaultTimeout()
data := check.InspectImageJSON()
Expect(data[0].Author).To(Equal("snoopy"))
Expect(data[0]).To(HaveField("Author", "snoopy"))
})

It("podman commit container with change flag", func() {
Expand Down Expand Up @@ -293,7 +293,7 @@ var _ = Describe("Podman commit", func() {
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
check.WaitWithDefaultTimeout()
data := check.InspectImageJSON()
Expect(data[0].ID).To(Equal(string(id)))
Expect(data[0]).To(HaveField("ID", string(id)))
})

It("podman commit should not commit secret", func() {
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/container_clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ var _ = Describe("Podman container clone", func() {
ctrInspect := podmanTest.Podman([]string{"inspect", clone.OutputToString()})
ctrInspect.WaitWithDefaultTimeout()
Expect(ctrInspect).To(Exit(0))
Expect(ctrInspect.InspectContainerToJSON()[0].ImageName).To(Equal(fedoraMinimal))
Expect(ctrInspect.InspectContainerToJSON()[0].Name).To(Equal("new_name"))
Expect(ctrInspect.InspectContainerToJSON()[0]).To(HaveField("ImageName", fedoraMinimal))
Expect(ctrInspect.InspectContainerToJSON()[0]).To(HaveField("Name", "new_name"))
})

It("podman container clone name test", func() {
Expand All @@ -84,7 +84,7 @@ var _ = Describe("Podman container clone", func() {
cloneInspect.WaitWithDefaultTimeout()
Expect(cloneInspect).To(Exit(0))
cloneData := cloneInspect.InspectContainerToJSON()
Expect(cloneData[0].Name).To(Equal("testing123"))
Expect(cloneData[0]).To(HaveField("Name", "testing123"))
})

It("podman container clone resource limits override", func() {
Expand All @@ -104,7 +104,7 @@ var _ = Describe("Podman container clone", func() {
cloneInspect.WaitWithDefaultTimeout()
Expect(cloneInspect).To(Exit(0))
cloneData := cloneInspect.InspectContainerToJSON()
Expect(createData[0].HostConfig.NanoCpus).To(Equal(cloneData[0].HostConfig.NanoCpus))
Expect(createData[0].HostConfig).To(HaveField("NanoCpus", cloneData[0].HostConfig.NanoCpus))

create = podmanTest.Podman([]string{"create", "--memory=5", ALPINE})
create.WaitWithDefaultTimeout()
Expand All @@ -122,7 +122,7 @@ var _ = Describe("Podman container clone", func() {
cloneInspect.WaitWithDefaultTimeout()
Expect(cloneInspect).To(Exit(0))
cloneData = cloneInspect.InspectContainerToJSON()
Expect(createData[0].HostConfig.MemorySwap).To(Equal(cloneData[0].HostConfig.MemorySwap))
Expect(createData[0].HostConfig).To(HaveField("MemorySwap", cloneData[0].HostConfig.MemorySwap))

create = podmanTest.Podman([]string{"create", "--cpus=5", ALPINE})
create.WaitWithDefaultTimeout()
Expand All @@ -145,7 +145,7 @@ var _ = Describe("Podman container clone", func() {
Expect(cloneInspect).To(Exit(0))
cloneData = cloneInspect.InspectContainerToJSON()
Expect(createData[0].HostConfig.NanoCpus).ToNot(Equal(cloneData[0].HostConfig.NanoCpus))
Expect(cloneData[0].HostConfig.NanoCpus).To(Equal(nanoCPUs))
Expect(cloneData[0].HostConfig).To(HaveField("NanoCpus", nanoCPUs))

create = podmanTest.Podman([]string{"create", ALPINE})
create.WaitWithDefaultTimeout()
Expand All @@ -158,7 +158,7 @@ var _ = Describe("Podman container clone", func() {
cloneInspect.WaitWithDefaultTimeout()
Expect(cloneInspect).To(Exit(0))
cloneData = cloneInspect.InspectContainerToJSON()
Expect(cloneData[0].HostConfig.MemorySwappiness).To(Equal(int64(0)))
Expect(cloneData[0].HostConfig).To(HaveField("MemorySwappiness", int64(0)))

})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/container_create_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func checkDataVolumeContainer(pTest *PodmanTestIntegration, image, cont, dest, d
inspect := pTest.InspectContainer(cont)
Expect(inspect).To(HaveLen(1))
Expect(inspect[0].Mounts).To(HaveLen(1))
Expect(inspect[0].Mounts[0].Destination).To(Equal(dest))
Expect(inspect[0].Mounts[0]).To(HaveField("Destination", dest))

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

Expand Down
32 changes: 16 additions & 16 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var _ = Describe("Podman create", func() {
Expect(session).Should(Exit(0))

ctrJSON := podmanTest.InspectContainer(ctrName)
Expect(podData.ID).To(Equal(ctrJSON[0].Pod)) // Make sure the container's pod matches the pod's ID
Expect(podData).To(HaveField("ID", ctrJSON[0].Pod)) // Make sure the container's pod matches the pod's ID
})

It("podman run entrypoint and cmd test", func() {
Expand All @@ -281,7 +281,7 @@ var _ = Describe("Podman create", func() {
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"))
Expect(ctrJSON[0].Config).To(HaveField("Entrypoint", "docker-entrypoint.sh"))
})

It("podman create --pull", func() {
Expand Down Expand Up @@ -413,8 +413,8 @@ var _ = Describe("Podman create", func() {
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
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)))
Expect(data[0].HostConfig.RestartPolicy).To(HaveField("Name", "on-failure"))
Expect(data[0].HostConfig.RestartPolicy).To(HaveField("MaximumRetryCount", uint(5)))
})

It("podman create with --restart-policy=always:5 fails", func() {
Expand All @@ -434,7 +434,7 @@ var _ = Describe("Podman create", func() {
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.RestartPolicy.Name).To(Equal(unlessStopped))
Expect(data[0].HostConfig.RestartPolicy).To(HaveField("Name", unlessStopped))
})

It("podman create with -m 1000000 sets swap to 2000000", func() {
Expand All @@ -448,7 +448,7 @@ var _ = Describe("Podman create", func() {
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.MemorySwap).To(Equal(int64(2 * numMem)))
Expect(data[0].HostConfig).To(HaveField("MemorySwap", int64(2*numMem)))
})

It("podman create --cpus 5 sets nanocpus", func() {
Expand All @@ -463,7 +463,7 @@ var _ = Describe("Podman create", func() {
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(data).To(HaveLen(1))
Expect(data[0].HostConfig.NanoCpus).To(Equal(int64(nanoCPUs)))
Expect(data[0].HostConfig).To(HaveField("NanoCpus", int64(nanoCPUs)))
})

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

It("podman create --tz", func() {
Expand All @@ -509,15 +509,15 @@ var _ = Describe("Podman create", func() {
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Timezone).To(Equal("Pacific/Honolulu"))
Expect(data[0].Config).To(HaveField("Timezone", "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(data).To(HaveLen(1))
Expect(data[0].Config.Timezone).To(Equal("local"))
Expect(data[0].Config).To(HaveField("Timezone", "local"))
})

It("podman create --umask", func() {
Expand All @@ -531,31 +531,31 @@ var _ = Describe("Podman create", func() {
inspect.WaitWithDefaultTimeout()
data := inspect.InspectContainerToJSON()
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0022"))
Expect(data[0].Config).To(HaveField("Umask", "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(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0002"))
Expect(data[0].Config).To(HaveField("Umask", "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(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0077"))
Expect(data[0].Config).To(HaveField("Umask", "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(data).To(HaveLen(1))
Expect(data[0].Config.Umask).To(Equal("0022"))
Expect(data[0].Config).To(HaveField("Umask", "0022"))

session = podmanTest.Podman([]string{"create", "--umask", "9999", "--name", "bad", ALPINE})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -689,8 +689,8 @@ var _ = Describe("Podman create", func() {

idata := setup.InspectImageJSON() // returns []inspect.ImageData
Expect(idata).To(HaveLen(1))
Expect(idata[0].Os).To(Equal(runtime.GOOS))
Expect(idata[0].Architecture).To(Equal("arm64"))
Expect(idata[0]).To(HaveField("Os", runtime.GOOS))
Expect(idata[0]).To(HaveField("Architecture", "arm64"))
})

It("podman create --uid/gidmap --pod conflict test", func() {
Expand Down
Loading

0 comments on commit 87454cf

Please sign in to comment.