Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden journald test #3843

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
apostasie marked this conversation as resolved.
Show resolved Hide resolved
t.Skipf("current user is not allowed to access journal logs: %s", res.Combined())
}

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.Skipf("current user is not allowed to access journal logs: %s", res.Combined())
}

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.Skipf("current user is not allowed to access journal logs: %s", res.Combined())
}

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