From 465b52caab645032ed0c599c09ea4cea196c4b90 Mon Sep 17 00:00:00 2001 From: apostasie Date: Thu, 31 Oct 2024 12:55:25 +0100 Subject: [PATCH 1/4] Enable image_remove tests to run on windows Signed-off-by: apostasie --- cmd/nerdctl/image/image_remove_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cmd/nerdctl/image/image_remove_test.go b/cmd/nerdctl/image/image_remove_test.go index f94b0e71e57..5771ac4c07c 100644 --- a/cmd/nerdctl/image/image_remove_test.go +++ b/cmd/nerdctl/image/image_remove_test.go @@ -43,7 +43,6 @@ 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) { @@ -68,7 +67,6 @@ 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) }, @@ -90,7 +88,6 @@ 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) { @@ -121,7 +118,6 @@ 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) { @@ -146,7 +142,6 @@ 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", nerdtest.Infinity) }, @@ -169,7 +164,6 @@ 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", nerdtest.Infinity) @@ -197,7 +191,6 @@ 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, ), @@ -225,7 +218,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 @@ -258,7 +250,6 @@ 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) { @@ -284,7 +275,6 @@ 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", nerdtest.Infinity) helpers.Ensure("kill", data.Identifier()) From 4623930836c23816cad9ae320494528ceb2021c3 Mon Sep 17 00:00:00 2001 From: apostasie Date: Thu, 31 Oct 2024 13:55:45 +0100 Subject: [PATCH 2/4] Enable issues tests to run on Windows Signed-off-by: apostasie --- cmd/nerdctl/issues/main_linux_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/nerdctl/issues/main_linux_test.go b/cmd/nerdctl/issues/main_linux_test.go index c67fa8eb1c1..a1af21d8ff5 100644 --- a/cmd/nerdctl/issues/main_linux_test.go +++ b/cmd/nerdctl/issues/main_linux_test.go @@ -33,8 +33,6 @@ 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", From 93189e13fa0db738ded2c743854520e40c1ca7e6 Mon Sep 17 00:00:00 2001 From: apostasie Date: Thu, 31 Oct 2024 13:59:03 +0100 Subject: [PATCH 3/4] Annotate non-windows compatible image tests Signed-off-by: apostasie --- cmd/nerdctl/image/image_convert_linux_test.go | 1 + cmd/nerdctl/image/image_inspect_test.go | 1 + cmd/nerdctl/image/image_save_test.go | 1 + 3 files changed, 3 insertions(+) diff --git a/cmd/nerdctl/image/image_convert_linux_test.go b/cmd/nerdctl/image/image_convert_linux_test.go index 3a202a818ef..6968e5ab7a5 100644 --- a/cmd/nerdctl/image/image_convert_linux_test.go +++ b/cmd/nerdctl/image/image_convert_linux_test.go @@ -31,6 +31,7 @@ func TestImageConvert(t *testing.T) { testCase := &test.Case{ Require: test.Require( + // FIXME: windows does not support stargz test.Not(test.Windows), test.Not(nerdtest.Docker), ), diff --git a/cmd/nerdctl/image/image_inspect_test.go b/cmd/nerdctl/image/image_inspect_test.go index 816b163abbd..4ac86996bd8 100644 --- a/cmd/nerdctl/image/image_inspect_test.go +++ b/cmd/nerdctl/image/image_inspect_test.go @@ -87,6 +87,7 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) { testCase := &test.Case{ Require: test.Require( test.Not(nerdtest.Docker), + // FIXME: this test depends on hub images that do not have windows versions test.Not(test.Windows), // We need a clean slate nerdtest.Private, diff --git a/cmd/nerdctl/image/image_save_test.go b/cmd/nerdctl/image/image_save_test.go index 90aa59909d2..3fcb9b8ceef 100644 --- a/cmd/nerdctl/image/image_save_test.go +++ b/cmd/nerdctl/image/image_save_test.go @@ -35,6 +35,7 @@ func TestSaveContent(t *testing.T) { nerdtest.Setup() testCase := &test.Case{ + // FIXME: move to busybox for windows? Require: test.Not(test.Windows), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("pull", "--quiet", testutil.CommonImage) From dc2c7b93f7a947463f91bcc6dd0001bd56794371 Mon Sep 17 00:00:00 2001 From: apostasie Date: Thu, 31 Oct 2024 14:02:24 +0100 Subject: [PATCH 4/4] Enable network_inspect tests to run on windows Signed-off-by: apostasie --- cmd/nerdctl/network/network_inspect_test.go | 78 +++++++++++++++------ 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/cmd/nerdctl/network/network_inspect_test.go b/cmd/nerdctl/network/network_inspect_test.go index f7ce5356dca..d493db498fd 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,45 +127,56 @@ func TestNetworkInspect(t *testing.T) { }, { Description: "match exact id", - Require: test.Not(test.Windows), + // See notes below 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) { - 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, "bridge") - }), + Expected: func(data test.Data, helpers test.Helpers) *test.Expected { + return &test.Expected{ + Output: 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, data.Get("basenet")) + }, + } + }, }, { Description: "match part of id", - Require: test.Not(test.Windows), + // FIXME: for windows, network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} MAY fail here + // This is bizarre, as it is working in the match exact id test - and there does not seem to be a particular reason for that + 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) { - 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, "bridge") - }), + Expected: func(data test.Data, helpers test.Helpers) *test.Expected { + return &test.Expected{ + Output: 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, data.Get("basenet")) + }, + } + }, }, { Description: "using another net short id", - Require: test.Not(test.Windows), + // FIXME: for windows, network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} MAY fail here + // This is bizarre, as it is working in the match exact id test - and there does not seem to be a particular reason for that + 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 }}")) - helpers.Anyhow("network", "remove", id[0:12]) + helpers.Anyhow("network", "remove", data.Get("netname")) }, Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("network", "inspect", data.Get("netname")) @@ -163,7 +195,7 @@ func TestNetworkInspect(t *testing.T) { }, { Description: "basic", - // IPAMConfig is not implemented on Windows yet + // FIXME: IPAMConfig is not implemented on Windows yet Require: test.Not(test.Windows), Setup: func(data test.Data, helpers test.Helpers) { helpers.Ensure("network", "create", "--label", "tag=testNetwork", "--subnet", testSubnet,