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 Should(Exit()) and ExitWithError() #10932

Merged
merged 1 commit into from
Jul 15, 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
25 changes: 13 additions & 12 deletions test/e2e/attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/containers/podman/v3/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman attach", func() {
Expand Down Expand Up @@ -36,48 +37,48 @@ var _ = Describe("Podman attach", func() {
It("podman attach to bogus container", func() {
session := podmanTest.Podman([]string{"attach", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
Expect(session).Should(Exit(125))
})

It("podman attach to non-running container", func() {
session := podmanTest.Podman([]string{"create", "--name", "test1", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

results := podmanTest.Podman([]string{"attach", "test1"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
Expect(results).Should(Exit(125))
})

It("podman container attach to non-running container", func() {
session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-i", ALPINE, "ls"})

session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

results := podmanTest.Podman([]string{"container", "attach", "test1"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
Expect(results).Should(Exit(125))
})

It("podman attach to multiple containers", func() {
session := podmanTest.RunTopContainer("test1")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.RunTopContainer("test2")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

results := podmanTest.Podman([]string{"attach", "test1", "test2"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
Expect(results).Should(Exit(125))
})

It("podman attach to a running container", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test", ALPINE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

results := podmanTest.Podman([]string{"attach", "test"})
time.Sleep(2 * time.Second)
Expand All @@ -88,11 +89,11 @@ var _ = Describe("Podman attach", func() {
It("podman attach to the latest container", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"run", "-d", "--name", "test2", ALPINE, "/bin/sh", "-c", "while true; do echo test2; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

cid := "-l"
if IsRemote() {
Expand All @@ -108,7 +109,7 @@ var _ = Describe("Podman attach", func() {
It("podman attach to a container with --sig-proxy set to false", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test", ALPINE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

results := podmanTest.Podman([]string{"attach", "--sig-proxy=false", "test"})
time.Sleep(2 * time.Second)
Expand Down
75 changes: 38 additions & 37 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/containers/podman/v3/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman build", func() {
Expand Down Expand Up @@ -42,7 +43,7 @@ var _ = Describe("Podman build", func() {
podmanTest.AddImageToRWStore(ALPINE)
session := podmanTest.Podman([]string{"build", "--pull-never", "build/basicalpine"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

iid := session.OutputToStringArray()[len(session.OutputToStringArray())-1]

Expand All @@ -55,14 +56,14 @@ var _ = Describe("Podman build", func() {

session = podmanTest.Podman([]string{"rmi", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
})

It("podman build with logfile", func() {
logfile := filepath.Join(podmanTest.TempDir, "logfile")
session := podmanTest.Podman([]string{"build", "--pull-never", "--tag", "test", "--logfile", logfile, "build/basicalpine"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

// Verify that OS and Arch are being set
inspect := podmanTest.Podman([]string{"inspect", "test"})
Expand All @@ -77,63 +78,63 @@ var _ = Describe("Podman build", func() {

session = podmanTest.Podman([]string{"rmi", "test"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
})

// If the context directory is pointing at a file and not a directory,
// that's a no no, fail out.
It("podman build context directory a file", func() {
session := podmanTest.Podman([]string{"build", "--pull-never", "build/context_dir_a_file"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
Expect(session).Should(Exit(125))
})

// Check that builds with different values for the squash options
// create the appropriate number of layers, then clean up after.
It("podman build basic alpine with squash", func() {
session := podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-a", "-t", "test-squash-a:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-a"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
// Check for two layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2))

session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-b", "--squash", "-t", "test-squash-b:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-b"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
// Check for three layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(3))

session = podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/squash/Dockerfile.squash-c", "--squash", "-t", "test-squash-c:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-c"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
// Check for two layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(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()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-d"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
// Check for one layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(1))

session = podmanTest.Podman([]string{"rm", "-a"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
})

It("podman build Containerfile locations", func() {
Expand Down Expand Up @@ -168,7 +169,7 @@ var _ = Describe("Podman build", func() {
session.WaitWithDefaultTimeout()

// Then
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
Expect(strings.Fields(session.OutputToString())).
To(ContainElement("scratch"))
})
Expand All @@ -188,7 +189,7 @@ var _ = Describe("Podman build", func() {

session := podmanTest.Podman([]string{"build", "--pull-never", "build/basicalpine", "--iidfile", targetFile})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
id, _ := ioutil.ReadFile(targetFile)

// Verify that id is correct
Expand All @@ -204,11 +205,11 @@ var _ = Describe("Podman build", func() {
"build", "--pull-never", "-f", "build/basicalpine/Containerfile.path", "-t", "test-path",
})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"run", "test-path", "printenv", "PATH"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
stdoutLines := session.OutputToStringArray()
Expect(stdoutLines[0]).Should(Equal(path))
})
Expand All @@ -228,7 +229,7 @@ RUN printenv http_proxy`, ALPINE)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "--http-proxy", "--file", dockerfilePath, podmanTest.TempDir})
session.Wait(120)
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
ok, _ := session.GrepString("1.2.3.4")
Expect(ok).To(BeTrue())
os.Unsetenv("http_proxy")
Expand All @@ -237,7 +238,7 @@ RUN printenv http_proxy`, ALPINE)
It("podman build and check identity", func() {
session := podmanTest.Podman([]string{"build", "--pull-never", "-f", "build/basicalpine/Containerfile.path", "--no-cache", "-t", "test", "build/basicalpine"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

// Verify that OS and Arch are being set
inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ index .Config.Labels }}", "test"})
Expand Down Expand Up @@ -282,7 +283,7 @@ RUN find /test`, ALPINE)

session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "Containerfile", targetSubPath})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
ok, _ := session.GrepString("/test/dummy")
Expect(ok).To(BeTrue())
})
Expand Down Expand Up @@ -324,7 +325,7 @@ RUN find /test`, ALPINE)

session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "subdir/Containerfile", "."})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
})

It("podman remote test .dockerignore", func() {
Expand Down Expand Up @@ -388,7 +389,7 @@ subdir**`

session := podmanTest.Podman([]string{"build", "-t", "test", "."})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
ok, _ := session.GrepString("/testfilter/dummy1")
Expect(ok).NotTo(BeTrue())
ok, _ = session.GrepString("/testfilter/dummy2")
Expand Down Expand Up @@ -448,7 +449,7 @@ RUN [[ -L /test/dummy-symlink ]] && echo SYMLNKOK || echo SYMLNKERR`, ALPINE)

session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", targetSubPath})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
ok, _ := session.GrepString("/test/dummy")
Expect(ok).To(BeTrue())
ok, _ = session.GrepString("/test/emptyDir")
Expand Down Expand Up @@ -481,7 +482,7 @@ RUN grep CapEff /proc/self/status`
session.WaitWithDefaultTimeout()

// Then
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
Expect(strings.Fields(session.OutputToString())).
To(ContainElement(ALPINE))
Expect(strings.Fields(session.OutputToString())).
Expand All @@ -507,31 +508,31 @@ RUN grep CapEff /proc/self/status`
})
session.WaitWithDefaultTimeout()
// Then
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

// When
session = podmanTest.Podman([]string{
"build", "--isolation", "chroot", "--arch", "arm64", targetPath,
})
session.WaitWithDefaultTimeout()
// Then
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

// When
session = podmanTest.Podman([]string{
"build", "--pull-never", "--isolation", "rootless", "--arch", "arm64", targetPath,
})
session.WaitWithDefaultTimeout()
// Then
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

// When
session = podmanTest.Podman([]string{
"build", "--pull-never", "--isolation", "bogus", "--arch", "arm64", targetPath,
})
session.WaitWithDefaultTimeout()
// Then
Expect(session.ExitCode()).To(Equal(125))
Expect(session).Should(Exit(125))
})

It("podman build --timestamp flag", func() {
Expand All @@ -543,7 +544,7 @@ RUN echo hello`, ALPINE)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--timestamp", "0", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Created }}", "test"})
inspect.WaitWithDefaultTimeout()
Expand All @@ -561,7 +562,7 @@ RUN echo hello`, ALPINE)

session := podmanTest.Podman([]string{"build", "--log-rusage", "--pull-never", targetPath})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring("(system)"))
Expect(session.OutputToString()).To(ContainSubstring("(user)"))
Expect(session.OutputToString()).To(ContainSubstring("(elapsed)"))
Expand All @@ -574,7 +575,7 @@ RUN echo hello`, ALPINE)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--arch", "foo", "--os", "bar", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Architecture }}", "test"})
inspect.WaitWithDefaultTimeout()
Expand All @@ -593,7 +594,7 @@ RUN echo hello`, ALPINE)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--os", "windows", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))

inspect := podmanTest.Podman([]string{"image", "inspect", "--format", "{{ .Architecture }}", "test"})
inspect.WaitWithDefaultTimeout()
Expand All @@ -616,11 +617,11 @@ RUN ls /dev/fuse`, ALPINE)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
Expect(session).Should(Exit(125))

session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/fuse", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
})

It("podman build device rename test", func() {
Expand All @@ -632,10 +633,10 @@ RUN ls /dev/test1`, ALPINE)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
Expect(session).Should(Exit(125))

session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/zero:/dev/test1", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session).Should(Exit(0))
})
})
Loading