Skip to content

Commit

Permalink
Enable network_inspect tests to run on windows
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
  • Loading branch information
apostasie committed Nov 2, 2024
1 parent 93189e1 commit b7e83b3
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 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,49 @@ 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) {
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),
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),
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 +188,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 b7e83b3

Please sign in to comment.