Skip to content

Commit 955e7f5

Browse files
mtrmacTomSweeneyRedHat
authored andcommitted
[v4.4.1-rhel] Introduce PodmanTestIntegration.PodmanExitCleanly
This significantly simplifies the ceromony of running a Podman command in integration tests, from > session := p.Podman([]string{"stop", id}) > session.WaitWithDefaultTimeout() > Expect(session).Should(ExitCleanly()) to > p.PodmanExitCleanly("stop", id) There are >4650 instances of ExitCleanly() in the tests, and many could be migrated; this does not do that. Signed-off-by: Miloslav Trmač <mitr@redhat.com> (cherry picked from commit 0c18bea) Signed-off-by: Tom Sweeney <tsweeney@redhat.com>
1 parent a9ac512 commit 955e7f5

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

test/e2e/common_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ func (s *PodmanSessionIntegration) InspectImageJSON() []inspect.ImageData {
421421
return i
422422
}
423423

424+
// PodmanExitCleanly runs a podman command with args, and expects it to ExitCleanly within the default timeout.
425+
// It returns the session (to allow consuming output if desired).
426+
func (p *PodmanTestIntegration) PodmanExitCleanly(args ...string) *PodmanSessionIntegration {
427+
GinkgoHelper()
428+
session := p.Podman(args)
429+
session.WaitWithDefaultTimeout()
430+
Expect(session).Should(ExitCleanly())
431+
return session
432+
}
433+
424434
// InspectContainer returns a container's inspect data in JSON format
425435
func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectContainerData {
426436
cmd := []string{"inspect", name}
@@ -475,8 +485,15 @@ func (p *PodmanTestIntegration) RunTopContainerWithArgs(name string, args []stri
475485
podmanArgs = append(podmanArgs, "--name", name)
476486
}
477487
podmanArgs = append(podmanArgs, args...)
478-
podmanArgs = append(podmanArgs, "-d", ALPINE, "top")
479-
return p.Podman(podmanArgs)
488+
podmanArgs = append(podmanArgs, "-d", ALPINE, "top", "-b")
489+
session := p.PodmanExitCleanly(podmanArgs...)
490+
cid := session.OutputToString()
491+
// Output indicates that top is running, which means it's safe
492+
// for our caller to invoke `podman stop`
493+
if !WaitContainerReady(p, cid, "Mem:", 20, 1) {
494+
Fail("Could not start a top container")
495+
}
496+
return session
480497
}
481498

482499
// RunLsContainer runs a simple container in the background that

test/utils/matchers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
169169
}
170170

171171
// ExitCleanly asserts that a PodmanSession exits 0 and with no stderr
172+
// Consider using PodmanTestIntegration.PodmanExitCleanly instead of directly using this matcher.
172173
func ExitCleanly() types.GomegaMatcher {
173174
return &exitCleanlyMatcher{}
174175
}

0 commit comments

Comments
 (0)