Skip to content

Commit

Permalink
Harden journald test
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Jan 24, 2025
1 parent 300a705 commit 89c58d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion cmd/nerdctl/container/container_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package container

import (
"fmt"
"os/exec"
"runtime"
"strings"
"testing"
"time"

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"

"github.com/containerd/nerdctl/v2/pkg/testutil"
)
Expand Down Expand Up @@ -109,8 +111,14 @@ func TestLogsWithInheritedFlags(t *testing.T) {
}

func TestLogsOfJournaldDriver(t *testing.T) {
t.Parallel()
testutil.RequireExecutable(t, "journalctl")
journalctl, _ := exec.LookPath("journalctl")
res := icmd.RunCmd(icmd.Command(journalctl, "-xe"))
if res.ExitCode != 0 {
t.Skip("current user is not allowed to access journal logs - presumably not a member of adm")
}

t.Parallel()
base := testutil.NewBase(t)
containerName := testutil.Identifier(t)

Expand Down
18 changes: 14 additions & 4 deletions cmd/nerdctl/container/container_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ func TestRunWithJsonFileLogDriverAndLogPathOpt(t *testing.T) {
}

func TestRunWithJournaldLogDriver(t *testing.T) {
testutil.RequireExecutable(t, "journalctl")
journalctl, _ := exec.LookPath("journalctl")
res := icmd.RunCmd(icmd.Command(journalctl, "-xe"))
if res.ExitCode != 0 {
t.Skip("current user is not allowed to access journal logs - presumably not a member of adm")
}

if runtime.GOOS == "windows" {
t.Skip("journald log driver is not yet implemented on Windows")
}
Expand All @@ -327,8 +334,6 @@ func TestRunWithJournaldLogDriver(t *testing.T) {
"sh", "-euxc", "echo foo; echo bar").AssertOK()

time.Sleep(3 * time.Second)
journalctl, err := exec.LookPath("journalctl")
assert.NilError(t, err)

inspectedContainer := base.InspectContainer(containerName)

Expand Down Expand Up @@ -370,6 +375,13 @@ func TestRunWithJournaldLogDriver(t *testing.T) {
}

func TestRunWithJournaldLogDriverAndLogOpt(t *testing.T) {
testutil.RequireExecutable(t, "journalctl")
journalctl, _ := exec.LookPath("journalctl")
res := icmd.RunCmd(icmd.Command(journalctl, "-xe"))
if res.ExitCode != 0 {
t.Skip("current user is not allowed to access journal logs - presumably not a member of adm")
}

if runtime.GOOS == "windows" {
t.Skip("journald log driver is not yet implemented on Windows")
}
Expand All @@ -381,8 +393,6 @@ func TestRunWithJournaldLogDriverAndLogOpt(t *testing.T) {
"sh", "-euxc", "echo foo; echo bar").AssertOK()

time.Sleep(3 * time.Second)
journalctl, err := exec.LookPath("journalctl")
assert.NilError(t, err)
inspectedContainer := base.InspectContainer(containerName)
found := 0
check := func(log poll.LogT) poll.Result {
Expand Down

0 comments on commit 89c58d4

Please sign in to comment.