Skip to content

Commit ec3b019

Browse files
committed
Small improvements
1 parent 1e77ec8 commit ec3b019

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

filebeat/input/journald/pkg/journalctl/chroot_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ func TestNewFactoryChroot(t *testing.T) {
6767

6868
// Create container configuration
6969
containerConfig := &container.Config{
70-
Image: imageName,
71-
Cmd: []string{"go", "test", "-v", "-count=1", "-run=TestInDockerNewFactory"},
72-
Tty: true,
73-
WorkingDir: "/workspace/filebeat/input/journald/pkg/journalctl",
70+
Image: imageName,
71+
Cmd: []string{"go", "test", "-v", "-count=1", "-run=TestInDockerNewFactory"},
72+
Tty: true,
73+
AttachStdin: false,
74+
WorkingDir: "/workspace/filebeat/input/journald/pkg/journalctl",
7475
Env: []string{
7576
"IN_DOCKER_CONTAINER=true",
7677
fmt.Sprintf("JOURNALCTL_PATH=%s", journalctlPath),
@@ -149,20 +150,21 @@ func TestInDockerNewFactory(t *testing.T) {
149150
require.NotEmpty(t, chrootPath, "CHROOT_PATH must be set")
150151

151152
tempDir := os.Getenv("TEST_TEMP_DIR")
152-
require.NotEmpty(t, chrootPath, "TEST_TEMP_DIR be set")
153+
require.NotEmpty(t, tempDir, "TEST_TEMP_DIR be set")
153154

154-
testCtx, cancel := context.WithCancel(t.Context())
155+
jctlCtx, cancel := context.WithCancel(t.Context())
155156
t.Cleanup(cancel)
156157

157158
logger := logptest.NewFileLogger(t, tempDir)
158159
factory := NewFactory(chrootPath, journalctlPath)
159160

160-
jctl, err := factory(testCtx, logger.Logger, "--version")
161+
// Try to read version output, this ensures we can call journalctl
162+
// without the need of any messages in the journal
163+
jctl, err := factory(jctlCtx, logger.Logger, "--version")
161164
require.NoError(t, err, "failed to create journalctl with chroot")
162165
defer jctl.Kill()
163166

164-
// Try to read version output
165-
data, err := jctl.Next(testCtx)
167+
data, err := jctl.Next(jctlCtx)
166168
require.NoError(t, err, "failed to read from journalctl")
167169
require.NotEmpty(t, data, "expected output from journalctl --version")
168170
}

filebeat/input/journald/pkg/journalctl/journalctl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type journalctl struct {
4545
waitDone sync.WaitGroup
4646
}
4747

48-
// NewFactory returns a function that instantiates[journalctl].
48+
// NewFactory returns a function that instantiates [journalctl].
4949
// The caller is responsible for calling Kill to ensure the
5050
// journalctl process created is correctly terminated.
5151
//
52-
// If chroot is non-empty, then journalctlPath must be set and be
52+
// If chroot is non-empty, then journalctlPath must be non-empty and be
5353
// the absolute path to the journalctl binary inside the chroot.
5454
//
5555
// The returned type is an interface to allow mocking for testing

0 commit comments

Comments
 (0)