Skip to content

Commit

Permalink
Merge pull request #21107 from fj-tsubasa/e2e-systemd_test-journald
Browse files Browse the repository at this point in the history
e2e: Skip journalctl if journald is unavailable
  • Loading branch information
openshift-merge-bot[bot] authored Jan 1, 2024
2 parents 7dc7cbf + ec5422a commit 4419924
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions test/e2e/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"))
Expand Down

0 comments on commit 4419924

Please sign in to comment.