Skip to content

Commit

Permalink
Enable tests to run on windows
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Oct 21, 2024
1 parent 62d0266 commit 1eebc48
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
30 changes: 10 additions & 20 deletions cmd/nerdctl/image/image_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ func TestRemove(t *testing.T) {
Description: "Remove image with stopped container - without -f",
NoParallel: true,
Require: test.Require(
test.Not(test.Windows),
test.Not(nerdtest.Docker),
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "--name", data.Identifier(), testutil.CommonImage)
helpers.Ensure("run", "--name", data.Identifier(), testutil.CommonImage)
},
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", data.Identifier())
Expand All @@ -65,9 +64,8 @@ func TestRemove(t *testing.T) {
{
Description: "Remove image with stopped container - with -f",
NoParallel: true,
Require: test.Not(test.Windows),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "--name", data.Identifier(), testutil.CommonImage)
helpers.Ensure("run", "--name", data.Identifier(), testutil.CommonImage)
},
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", data.Identifier())
Expand All @@ -87,11 +85,10 @@ func TestRemove(t *testing.T) {
Description: "Remove image with running container - without -f",
NoParallel: true,
Require: test.Require(
test.Not(test.Windows),
test.Not(nerdtest.Docker),
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
},
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", data.Identifier())
Expand All @@ -118,11 +115,10 @@ func TestRemove(t *testing.T) {
// untags `imageName` (left a `<none>` image) without deletion; `docker rmi -rf imageID` fails.
// In both cases, `nerdctl rmi -f` will fail.
Require: test.Require(
test.Not(test.Windows),
test.Not(nerdtest.Docker),
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
},
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", data.Identifier())
Expand All @@ -143,9 +139,8 @@ func TestRemove(t *testing.T) {
{
Description: "Remove image with created container - without -f",
NoParallel: true,
Require: test.Not(test.Windows),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("create", "--pull", "always", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("create", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
},
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", data.Identifier())
Expand All @@ -164,10 +159,9 @@ func TestRemove(t *testing.T) {
{
Description: "Remove image with created container - with -f",
NoParallel: true,
Require: test.Not(test.Windows),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("pull", "--quiet", testutil.NginxAlpineImage)
helpers.Ensure("create", "--pull", "always", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("create", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("rmi", testutil.NginxAlpineImage)
},
Cleanup: func(data test.Data, helpers test.Helpers) {
Expand All @@ -192,12 +186,11 @@ func TestRemove(t *testing.T) {
Description: "Remove image with paused container - without -f",
NoParallel: true,
Require: test.Require(
test.Not(test.Windows),
test.Not(nerdtest.Docker),
nerdtest.CGroup,
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("pause", data.Identifier())
},
Cleanup: func(data test.Data, helpers test.Helpers) {
Expand All @@ -220,7 +213,6 @@ func TestRemove(t *testing.T) {
Description: "Remove image with paused container - with -f",
NoParallel: true,
Require: test.Require(
test.Not(test.Windows),
nerdtest.CGroup,
// FIXME: nerdctl is broken
// https://github.com/containerd/nerdctl/issues/3454
Expand All @@ -230,7 +222,7 @@ func TestRemove(t *testing.T) {
test.Not(nerdtest.Docker),
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("pause", data.Identifier())
},
Cleanup: func(data test.Data, helpers test.Helpers) {
Expand All @@ -253,11 +245,10 @@ func TestRemove(t *testing.T) {
Description: "Remove image with killed container - without -f",
NoParallel: true,
Require: test.Require(
test.Not(test.Windows),
test.Not(nerdtest.Docker),
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("kill", data.Identifier())
},
Cleanup: func(data test.Data, helpers test.Helpers) {
Expand All @@ -279,9 +270,8 @@ func TestRemove(t *testing.T) {
{
Description: "Remove image with killed container - with -f",
NoParallel: true,
Require: test.Not(test.Windows),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("run", "--pull", "always", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("run", "-d", "--name", data.Identifier(), testutil.CommonImage, "sleep", "infinity")
helpers.Ensure("kill", data.Identifier())
},
Cleanup: func(data test.Data, helpers test.Helpers) {
Expand Down
6 changes: 2 additions & 4 deletions cmd/nerdctl/issues/main_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ func TestMain(m *testing.M) {
func TestIssue108(t *testing.T) {
testCase := nerdtest.Setup()

testCase.Require = test.Linux

testCase.SubTests = []*test.Case{
{
Description: "-it --net=host",
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
cmd := helpers.Command("run", "-it", "--rm", "--net=host", testutil.AlpineImage, "echo", "this was always working")
cmd := helpers.Command("run", "-it", "--rm", "--net=host", testutil.CommonImage, "echo", "this was always working")
cmd.WithPseudoTTY()
return cmd
},
Expand All @@ -48,7 +46,7 @@ func TestIssue108(t *testing.T) {
{
Description: "--net=host -it",
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
cmd := helpers.Command("run", "--rm", "--net=host", "-it", testutil.AlpineImage, "echo", "this was not working due to issue #108")
cmd := helpers.Command("run", "--rm", "--net=host", "-it", testutil.CommonImage, "echo", "this was not working due to issue #108")
cmd.WithPseudoTTY()
return cmd
},
Expand Down
32 changes: 25 additions & 7 deletions cmd/nerdctl/network/network_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func TestNetworkInspect(t *testing.T) {
testIPRange = "10.24.24.0/25"
)

testCase.Setup = func(data test.Data, helpers test.Helpers) {
helpers.Ensure("network", "create", data.Identifier("basenet"))
data.Set("basenet", data.Identifier("basenet"))
}

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("network", "rm", data.Identifier("basenet"))
}

testCase.SubTests = []*test.Case{
{
Description: "non existent network",
Expand Down Expand Up @@ -87,6 +96,18 @@ func TestNetworkInspect(t *testing.T) {
assert.Equal(t, dc[0].Name, "bridge")
}),
},
{
Description: "nat",
Require: test.Windows,
Command: test.Command("network", "inspect", "nat"),
Expected: test.Expects(0, nil, func(stdout string, info string, t *testing.T) {
var dc []dockercompat.Network
err := json.Unmarshal([]byte(stdout), &dc)
assert.NilError(t, err, "Unable to unmarshal output\n"+info)
assert.Equal(t, 1, len(dc), "Unexpectedly got multiple results\n"+info)
assert.Equal(t, dc[0].Name, "nat")
}),
},
{
Description: "custom",
Setup: func(data test.Data, helpers test.Helpers) {
Expand All @@ -106,9 +127,8 @@ func TestNetworkInspect(t *testing.T) {
},
{
Description: "match exact id",
Require: test.Not(test.Windows),
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
id := strings.TrimSpace(helpers.Capture("network", "inspect", "bridge", "--format", "{{ .Id }}"))
id := strings.TrimSpace(helpers.Capture("network", "inspect", data.Get("basenet"), "--format", "{{ .Id }}"))
return helpers.Command("network", "inspect", id)
},
Expected: test.Expects(0, nil, func(stdout string, info string, t *testing.T) {
Expand All @@ -121,9 +141,8 @@ func TestNetworkInspect(t *testing.T) {
},
{
Description: "match part of id",
Require: test.Not(test.Windows),
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
id := strings.TrimSpace(helpers.Capture("network", "inspect", "bridge", "--format", "{{ .Id }}"))
id := strings.TrimSpace(helpers.Capture("network", "inspect", data.Get("basenet"), "--format", "{{ .Id }}"))
return helpers.Command("network", "inspect", id[0:25])
},
Expected: test.Expects(0, nil, func(stdout string, info string, t *testing.T) {
Expand All @@ -136,14 +155,13 @@ func TestNetworkInspect(t *testing.T) {
},
{
Description: "using another net short id",
Require: test.Not(test.Windows),
Setup: func(data test.Data, helpers test.Helpers) {
id := strings.TrimSpace(helpers.Capture("network", "inspect", "bridge", "--format", "{{ .Id }}"))
id := strings.TrimSpace(helpers.Capture("network", "inspect", data.Get("basenet"), "--format", "{{ .Id }}"))
helpers.Ensure("network", "create", id[0:12])
data.Set("netname", id[0:12])
},
Cleanup: func(data test.Data, helpers test.Helpers) {
id := strings.TrimSpace(helpers.Capture("network", "inspect", "bridge", "--format", "{{ .Id }}"))
id := strings.TrimSpace(helpers.Capture("network", "inspect", data.Get("basenet"), "--format", "{{ .Id }}"))
helpers.Anyhow("network", "remove", id[0:12])
},
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
Expand Down

0 comments on commit 1eebc48

Please sign in to comment.