@@ -28,6 +28,7 @@ import (
28
28
"github.com/containerd/nerdctl/mod/tigron/expect"
29
29
"github.com/containerd/nerdctl/mod/tigron/require"
30
30
"github.com/containerd/nerdctl/mod/tigron/test"
31
+ "github.com/containerd/nerdctl/mod/tigron/tig"
31
32
32
33
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
33
34
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -323,33 +324,29 @@ func TestNetworkInspect(t *testing.T) {
323
324
{
324
325
Description : "Display containers belonging to multiple networks in the output of nerdctl network inspect" ,
325
326
Setup : func (data test.Data , helpers test.Helpers ) {
326
- helpers .Ensure ("network" , "create" , data .Identifier ("nginx- network-1" ))
327
- helpers .Ensure ("network" , "create" , data .Identifier ("nginx- network-2" ))
327
+ helpers .Ensure ("network" , "create" , data .Identifier ("network-1" ))
328
+ helpers .Ensure ("network" , "create" , data .Identifier ("network-2" ))
328
329
329
- helpers .Ensure ("run" , "-d" , "--name" , data .Identifier (), "--network" , data .Identifier ("nginx- network-1" ), "--network" , data .Identifier ("nginx- network-2" ), testutil .NginxAlpineImage )
330
+ containerID := helpers .Capture ("run" , "-d" , "--name" , data .Identifier (), "--network" , data .Identifier ("network-1" ), "--network" , data .Identifier ("network-2" ), testutil .CommonImage , "sleep" , nerdtest . Infinity )
330
331
331
- data .Labels ().Set ("containerID" , strings .Trim (helpers . Capture ( "inspect" , data . Identifier (), "--format" , "{{.Id}}" ) , "\n " ))
332
+ data .Labels ().Set ("containerID" , strings .Trim (containerID , "\n " ))
332
333
},
333
334
Cleanup : func (data test.Data , helpers test.Helpers ) {
334
335
helpers .Anyhow ("rm" , "-f" , data .Identifier ())
335
- helpers .Anyhow ("network" , "remove" , data .Identifier ("nginx- network-1" ))
336
- helpers .Anyhow ("network" , "remove" , data .Identifier ("nginx- network-2" ))
336
+ helpers .Anyhow ("network" , "remove" , data .Identifier ("network-1" ))
337
+ helpers .Anyhow ("network" , "remove" , data .Identifier ("network-2" ))
337
338
},
338
339
Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
339
- return helpers .Command ("network" , "inspect" , data .Identifier ("nginx- network-1" ))
340
+ return helpers .Command ("network" , "inspect" , data .Identifier ("network-1" ))
340
341
},
341
342
Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
342
343
return & test.Expected {
343
- Output : func (stdout string , info string , t * testing.T ) {
344
- var dc []dockercompat.Network
345
- err := json .Unmarshal ([]byte (stdout ), & dc )
346
-
347
- assert .NilError (t , err , "Unable to unmarshal output\n " + info )
344
+ Output : expect .JSON ([]dockercompat.Network {}, func (dc []dockercompat.Network , info string , t tig.T ) {
348
345
assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
349
- assert .Equal (t , dc [0 ].Name , data .Identifier ("nginx- network-1" ))
346
+ assert .Equal (t , dc [0 ].Name , data .Identifier ("network-1" ))
350
347
assert .Equal (t , 1 , len (dc [0 ].Containers ), "Expected a single container as per configuration, but got multiple." )
351
348
assert .Equal (t , data .Identifier (), dc [0 ].Containers [data .Labels ().Get ("containerID" )].Name )
352
- },
349
+ }) ,
353
350
}
354
351
},
355
352
},
0 commit comments