diff --git a/cmd/nerdctl/image/image_remove_test.go b/cmd/nerdctl/image/image_remove_test.go index 5e48372332c..70c689184d1 100644 --- a/cmd/nerdctl/image/image_remove_test.go +++ b/cmd/nerdctl/image/image_remove_test.go @@ -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()) @@ -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()) @@ -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()) @@ -121,11 +118,10 @@ func TestRemove(t *testing.T) { // untags `imageName` (left a `` 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()) @@ -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()) @@ -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) { @@ -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) { @@ -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 @@ -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) { @@ -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) { @@ -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) { diff --git a/cmd/nerdctl/issues/main_linux_test.go b/cmd/nerdctl/issues/main_linux_test.go index e6735f02c14..a1af21d8ff5 100644 --- a/cmd/nerdctl/issues/main_linux_test.go +++ b/cmd/nerdctl/issues/main_linux_test.go @@ -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 }, @@ -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 }, diff --git a/cmd/nerdctl/network/network_inspect_test.go b/cmd/nerdctl/network/network_inspect_test.go index 64d5631e2bf..593f7184243 100644 --- a/cmd/nerdctl/network/network_inspect_test.go +++ b/cmd/nerdctl/network/network_inspect_test.go @@ -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", @@ -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) { @@ -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) { @@ -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) { @@ -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 {