diff options
author | baude <bbaude@redhat.com> | 2018-01-31 18:47:51 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-02-01 19:04:00 +0000 |
commit | 0387f69d39b7ff15c78ff39ddb350523c73719d6 (patch) | |
tree | d19cbbeeaa105f7ee4dfaa733b0808d76a79f0cb /test | |
parent | 03cfe5ebbee306ee4aa84c74bbff83712e50fb1c (diff) | |
download | podman-0387f69d39b7ff15c78ff39ddb350523c73719d6.tar.gz podman-0387f69d39b7ff15c78ff39ddb350523c73719d6.tar.bz2 podman-0387f69d39b7ff15c78ff39ddb350523c73719d6.zip |
Migrate kill tests to ginkgo
Migrate kill tests to the ginkgo suite and remove the
podman_kill bats.
Signed-off-by: baude <bbaude@redhat.com>
Closes: #281
Approved by: baude
Diffstat (limited to 'test')
-rw-r--r-- | test/e2e/kill_test.go | 95 | ||||
-rw-r--r-- | test/e2e/libpod_suite_test.go | 21 | ||||
-rw-r--r-- | test/e2e/ps_test.go | 68 | ||||
-rw-r--r-- | test/e2e/rm_test.go | 6 | ||||
-rw-r--r-- | test/podman_kill.bats | 71 |
5 files changed, 142 insertions, 119 deletions
diff --git a/test/e2e/kill_test.go b/test/e2e/kill_test.go new file mode 100644 index 000000000..c0ee3dab9 --- /dev/null +++ b/test/e2e/kill_test.go @@ -0,0 +1,95 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman kill", func() { + var ( + tempdir string + err error + podmanTest PodmanTest + ) + + BeforeEach(func() { + tempdir, err = CreateTempDirInTempDir() + if err != nil { + os.Exit(1) + } + podmanTest = PodmanCreate(tempdir) + podmanTest.RestoreAllArtifacts() + }) + + AfterEach(func() { + podmanTest.Cleanup() + + }) + + It("podman kill bogus container", func() { + session := podmanTest.Podman([]string{"kill", "foobar"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Not(Equal(0))) + }) + + It("podman kill a running container by id", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"kill", cid}) + result.WaitWithDefaultTimeout() + + Expect(result.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) + }) + + It("podman kill a running container by id with TERM", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"kill", "-s", "9", cid}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) + }) + + It("podman kill a running container by name", func() { + session := podmanTest.RunSleepContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"kill", "-s", "9", "test1"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) + }) + + It("podman kill a running container by id with a bogus signal", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"kill", "-s", "foobar", cid}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(125)) + Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) + }) + + It("podman kill latest container", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"kill", "-l"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) + }) +}) diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index aaad97447..be9be93d8 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -345,11 +345,28 @@ func (p *PodmanTest) RunSleepContainer(name string) *PodmanSession { //RunLsContainer runs a simple container in the background that // simply runs ls. If the name passed != "", it will have a name -func (p *PodmanTest) RunLsContainer(name string) *PodmanSession { +func (p *PodmanTest) RunLsContainer(name string) (*PodmanSession, int, string) { var podmanArgs = []string{"run"} if name != "" { podmanArgs = append(podmanArgs, "--name", name) } podmanArgs = append(podmanArgs, "-d", ALPINE, "ls") - return p.Podman(podmanArgs) + session := p.Podman(podmanArgs) + session.WaitWithDefaultTimeout() + return session, session.ExitCode(), session.OutputToString() +} + +//NumberOfContainersRunning returns an int of how many +// containers are currently running. +func (p *PodmanTest) NumberOfContainersRunning() int { + var containers []string + ps := p.Podman([]string{"ps", "-q"}) + ps.WaitWithDefaultTimeout() + Expect(ps.ExitCode()).To(Equal(0)) + for _, i := range ps.OutputToStringArray() { + if i != "" { + containers = append(containers, i) + } + } + return len(containers) } diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index 690015552..d0aa0bd7c 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -47,9 +47,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps all", func() { - session := podmanTest.RunLsContainer("") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a"}) result.WaitWithDefaultTimeout() @@ -58,9 +57,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps size flag", func() { - session := podmanTest.RunLsContainer("") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "--size"}) result.WaitWithDefaultTimeout() @@ -69,10 +67,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps quiet flag", func() { - session := podmanTest.RunLsContainer("") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - fullCid := session.OutputToString() + _, ec, fullCid := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "-q"}) result.WaitWithDefaultTimeout() @@ -82,9 +78,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps latest flag", func() { - session := podmanTest.RunLsContainer("") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "--latest"}) result.WaitWithDefaultTimeout() @@ -93,18 +88,15 @@ var _ = Describe("Podman ps", func() { }) It("podman ps last flag", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) - session = podmanTest.RunLsContainer("test2") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ = podmanTest.RunLsContainer("test2") + Expect(ec).To(Equal(0)) - session = podmanTest.RunLsContainer("test3") - session.WaitWithDefaultTimeout() + _, ec, _ = podmanTest.RunLsContainer("test3") + Expect(ec).To(Equal(0)) - Expect(session.ExitCode()).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "--last", "2"}) result.WaitWithDefaultTimeout() Expect(result.ExitCode()).To(Equal(0)) @@ -112,10 +104,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps no-trunc", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - fullCid := session.OutputToString() + _, ec, fullCid := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"}) result.WaitWithDefaultTimeout() @@ -125,9 +115,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps namespace flag", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "--namespace"}) result.WaitWithDefaultTimeout() @@ -136,9 +125,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps namespace flag with json format", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"}) result.WaitWithDefaultTimeout() @@ -147,9 +135,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps namespace flag with go template format", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "--format", "\"table {{.ID}} {{.Image}} {{.Labels}}\""}) result.WaitWithDefaultTimeout() @@ -158,9 +145,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps ancestor filter flag", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "--filter", "ancestor=docker.io/library/alpine:latest"}) result.WaitWithDefaultTimeout() @@ -168,10 +154,8 @@ var _ = Describe("Podman ps", func() { }) It("podman ps id filter flag", func() { - session := podmanTest.RunLsContainer("test1") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - fullCid := session.OutputToString() + _, ec, fullCid := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"ps", "-a", "--filter", fmt.Sprintf("id=%s", fullCid)}) result.WaitWithDefaultTimeout() diff --git a/test/e2e/rm_test.go b/test/e2e/rm_test.go index 1ef8ee5e6..a59b2ee01 100644 --- a/test/e2e/rm_test.go +++ b/test/e2e/rm_test.go @@ -29,10 +29,8 @@ var _ = Describe("Podman rm", func() { }) It("podman rm stopped container", func() { - session := podmanTest.RunLsContainer("") - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) - cid := session.OutputToString() + _, ec, cid := podmanTest.RunLsContainer("") + Expect(ec).To(Equal(0)) result := podmanTest.Podman([]string{"rm", cid}) result.WaitWithDefaultTimeout() diff --git a/test/podman_kill.bats b/test/podman_kill.bats deleted file mode 100644 index f24bd0971..000000000 --- a/test/podman_kill.bats +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -function teardown() { - cleanup_test -} - -function setup() { - copy_images -} - -@test "kill a bogus container" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} kill foobar - echo "$output" - [ "$status" -ne 0 ] -} - -@test "kill a running container by id" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d ${ALPINE} sleep 9999 - [ "$status" -eq 0 ] - ctr_id="$output" - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} kill $ctr_id - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps - [ "$status" -eq 0 ] -} - -@test "kill a running container by id with TERM" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d ${ALPINE} sleep 9999 - [ "$status" -eq 0 ] - ctr_id="$output" - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} kill -s TERM $ctr_id - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps --no-trunc - [ "$status" -eq 0 ] -} - -@test "kill a running container by name" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run --name test1 -d ${ALPINE} sleep 9999 - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} kill -s TERM test1 - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps --no-trunc - [ "$status" -eq 0 ] -} - -@test "kill a running container by id with a bogus signal" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d ${ALPINE} sleep 9999 - [ "$status" -eq 0 ] - ctr_id="$output" - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} kill -s foobar $ctr_id - [ "$status" -eq 125 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} ps --no-trunc - [ "$status" -eq 0 ] -} - -@test "kill the latest container run" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d ${ALPINE} sleep 9999 - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} kill -l - echo "$output" - [ "$status" -eq 0 ] -} |