Skip to content

Commit

Permalink
Merge pull request #3624 from apostasie/series-13
Browse files Browse the repository at this point in the history
Enable more tests to run on windows
  • Loading branch information
AkihiroSuda authored Nov 4, 2024
2 parents 2b0550f + dc2c7b9 commit f12f7fe
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 35 deletions.
1 change: 1 addition & 0 deletions cmd/nerdctl/image/image_convert_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
1 change: 1 addition & 0 deletions cmd/nerdctl/image/image_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions cmd/nerdctl/image/image_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
},
Expand All @@ -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) {
Expand Down Expand Up @@ -121,7 +118,6 @@ 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) {
Expand All @@ -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)
},
Expand All @@ -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)
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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())
Expand Down
1 change: 1 addition & 0 deletions cmd/nerdctl/image/image_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions cmd/nerdctl/issues/main_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
78 changes: 55 additions & 23 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,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"))
Expand All @@ -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,
Expand Down

0 comments on commit f12f7fe

Please sign in to comment.