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 22, 2024
1 parent 2b3624e commit 23e58ba
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 @@ -43,11 +43,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 @@ -68,9 +67,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 @@ -90,11 +88,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 @@ -121,11 +118,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 @@ -146,9 +142,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 @@ -167,10 +162,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 @@ -195,12 +189,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 @@ -223,7 +216,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 @@ -233,7 +225,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 @@ -256,11 +248,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 @@ -282,9 +273,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 23e58ba

Please sign in to comment.