@@ -38,6 +38,15 @@ func TestNetworkInspect(t *testing.T) {
3838 testIPRange = "10.24.24.0/25"
3939 )
4040
41+ testCase .Setup = func (data test.Data , helpers test.Helpers ) {
42+ helpers .Ensure ("network" , "create" , data .Identifier ("basenet" ))
43+ data .Set ("basenet" , data .Identifier ("basenet" ))
44+ }
45+
46+ testCase .Cleanup = func (data test.Data , helpers test.Helpers ) {
47+ helpers .Anyhow ("network" , "rm" , data .Identifier ("basenet" ))
48+ }
49+
4150 testCase .SubTests = []* test.Case {
4251 {
4352 Description : "non existent network" ,
@@ -87,6 +96,18 @@ func TestNetworkInspect(t *testing.T) {
8796 assert .Equal (t , dc [0 ].Name , "bridge" )
8897 }),
8998 },
99+ {
100+ Description : "nat" ,
101+ Require : test .Windows ,
102+ Command : test .Command ("network" , "inspect" , "nat" ),
103+ Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
104+ var dc []dockercompat.Network
105+ err := json .Unmarshal ([]byte (stdout ), & dc )
106+ assert .NilError (t , err , "Unable to unmarshal output\n " + info )
107+ assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
108+ assert .Equal (t , dc [0 ].Name , "nat" )
109+ }),
110+ },
90111 {
91112 Description : "custom" ,
92113 Setup : func (data test.Data , helpers test.Helpers ) {
@@ -106,45 +127,58 @@ func TestNetworkInspect(t *testing.T) {
106127 },
107128 {
108129 Description : "match exact id" ,
109- Require : test . Not ( test . Windows ) ,
130+ NoParallel : true ,
110131 Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
111- id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , "bridge" , "--format" , "{{ .Id }}" ))
132+ id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , data . Get ( "basenet" ) , "--format" , "{{ .Id }}" ))
112133 return helpers .Command ("network" , "inspect" , id )
113134 },
114- Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
115- var dc []dockercompat.Network
116- err := json .Unmarshal ([]byte (stdout ), & dc )
117- assert .NilError (t , err , "Unable to unmarshal output\n " + info )
118- assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
119- assert .Equal (t , dc [0 ].Name , "bridge" )
120- }),
135+ Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
136+ return & test.Expected {
137+ Output : func (stdout string , info string , t * testing.T ) {
138+ var dc []dockercompat.Network
139+ err := json .Unmarshal ([]byte (stdout ), & dc )
140+ assert .NilError (t , err , "Unable to unmarshal output\n " + info )
141+ assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
142+ assert .Equal (t , dc [0 ].Name , data .Get ("basenet" ))
143+ },
144+ }
145+ },
121146 },
122147 {
123148 Description : "match part of id" ,
124- Require : test .Not (test .Windows ),
149+ // FIXME: network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} is failing here
150+ // 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
151+ // Is it the concurrency?
152+ NoParallel : true ,
125153 Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
126- id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , "bridge" , "--format" , "{{ .Id }}" ))
154+ id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , data . Get ( "basenet" ) , "--format" , "{{ .Id }}" ))
127155 return helpers .Command ("network" , "inspect" , id [0 :25 ])
128156 },
129- Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
130- var dc []dockercompat.Network
131- err := json .Unmarshal ([]byte (stdout ), & dc )
132- assert .NilError (t , err , "Unable to unmarshal output\n " + info )
133- assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
134- assert .Equal (t , dc [0 ].Name , "bridge" )
135- }),
157+ Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
158+ return & test.Expected {
159+ Output : func (stdout string , info string , t * testing.T ) {
160+ var dc []dockercompat.Network
161+ err := json .Unmarshal ([]byte (stdout ), & dc )
162+ assert .NilError (t , err , "Unable to unmarshal output\n " + info )
163+ assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
164+ assert .Equal (t , dc [0 ].Name , data .Get ("basenet" ))
165+ },
166+ }
167+ },
136168 },
137169 {
138170 Description : "using another net short id" ,
139- Require : test .Not (test .Windows ),
171+ // FIXME: network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} is failing here
172+ // 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
173+ // Is it the concurrency?
174+ NoParallel : true ,
140175 Setup : func (data test.Data , helpers test.Helpers ) {
141- id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , "bridge" , "--format" , "{{ .Id }}" ))
176+ id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , data . Get ( "basenet" ) , "--format" , "{{ .Id }}" ))
142177 helpers .Ensure ("network" , "create" , id [0 :12 ])
143178 data .Set ("netname" , id [0 :12 ])
144179 },
145180 Cleanup : func (data test.Data , helpers test.Helpers ) {
146- id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , "bridge" , "--format" , "{{ .Id }}" ))
147- helpers .Anyhow ("network" , "remove" , id [0 :12 ])
181+ helpers .Anyhow ("network" , "remove" , data .Get ("netname" ))
148182 },
149183 Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
150184 return helpers .Command ("network" , "inspect" , data .Get ("netname" ))
@@ -163,7 +197,7 @@ func TestNetworkInspect(t *testing.T) {
163197 },
164198 {
165199 Description : "basic" ,
166- // IPAMConfig is not implemented on Windows yet
200+ // FIXME: IPAMConfig is not implemented on Windows yet
167201 Require : test .Not (test .Windows ),
168202 Setup : func (data test.Data , helpers test.Helpers ) {
169203 helpers .Ensure ("network" , "create" , "--label" , "tag=testNetwork" , "--subnet" , testSubnet ,
0 commit comments