From cf4cb4184c5b3e333f55dd2931c88b8ba41366d2 Mon Sep 17 00:00:00 2001 From: Tushar Verma Date: Tue, 25 Aug 2026 22:50:18 +0530 Subject: [PATCH] test/e2e: do not use os.Exit for error handling os.Exit(1) kills the process without ginkgo getting a chance to report anything, so a failure here shows up as a suite that just stopped with no output. All six sites run inside ginkgo, three in a SynchronizedBefore Suite and a helper and three inside It blocks, so Expect works and prints the error and the location. The os.Exit(m.Run()) in TestMain stays, that one is correct. Part of #18540. Signed-off-by: Tushar Verma --- test/e2e/common_test.go | 17 +++++------------ test/e2e/top_test.go | 5 +---- test/e2e/trust_test.go | 8 ++------ 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 32fc3e04e7..d110e75fa7 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -195,19 +195,15 @@ var _ = SynchronizedBeforeSuite(func() []byte { podman.createArtifact(image) } - if err := os.MkdirAll(filepath.Join(ImageCacheDir, podman.ImageCacheFS+"-images"), 0o777); err != nil { - GinkgoWriter.Printf("%q\n", err) - os.Exit(1) - } + err = os.MkdirAll(filepath.Join(ImageCacheDir, podman.ImageCacheFS+"-images"), 0o777) + Expect(err).ToNot(HaveOccurred()) podman.Root = ImageCacheDir // If running localized tests, the cache dir is created and populated. if the // tests are remote, this is a no-op populateCache(podman) - if err := os.MkdirAll(filepath.Join(globalTmpDir, lockdir), 0o700); err != nil { - GinkgoWriter.Printf("%q\n", err) - os.Exit(1) - } + err = os.MkdirAll(filepath.Join(globalTmpDir, lockdir), 0o700) + Expect(err).ToNot(HaveOccurred()) // If running remote, we need to stop the associated podman system service if podman.RemoteTest { @@ -741,10 +737,7 @@ func processTestResult(r SpecReport) { func GetPortLock(port string) *lockfile.LockFile { lockFile := filepath.Join(LockTmpDir, port) lock, err := lockfile.GetLockFile(lockFile) - if err != nil { - GinkgoWriter.Println(err) - os.Exit(1) - } + Expect(err).ToNot(HaveOccurred()) lock.Lock() return lock } diff --git a/test/e2e/top_test.go b/test/e2e/top_test.go index 434e5f7806..fc68c551c0 100644 --- a/test/e2e/top_test.go +++ b/test/e2e/top_test.go @@ -3,7 +3,6 @@ package integration import ( - "os" "os/user" . "github.com/onsi/ginkgo/v2" @@ -81,9 +80,7 @@ var _ = Describe("Podman top", func() { Expect(result.OutputToStringArray()[1]).To(Equal("0")) user, err := user.Current() - if err != nil { - os.Exit(1) - } + Expect(err).ToNot(HaveOccurred()) result = podmanTest.Podman([]string{"container", "top", session.OutputToString(), "huid"}) result.WaitWithDefaultTimeout() diff --git a/test/e2e/trust_test.go b/test/e2e/trust_test.go index 7b31ff689f..7e7e7c041b 100644 --- a/test/e2e/trust_test.go +++ b/test/e2e/trust_test.go @@ -39,13 +39,9 @@ var _ = Describe("Podman trust", Ordered, func() { Expect(session).Should(ExitCleanly()) var teststruct map[string][]map[string]string policyContent, err := os.ReadFile(policyJSON) - if err != nil { - os.Exit(1) - } + Expect(err).ToNot(HaveOccurred()) err = json.Unmarshal(policyContent, &teststruct) - if err != nil { - os.Exit(1) - } + Expect(err).ToNot(HaveOccurred()) Expect(teststruct["default"][0]).To(HaveKeyWithValue("type", "insecureAcceptAnything")) })