refactor: migrate container_create_linux_test.go to nerdtest.Setup#4900
Conversation
|
TestCreateWithTty seems failing |
|
Thanks for flagging. The issue: with |
| } | ||
| testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected { | ||
| return &test.Expected{ | ||
| ExitCode: 0, |
There was a problem hiding this comment.
Use constants defined in the tigron framework for the exit codes. Change them in other test cases as well
|
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. |
| return &test.Expected{ | ||
| ExitCode: expect.ExitCodeSuccess, | ||
| Output: func(stdout string, t tig.T) { | ||
| helpers.Ensure("start", "-a", data.Identifier()) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
We shouldn't write builder prune -all --force.
https://github.com/containerd/nerdctl/blob/main/pkg/testutil/nerdtest/requirements.go#L376C2-L383C4
| 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) |
There was a problem hiding this comment.
Better to use data.Temp().Save(dockerfile, "Dockerfile")
|
@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>
9acaed1 to
819768e
Compare
|
@haytok thanks for the review. Addressed all three:
Also rebased onto main. |
Summary
Continues the Tigron migration work tracked in #4613. Migrates the remaining
testutil.NewBase-based tests incmd/nerdctl/container/container_create_linux_test.go:TestCreateWithLabel: migrated; label assertions now usehelpers.Capture("inspect", "--format", ...)in theOutputcallbackTestCreateWithMACAddress: migrated; parentSetupcreates networks and fetches the host default MAC, per-subtestSetupgenerates a unique MAC,Outputcallbacks runstart -ato verify MAC propagationTestCreateWithTty: migrated; split into two subtests usingstart -aas theCommand, stderr checked viaErrorsfor the no-TTY caseTestCreateFromOCIArchive: migrated; build context created indata.Temp(), OCI archive built and container created inSetup,start --attachreturned as theCommandTestUsernsMappingCreateCmd: fixed a pre-existing inconsistency wherenerdtest.Setup()was called for its side-effect only and the returned*test.Casediscarded; now uses the returned case directly.removeUsernsConfigupdated to accepttig.Tinstead of*testing.T.TestIssue2993was 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 cleanlyRelated: #4613