Skip to content

Commit fee517a

Browse files
committed
test: add one test case to TestNetworkInspect in network_inspect_test.go
Suppose that a `container A` is running in the network `some-network-as-well`. In this case, this commit adds a test to ensure that `container A` isn't displayed in the `Containers` section of the output of `nerdctl network inspect some-network`. Signed-off-by: Hayato Kiwata <[email protected]>
1 parent 3086d71 commit fee517a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cmd/nerdctl/network/network_inspect_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,32 @@ func TestNetworkInspect(t *testing.T) {
350350
}
351351
},
352352
},
353+
{
354+
Description: "Display only containers attached to the specific network",
355+
Setup: func(data test.Data, helpers test.Helpers) {
356+
helpers.Ensure("network", "create", data.Identifier("some-network"))
357+
helpers.Ensure("network", "create", data.Identifier("some-network-as-well"))
358+
359+
helpers.Ensure("run", "-d", "--name", data.Identifier(), "--network", data.Identifier("some-network-as-well"), testutil.CommonImage, "sleep", nerdtest.Infinity)
360+
},
361+
Cleanup: func(data test.Data, helpers test.Helpers) {
362+
helpers.Anyhow("rm", "-f", data.Identifier())
363+
helpers.Anyhow("network", "remove", data.Identifier("some-network"))
364+
helpers.Anyhow("network", "remove", data.Identifier("some-network-as-well"))
365+
},
366+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
367+
return helpers.Command("network", "inspect", data.Identifier("some-network"))
368+
},
369+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
370+
return &test.Expected{
371+
Output: expect.JSON([]dockercompat.Network{}, func(dc []dockercompat.Network, info string, t tig.T) {
372+
assert.Equal(t, 1, len(dc), "Unexpectedly got multiple results\n"+info)
373+
assert.Equal(t, dc[0].Name, data.Identifier("some-network"))
374+
assert.Equal(t, 0, len(dc[0].Containers), "Expected no containers as per configuration, but got multiple.")
375+
}),
376+
}
377+
},
378+
},
353379
}
354380

355381
testCase.Run(t)

0 commit comments

Comments
 (0)