Skip to content

refactor: migrate container_create_linux_test.go to nerdtest.Setup#4900

Merged
AkihiroSuda merged 5 commits into
containerd:mainfrom
ogulcanaydogan:refactor/4613-container-create-linux-tigron
Jun 10, 2026
Merged

refactor: migrate container_create_linux_test.go to nerdtest.Setup#4900
AkihiroSuda merged 5 commits into
containerd:mainfrom
ogulcanaydogan:refactor/4613-container-create-linux-tigron

Conversation

@ogulcanaydogan

Copy link
Copy Markdown
Contributor

Summary

Continues the Tigron migration work tracked in #4613. Migrates the remaining testutil.NewBase-based tests in cmd/nerdctl/container/container_create_linux_test.go:

  • TestCreateWithLabel: migrated; label assertions now use helpers.Capture("inspect", "--format", ...) in the Output callback
  • TestCreateWithMACAddress: migrated; parent Setup creates networks and fetches the host default MAC, per-subtest Setup generates a unique MAC, Output callbacks run start -a to verify MAC propagation
  • TestCreateWithTty: migrated; split into two subtests using start -a as the Command, stderr checked via Errors for the no-TTY case
  • TestCreateFromOCIArchive: migrated; build context created in data.Temp(), OCI archive built and container created in Setup, start --attach returned as the Command
  • TestUsernsMappingCreateCmd: fixed a pre-existing inconsistency where nerdtest.Setup() was called for its side-effect only and the returned *test.Case discarded; now uses the returned case directly. removeUsernsConfig updated to accept tig.T instead of *testing.T.

TestIssue2993 was already fully migrated and is left unchanged.

Test plan

  • go build ./cmd/nerdctl/container/ passes (no compile errors)
  • go test -run ^$ ./cmd/nerdctl/container/ compiles cleanly
  • CI for the migrated tests on Linux (requires a running containerd environment)

Related: #4613

@AkihiroSuda

Copy link
Copy Markdown
Member

@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

Thanks for flagging. The issue: with -t, the container's output goes through a pseudoTTY, so capturing it via start -a is unreliable across containerd versions. Fixed by matching the original test's approach: start without -a in Setup, then logs as the Command. The log driver captures tty output consistently regardless of containerd version.

}
testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
ExitCode: 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use constants defined in the tigron framework for the exit codes. Change them in other test cases as well

@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Replaced all hardcoded exit code literals in Tigron Expected structs with the named constants from the expect package (ExitCodeSuccess, ExitCodeGenericFail). The existing ExitCodeNoCheck usages were already correct.

@haytok haytok self-assigned this May 29, 2026
@haytok haytok self-requested a review May 30, 2026 05:16
@haytok haytok removed their assignment May 30, 2026
return &test.Expected{
ExitCode: expect.ExitCodeSuccess,
Output: func(stdout string, t tig.T) {
helpers.Ensure("start", "-a", data.Identifier())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test for the output of nerdctl start -a is missing.

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", data.Identifier())
helpers.Anyhow("rmi", "-f", data.Labels().Get("imageName"))
helpers.Anyhow("builder", "prune", "--all", "--force")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

base.Cmd("start", "--attach", containerName).AssertOutContains("test-nerdctl-create-from-oci-archive")
testCase.Setup = func(data test.Data, helpers test.Helpers) {
dockerfile := fmt.Sprintf("FROM %s\nCMD [\"echo\", \"%s\"]", testutil.CommonImage, sentinel)
err := os.WriteFile(filepath.Join(data.Temp().Path(), "Dockerfile"), []byte(dockerfile), 0644)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better to use data.Temp().Save(dockerfile, "Dockerfile")

@AkihiroSuda AkihiroSuda added this to the v2.3.2 milestone May 30, 2026
@AkihiroSuda AkihiroSuda requested a review from a team June 7, 2026 16:45
@AkihiroSuda

Copy link
Copy Markdown
Member

@ogulcanaydogan Could you check the review comments from haytok ?

Migrate TestCreateWithLabel, TestCreateWithMACAddress,
TestCreateWithTty, and TestCreateFromOCIArchive from
testutil.NewBase to the Tigron-based nerdtest.Setup pattern.

Also fix TestUsernsMappingCreateCmd which called nerdtest.Setup()
without using its return value; now uses the returned *test.Case
directly.

Helper function removeUsernsConfig updated to accept tig.T instead
of *testing.T to align with the rest of the Tigron-based test
infrastructure.

Part of containerd#4613.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
With -t, the container's output goes through a pseudoTTY. Attaching
via "start -a" does not reliably forward PTY output through Tigron's
subprocess pipe, causing the stty check to fail on certain containerd
versions (e.g. v1.7.30).

Match the original test's approach: start the container without -a,
then read its output via "nerdctl logs" which goes through the log
driver and is always available after the container exits.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
Replace hardcoded exit code literals (0, 1) in Tigron test.Expected
structs with the named constants from the expect package:
ExitCodeSuccess, ExitCodeGenericFail.

Existing ExitCodeNoCheck usages were already correct.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
Capture the start -a output and assert the passed MAC is absent for the
none-network case, instead of only checking the exit code.

Use data.Temp().Save for the Dockerfile instead of os.WriteFile, and drop
the manual builder prune --all --force which the Build requirement
deliberately omits to keep build tests parallelizable.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
@ogulcanaydogan ogulcanaydogan force-pushed the refactor/4613-container-create-linux-tigron branch from 9acaed1 to 819768e Compare June 8, 2026 16:22
@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

@haytok thanks for the review. Addressed all three:

  • The start -a output is now captured and asserted - the none-network case checks the passed MAC is not present, since network none has no interface to apply it to.
  • The Dockerfile now uses data.Temp().Save.
  • Dropped builder prune --all --force from cleanup, matching the Build requirement which leaves it out to keep build tests parallelizable.

Also rebased onto main.

@haytok haytok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@haytok haytok requested a review from AkihiroSuda June 9, 2026 14:28

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 0899187 into containerd:main Jun 10, 2026
106 of 116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants