@@ -38,6 +38,15 @@ func TestNetworkInspect(t *testing.T) {
38
38
testIPRange = "10.24.24.0/25"
39
39
)
40
40
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
+
41
50
testCase .SubTests = []* test.Case {
42
51
{
43
52
Description : "non existent network" ,
@@ -87,6 +96,18 @@ func TestNetworkInspect(t *testing.T) {
87
96
assert .Equal (t , dc [0 ].Name , "bridge" )
88
97
}),
89
98
},
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
+ },
90
111
{
91
112
Description : "custom" ,
92
113
Setup : func (data test.Data , helpers test.Helpers ) {
@@ -106,45 +127,56 @@ func TestNetworkInspect(t *testing.T) {
106
127
},
107
128
{
108
129
Description : "match exact id" ,
109
- Require : test . Not ( test . Windows ),
130
+ // See notes below
110
131
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 }}" ))
112
133
return helpers .Command ("network" , "inspect" , id )
113
134
},
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
+ },
121
146
},
122
147
{
123
148
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 ),
125
152
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 }}" ))
127
154
return helpers .Command ("network" , "inspect" , id [0 :25 ])
128
155
},
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
+ },
136
167
},
137
168
{
138
169
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 ),
140
173
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 }}" ))
142
175
helpers .Ensure ("network" , "create" , id [0 :12 ])
143
176
data .Set ("netname" , id [0 :12 ])
144
177
},
145
178
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" ))
148
180
},
149
181
Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
150
182
return helpers .Command ("network" , "inspect" , data .Get ("netname" ))
@@ -163,7 +195,7 @@ func TestNetworkInspect(t *testing.T) {
163
195
},
164
196
{
165
197
Description : "basic" ,
166
- // IPAMConfig is not implemented on Windows yet
198
+ // FIXME: IPAMConfig is not implemented on Windows yet
167
199
Require : test .Not (test .Windows ),
168
200
Setup : func (data test.Data , helpers test.Helpers ) {
169
201
helpers .Ensure ("network" , "create" , "--label" , "tag=testNetwork" , "--subnet" , testSubnet ,
0 commit comments