From ec5422af5b5cacc506818b04d7a0e82d10941e71 Mon Sep 17 00:00:00 2001 From: Tsubasa Watanabe Date: Sat, 30 Dec 2023 00:42:13 +0900 Subject: [PATCH] e2e: Skip journalctl if journald is unavailable Test "podman start container by systemd" is failed on the system in which rootless users don't have accessibility to journald. Therefore, skip the part that reads journal with journalctl. Signed-off-by: Tsubasa Watanabe --- test/e2e/common_test.go | 8 ++++++-- test/e2e/systemd_test.go | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 6d0ed0d5f8..56a26b35be 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -851,17 +851,21 @@ type journaldTests struct { var journald journaldTests -func SkipIfJournaldUnavailable() { +// Check if journalctl is unavailable +func checkAvailableJournald() { f := func() { journald.journaldSkip = false - // Check if journalctl is unavailable cmd := exec.Command("journalctl", "-n", "1") if err := cmd.Run(); err != nil { journald.journaldSkip = true } } journald.journaldOnce.Do(f) +} + +func SkipIfJournaldUnavailable() { + checkAvailableJournald() // In container, journalctl does not return an error even if // journald is unavailable diff --git a/test/e2e/systemd_test.go b/test/e2e/systemd_test.go index 888ecc5cae..da5d2ccc27 100644 --- a/test/e2e/systemd_test.go +++ b/test/e2e/systemd_test.go @@ -64,8 +64,11 @@ WantedBy=default.target start := SystemExec("systemctl", []string{dashWhat, "start", serviceName}) Expect(start).Should(ExitCleanly()) - logs := SystemExec("journalctl", []string{dashWhat, "-n", "20", "-u", serviceName}) - Expect(logs).Should(ExitCleanly()) + checkAvailableJournald() + if !journald.journaldSkip { + logs := SystemExec("journalctl", []string{dashWhat, "-n", "20", "-u", serviceName}) + Expect(logs).Should(ExitCleanly()) + } status := SystemExec("systemctl", []string{dashWhat, "status", serviceName}) Expect(status.OutputToString()).To(ContainSubstring("active (running)"))