mirror of https://github.com/containers/podman.git
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
This commit is contained in:
parent
03cfe5ebbe
commit
0387f69d39
|
@ -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))
|
||||||
|
})
|
||||||
|
})
|
|
@ -345,11 +345,28 @@ func (p *PodmanTest) RunSleepContainer(name string) *PodmanSession {
|
||||||
|
|
||||||
//RunLsContainer runs a simple container in the background that
|
//RunLsContainer runs a simple container in the background that
|
||||||
// simply runs ls. If the name passed != "", it will have a name
|
// 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"}
|
var podmanArgs = []string{"run"}
|
||||||
if name != "" {
|
if name != "" {
|
||||||
podmanArgs = append(podmanArgs, "--name", name)
|
podmanArgs = append(podmanArgs, "--name", name)
|
||||||
}
|
}
|
||||||
podmanArgs = append(podmanArgs, "-d", ALPINE, "ls")
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps all", func() {
|
It("podman ps all", func() {
|
||||||
session := podmanTest.RunLsContainer("")
|
_, ec, _ := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a"})
|
result := podmanTest.Podman([]string{"ps", "-a"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -58,9 +57,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps size flag", func() {
|
It("podman ps size flag", func() {
|
||||||
session := podmanTest.RunLsContainer("")
|
_, ec, _ := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "--size"})
|
result := podmanTest.Podman([]string{"ps", "-a", "--size"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -69,10 +67,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps quiet flag", func() {
|
It("podman ps quiet flag", func() {
|
||||||
session := podmanTest.RunLsContainer("")
|
_, ec, fullCid := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
fullCid := session.OutputToString()
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "-q"})
|
result := podmanTest.Podman([]string{"ps", "-a", "-q"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -82,9 +78,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps latest flag", func() {
|
It("podman ps latest flag", func() {
|
||||||
session := podmanTest.RunLsContainer("")
|
_, ec, _ := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "--latest"})
|
result := podmanTest.Podman([]string{"ps", "--latest"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -93,18 +88,15 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps last flag", func() {
|
It("podman ps last flag", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
session = podmanTest.RunLsContainer("test2")
|
_, ec, _ = podmanTest.RunLsContainer("test2")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
session = podmanTest.RunLsContainer("test3")
|
_, ec, _ = podmanTest.RunLsContainer("test3")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
|
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
result := podmanTest.Podman([]string{"ps", "--last", "2"})
|
result := podmanTest.Podman([]string{"ps", "--last", "2"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
@ -112,10 +104,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps no-trunc", func() {
|
It("podman ps no-trunc", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, fullCid := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
fullCid := session.OutputToString()
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"})
|
result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -125,9 +115,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps namespace flag", func() {
|
It("podman ps namespace flag", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, _ := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "--namespace"})
|
result := podmanTest.Podman([]string{"ps", "-a", "--namespace"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -136,9 +125,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps namespace flag with json format", func() {
|
It("podman ps namespace flag with json format", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"})
|
result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -147,9 +135,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps namespace flag with go template format", func() {
|
It("podman ps namespace flag with go template format", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "--format", "\"table {{.ID}} {{.Image}} {{.Labels}}\""})
|
result := podmanTest.Podman([]string{"ps", "-a", "--format", "\"table {{.ID}} {{.Image}} {{.Labels}}\""})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -158,9 +145,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps ancestor filter flag", func() {
|
It("podman ps ancestor filter flag", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "--filter", "ancestor=docker.io/library/alpine:latest"})
|
result := podmanTest.Podman([]string{"ps", "-a", "--filter", "ancestor=docker.io/library/alpine:latest"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -168,10 +154,8 @@ var _ = Describe("Podman ps", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman ps id filter flag", func() {
|
It("podman ps id filter flag", func() {
|
||||||
session := podmanTest.RunLsContainer("test1")
|
_, ec, fullCid := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
fullCid := session.OutputToString()
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"ps", "-a", "--filter", fmt.Sprintf("id=%s", fullCid)})
|
result := podmanTest.Podman([]string{"ps", "-a", "--filter", fmt.Sprintf("id=%s", fullCid)})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
|
|
@ -29,10 +29,8 @@ var _ = Describe("Podman rm", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman rm stopped container", func() {
|
It("podman rm stopped container", func() {
|
||||||
session := podmanTest.RunLsContainer("")
|
_, ec, cid := podmanTest.RunLsContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
Expect(ec).To(Equal(0))
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
|
||||||
cid := session.OutputToString()
|
|
||||||
|
|
||||||
result := podmanTest.Podman([]string{"rm", cid})
|
result := podmanTest.Podman([]string{"rm", cid})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
|
|
@ -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 ]
|
|
||||||
}
|
|
Loading…
Reference in New Issue