@@ -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,56 @@ func TestNetworkInspect(t *testing.T) {
106127 },
107128 {
108129 Description : "match exact id" ,
109- Require : test . Not ( test . Windows ),
130+ // See notes below
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: for windows, network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} MAY fail 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+ Require : test .Not (test .Windows ),
125152 Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
126- id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , "bridge" , "--format" , "{{ .Id }}" ))
153+ id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , data . Get ( "basenet" ) , "--format" , "{{ .Id }}" ))
127154 return helpers .Command ("network" , "inspect" , id [0 :25 ])
128155 },
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- }),
156+ Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
157+ return & test.Expected {
158+ Output : func (stdout string , info string , t * testing.T ) {
159+ var dc []dockercompat.Network
160+ err := json .Unmarshal ([]byte (stdout ), & dc )
161+ assert .NilError (t , err , "Unable to unmarshal output\n " + info )
162+ assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
163+ assert .Equal (t , dc [0 ].Name , data .Get ("basenet" ))
164+ },
165+ }
166+ },
136167 },
137168 {
138169 Description : "using another net short id" ,
139- Require : test .Not (test .Windows ),
170+ // FIXME: for windows, network inspect testnetworkinspect-basenet-468cf999 --format {{ .Id }} MAY fail here
171+ // 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
172+ Require : test .Not (test .Windows ),
140173 Setup : func (data test.Data , helpers test.Helpers ) {
141- id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , "bridge" , "--format" , "{{ .Id }}" ))
174+ id := strings .TrimSpace (helpers .Capture ("network" , "inspect" , data . Get ( "basenet" ) , "--format" , "{{ .Id }}" ))
142175 helpers .Ensure ("network" , "create" , id [0 :12 ])
143176 data .Set ("netname" , id [0 :12 ])
144177 },
145178 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 ])
179+ helpers .Anyhow ("network" , "remove" , data .Get ("netname" ))
148180 },
149181 Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
150182 return helpers .Command ("network" , "inspect" , data .Get ("netname" ))
@@ -163,7 +195,7 @@ func TestNetworkInspect(t *testing.T) {
163195 },
164196 {
165197 Description : "basic" ,
166- // IPAMConfig is not implemented on Windows yet
198+ // FIXME: IPAMConfig is not implemented on Windows yet
167199 Require : test .Not (test .Windows ),
168200 Setup : func (data test.Data , helpers test.Helpers ) {
169201 helpers .Ensure ("network" , "create" , "--label" , "tag=testNetwork" , "--subnet" , testSubnet ,
0 commit comments