Skip to content
Merged
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
63 changes: 25 additions & 38 deletions cmd/nerdctl/container/container_run_systemd_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,49 +73,36 @@ func TestRunWithSystemdTrueEnabled(t *testing.T) {
)

testCase.Setup = func(data test.Data, helpers test.Helpers) {
containerName := testutil.Identifier(t)
data.Labels().Set("containerName", containerName)
helpers.Ensure("run", "-d", "--name", containerName, "--systemd=true", "--entrypoint=/sbin/init", testutil.SystemdImage)
nerdtest.EnsureContainerStarted(helpers, containerName)
helpers.Ensure("run", "-d", "--name", data.Identifier(), "--systemd=true", "--entrypoint=/sbin/init", testutil.SystemdImage)
}

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
containerName := data.Labels().Get("containerName")
helpers.Anyhow("container", "rm", "-f", containerName)
helpers.Anyhow("container", "rm", "-f", data.Identifier())
}

testCase.SubTests = []*test.Case{
{
Description: "should expose SIGTERM+3 stop signal labels",
Copy link
Member

@AkihiroSuda AkihiroSuda Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description texts should not be removed.
At least it should remain as code comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

NoParallel: true,
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
containerName := data.Labels().Get("containerName")
return helpers.Command("inspect", "--format", "{{json .Config.Labels}}", containerName)
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.Contains("SIGRTMIN+3")),
},
{
Description: "waits for systemd to become ready and lists systemd jobs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

NoParallel: true,
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
containerName := data.Labels().Get("containerName")
return helpers.Command("exec", containerName, "sh", "-c", "--", `tries=0

until systemctl is-system-running >/dev/null 2>&1; do

>&2 printf "Waiting for systemd to come up...\n"
sleep 1s
tries=$(( tries + 1))
[ $tries -lt 10 ] || {
>&2 printf "systemd failed to come up in a reasonable amount of time\n"
exit 1
}
done
systemctl list-jobs`)
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.Contains("jobs")),
},
}
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
// should expose SIGTERM+3 stop signal labels
helpers.Command("inspect", "--format", "{{json .Config.Labels}}", data.Identifier()).
Run(&test.Expected{
ExitCode: expect.ExitCodeSuccess,
Output: expect.Contains("SIGRTMIN+3"),
})

// waits for systemd to become ready and lists systemd jobs
return helpers.Command("exec", data.Identifier(), "sh", "-c", "--", `tries=0
until systemctl is-system-running >/dev/null 2>&1; do
>&2 printf "Waiting for systemd to come up...\n"
sleep 1s
tries=$(( tries + 1))
[ $tries -lt 10 ] || {
>&2 printf "systemd failed to come up in a reasonable amount of time\n"
exit 1
}
done
systemctl list-jobs`)
}

testCase.Expected = test.Expects(expect.ExitCodeSuccess, nil, expect.Contains("jobs"))

testCase.Run(t)
}
Expand Down