From 0c18beaea7393eb6662fa1b8deced6ca7591b3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 8 Jan 2025 20:32:40 +0100 Subject: [PATCH] Introduce PodmanTestIntegration.PodmanExitCleanly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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č --- test/e2e/common_test.go | 22 +++++++++++++--------- test/utils/matchers.go | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index f51d1b42c8..65edfc050d 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -484,6 +484,16 @@ func (s *PodmanSessionIntegration) InspectImageJSON() []inspect.ImageData { return i } +// PodmanExitCleanly runs a podman command with args, and expects it to ExitCleanly within the default timeout. +// It returns the session (to allow consuming output if desired). +func (p *PodmanTestIntegration) PodmanExitCleanly(args ...string) *PodmanSessionIntegration { + GinkgoHelper() + session := p.Podman(args) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + return session +} + // InspectContainer returns a container's inspect data in JSON format func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectContainerData { cmd := []string{"inspect", name} @@ -520,15 +530,11 @@ func (p *PodmanTestIntegration) CheckFileInContainerSubstring(name, filepath, ex // StopContainer stops a container with no timeout, ensuring a fast test. func (p *PodmanTestIntegration) StopContainer(nameOrID string) { - stop := p.Podman([]string{"stop", "-t0", nameOrID}) - stop.WaitWithDefaultTimeout() - Expect(stop).Should(ExitCleanly()) + p.PodmanExitCleanly("stop", "-t0", nameOrID) } func (p *PodmanTestIntegration) StopPod(nameOrID string) { - stop := p.Podman([]string{"pod", "stop", "-t0", nameOrID}) - stop.WaitWithDefaultTimeout() - Expect(stop).Should(ExitCleanly()) + p.PodmanExitCleanly("pod", "stop", "-t0", nameOrID) } func processTestResult(r SpecReport) { @@ -586,9 +592,7 @@ func (p *PodmanTestIntegration) RunTopContainerWithArgs(name string, args []stri } podmanArgs = append(podmanArgs, args...) podmanArgs = append(podmanArgs, "-d", ALPINE, "top", "-b") - session := p.Podman(podmanArgs) - session.WaitWithDefaultTimeout() - Expect(session).To(ExitCleanly()) + session := p.PodmanExitCleanly(podmanArgs...) cid := session.OutputToString() // Output indicates that top is running, which means it's safe // for our caller to invoke `podman stop` diff --git a/test/utils/matchers.go b/test/utils/matchers.go index 50766b7091..a452d19675 100644 --- a/test/utils/matchers.go +++ b/test/utils/matchers.go @@ -81,6 +81,7 @@ func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { } // ExitCleanly asserts that a PodmanSession exits 0 and with no stderr +// Consider using PodmanTestIntegration.PodmanExitCleanly instead of directly using this matcher. func ExitCleanly() types.GomegaMatcher { return &exitCleanlyMatcher{} }