Skip to content

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

Open
ogulcanaydogan wants to merge 4 commits into
containerd:mainfrom
ogulcanaydogan:refactor/4613-container-create-linux-tigron
Open

refactor: migrate container_create_linux_test.go to nerdtest.Setup#4900
ogulcanaydogan wants to merge 4 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

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>
@AkihiroSuda
Copy link
Copy Markdown
Member

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>
@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

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>
@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.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
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.

3 participants