Skip to content

Commit e08cb35

Browse files
authored
Merge pull request #3960 from apostasie/fix-test
Fix test TestNoneNetworkHostName
2 parents a85ee2b + 6d3c49a commit e08cb35

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

cmd/nerdctl/container/container_run_network_linux_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/containerd/containerd/v2/defaults"
3838
"github.com/containerd/containerd/v2/pkg/netns"
3939
"github.com/containerd/errdefs"
40+
"github.com/containerd/nerdctl/mod/tigron/expect"
4041
"github.com/containerd/nerdctl/mod/tigron/require"
4142
"github.com/containerd/nerdctl/mod/tigron/test"
4243

@@ -924,23 +925,19 @@ func TestNoneNetworkHostName(t *testing.T) {
924925
testCase := &test.Case{
925926
Require: require.Not(require.Windows),
926927
Setup: func(data test.Data, helpers test.Helpers) {
927-
data.Set("containerName1", data.Identifier())
928+
output := helpers.Capture("run", "-d", "--name", data.Identifier(), "--network", "none", testutil.NginxAlpineImage)
929+
assert.Assert(helpers.T(), len(output) > 12, output)
930+
data.Set("hostname", output[:12])
928931
},
929932
Cleanup: func(data test.Data, helpers test.Helpers) {
930933
helpers.Anyhow("rm", "-f", data.Identifier())
931934
},
932935
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
933-
return helpers.Command("run", "-d", "--name", data.Identifier(), "--network", "none", testutil.NginxAlpineImage)
936+
return helpers.Command("exec", data.Identifier(), "cat", "/etc/hostname")
934937
},
935938
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
936939
return &test.Expected{
937-
Output: func(stdout string, info string, t *testing.T) {
938-
hostname := stdout
939-
if len(hostname) > 12 {
940-
hostname = hostname[:12]
941-
}
942-
assert.Assert(t, strings.Compare(strings.TrimSpace(helpers.Capture("exec", data.Identifier(), "cat", "/etc/hostname")), hostname) == 0, info)
943-
},
940+
Output: expect.Equals(data.Get("hostname") + "\n"),
944941
}
945942
},
946943
}

0 commit comments

Comments
 (0)