Skip to content

Commit a1ad17d

Browse files
refactor: use named constants for port and exit code in tests
Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
1 parent cf2726d commit a1ad17d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

cmd/nerdctl/container/multi_platform_linux_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import (
3333
"github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil"
3434
)
3535

36+
// randomPort asks the registry helpers to acquire a free port automatically.
37+
const randomPort = 0
38+
3639
// requireMultiPlatformExec skips the test when the host cannot execute
3740
// linux/amd64, linux/arm64 and linux/arm/v7 images (e.g. no binfmt_misc).
3841
var requireMultiPlatformExec = &test.Requirement{
@@ -63,7 +66,8 @@ func assertMultiPlatformRun(helpers test.Helpers, image string) {
6366
helpers.T().Log(fmt.Sprintf("Testing platform %q (%q)", plat, expectedUnameM))
6467
helpers.Command("run", "--rm", "--platform="+plat, image, "uname", "-m").
6568
Run(&test.Expected{
66-
Output: expect.Equals(expectedUnameM + "\n"),
69+
ExitCode: expect.ExitCodeSuccess,
70+
Output: expect.Equals(expectedUnameM + "\n"),
6771
})
6872
}
6973
}
@@ -105,7 +109,7 @@ func TestMultiPlatformBuildPush(t *testing.T) {
105109
var reg *registry.Server
106110

107111
testCase.Setup = func(data test.Data, helpers test.Helpers) {
108-
reg = nerdtest.RegistryWithNoAuth(data, helpers, 0 /* random port */, false)
112+
reg = nerdtest.RegistryWithNoAuth(data, helpers, randomPort, false)
109113
reg.Setup(data, helpers)
110114
imageName := fmt.Sprintf("localhost:%d/%s:latest", reg.Port, data.Identifier())
111115
data.Labels().Set("image", imageName)
@@ -151,7 +155,7 @@ func TestMultiPlatformBuildPushNoRun(t *testing.T) {
151155
var reg *registry.Server
152156

153157
testCase.Setup = func(data test.Data, helpers test.Helpers) {
154-
reg = nerdtest.RegistryWithNoAuth(data, helpers, 0 /* random port */, false)
158+
reg = nerdtest.RegistryWithNoAuth(data, helpers, randomPort, false)
155159
reg.Setup(data, helpers)
156160
imageName := fmt.Sprintf("localhost:%d/%s:latest", reg.Port, data.Identifier())
157161
data.Labels().Set("image", imageName)
@@ -196,7 +200,7 @@ func TestMultiPlatformPullPushAllPlatforms(t *testing.T) {
196200
var reg *registry.Server
197201

198202
testCase.Setup = func(data test.Data, helpers test.Helpers) {
199-
reg = nerdtest.RegistryWithNoAuth(data, helpers, 0 /* random port */, false)
203+
reg = nerdtest.RegistryWithNoAuth(data, helpers, randomPort, false)
200204
reg.Setup(data, helpers)
201205
pushImageName := fmt.Sprintf("localhost:%d/%s:latest", reg.Port, data.Identifier())
202206
data.Labels().Set("image", pushImageName)

0 commit comments

Comments
 (0)