Skip to content

Commit 1194557

Browse files
Merge pull request containers#24977 from mtrmac/exitcleanly
RFC: Introduce PodmanTestIntegration.PodmanCleanly
2 parents 1a00c92 + de1aa44 commit 1194557

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

test/e2e/attach_test.go

+6-20
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,15 @@ var _ = Describe("Podman attach", func() {
2020
})
2121

2222
It("podman attach to non-running container", func() {
23-
session := podmanTest.Podman([]string{"create", "--name", "test1", "-i", CITEST_IMAGE, "ls"})
24-
session.WaitWithDefaultTimeout()
25-
Expect(session).Should(ExitCleanly())
23+
podmanTest.PodmanExitCleanly("create", "--name", "test1", "-i", CITEST_IMAGE, "ls")
2624

2725
results := podmanTest.Podman([]string{"attach", "test1"})
2826
results.WaitWithDefaultTimeout()
2927
Expect(results).Should(ExitWithError(125, "you can only attach to running containers"))
3028
})
3129

3230
It("podman container attach to non-running container", func() {
33-
session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-i", CITEST_IMAGE, "ls"})
34-
35-
session.WaitWithDefaultTimeout()
36-
Expect(session).Should(ExitCleanly())
31+
podmanTest.PodmanExitCleanly("container", "create", "--name", "test1", "-i", CITEST_IMAGE, "ls")
3732

3833
results := podmanTest.Podman([]string{"container", "attach", "test1"})
3934
results.WaitWithDefaultTimeout()
@@ -55,9 +50,7 @@ var _ = Describe("Podman attach", func() {
5550
})
5651

5752
It("podman attach to a running container", func() {
58-
session := podmanTest.Podman([]string{"run", "-d", "--name", "test", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done"})
59-
session.WaitWithDefaultTimeout()
60-
Expect(session).Should(ExitCleanly())
53+
podmanTest.PodmanExitCleanly("run", "-d", "--name", "test", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done")
6154

6255
results := podmanTest.Podman([]string{"attach", "test"})
6356
time.Sleep(2 * time.Second)
@@ -67,13 +60,8 @@ var _ = Describe("Podman attach", func() {
6760
})
6861

6962
It("podman attach to the latest container", func() {
70-
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done"})
71-
session.WaitWithDefaultTimeout()
72-
Expect(session).Should(ExitCleanly())
73-
74-
session = podmanTest.Podman([]string{"run", "-d", "--name", "test2", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test2; sleep 1; done"})
75-
session.WaitWithDefaultTimeout()
76-
Expect(session).Should(ExitCleanly())
63+
podmanTest.PodmanExitCleanly("run", "-d", "--name", "test1", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done")
64+
podmanTest.PodmanExitCleanly("run", "-d", "--name", "test2", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test2; sleep 1; done")
7765

7866
cid := "-l"
7967
if IsRemote() {
@@ -87,9 +75,7 @@ var _ = Describe("Podman attach", func() {
8775
})
8876

8977
It("podman attach to a container with --sig-proxy set to false", func() {
90-
session := podmanTest.Podman([]string{"run", "-d", "--name", "test", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done"})
91-
session.WaitWithDefaultTimeout()
92-
Expect(session).Should(ExitCleanly())
78+
podmanTest.PodmanExitCleanly("run", "-d", "--name", "test", CITEST_IMAGE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done")
9379

9480
results := podmanTest.Podman([]string{"attach", "--sig-proxy=false", "test"})
9581
time.Sleep(2 * time.Second)

test/e2e/common_test.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,16 @@ func (s *PodmanSessionIntegration) InspectImageJSON() []inspect.ImageData {
484484
return i
485485
}
486486

487+
// PodmanExitCleanly runs a podman command with args, and expects it to ExitCleanly within the default timeout.
488+
// It returns the session (to allow consuming output if desired).
489+
func (p *PodmanTestIntegration) PodmanExitCleanly(args ...string) *PodmanSessionIntegration {
490+
GinkgoHelper()
491+
session := p.Podman(args)
492+
session.WaitWithDefaultTimeout()
493+
Expect(session).Should(ExitCleanly())
494+
return session
495+
}
496+
487497
// InspectContainer returns a container's inspect data in JSON format
488498
func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectContainerData {
489499
cmd := []string{"inspect", name}
@@ -520,15 +530,11 @@ func (p *PodmanTestIntegration) CheckFileInContainerSubstring(name, filepath, ex
520530

521531
// StopContainer stops a container with no timeout, ensuring a fast test.
522532
func (p *PodmanTestIntegration) StopContainer(nameOrID string) {
523-
stop := p.Podman([]string{"stop", "-t0", nameOrID})
524-
stop.WaitWithDefaultTimeout()
525-
Expect(stop).Should(ExitCleanly())
533+
p.PodmanExitCleanly("stop", "-t0", nameOrID)
526534
}
527535

528536
func (p *PodmanTestIntegration) StopPod(nameOrID string) {
529-
stop := p.Podman([]string{"pod", "stop", "-t0", nameOrID})
530-
stop.WaitWithDefaultTimeout()
531-
Expect(stop).Should(ExitCleanly())
537+
p.PodmanExitCleanly("pod", "stop", "-t0", nameOrID)
532538
}
533539

534540
func processTestResult(r SpecReport) {
@@ -586,9 +592,7 @@ func (p *PodmanTestIntegration) RunTopContainerWithArgs(name string, args []stri
586592
}
587593
podmanArgs = append(podmanArgs, args...)
588594
podmanArgs = append(podmanArgs, "-d", ALPINE, "top", "-b")
589-
session := p.Podman(podmanArgs)
590-
session.WaitWithDefaultTimeout()
591-
Expect(session).To(ExitCleanly())
595+
session := p.PodmanExitCleanly(podmanArgs...)
592596
cid := session.OutputToString()
593597
// Output indicates that top is running, which means it's safe
594598
// for our caller to invoke `podman stop`

test/utils/matchers.go

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
8181
}
8282

8383
// ExitCleanly asserts that a PodmanSession exits 0 and with no stderr
84+
// Consider using PodmanTestIntegration.PodmanExitCleanly instead of directly using this matcher.
8485
func ExitCleanly() types.GomegaMatcher {
8586
return &exitCleanlyMatcher{}
8687
}

0 commit comments

Comments
 (0)