@@ -201,42 +201,88 @@ func TestParsePortSpecFull(t *testing.T) {
201201}
202202
203203func TestPartPortSpecIPV6 (t * testing.T ) {
204- portMappings , err := ParsePortSpec ("[2001:4860:0:2001::68]::333" )
205- if err != nil {
206- t .Fatalf ("expected nil error, got: %v" , err )
204+ type test struct {
205+ name string
206+ spec string
207+ expected []PortMapping
207208 }
208-
209- expected := []PortMapping {
209+ cases := []test {
210210 {
211- Port : "333/tcp" ,
212- Binding : PortBinding {
213- HostIP : "2001:4860:0:2001::68" ,
214- HostPort : "" ,
211+ name : "square angled IPV6 without host port" ,
212+ spec : "[2001:4860:0:2001::68]::333" ,
213+ expected : []PortMapping {
214+ {
215+ Port : "333/tcp" ,
216+ Binding : PortBinding {
217+ HostIP : "2001:4860:0:2001::68" ,
218+ HostPort : "" ,
219+ },
220+ },
215221 },
216222 },
217- }
218- if ! reflect .DeepEqual (expected , portMappings ) {
219- t .Fatalf ("wrong port mappings: got=%v, want=%v" , portMappings , expected )
220- }
221- }
222-
223- func TestPartPortSpecIPV6WithHostPort (t * testing.T ) {
224- portMappings , err := ParsePortSpec ("[::1]:80:80" )
225- if err != nil {
226- t .Fatalf ("expected nil error, got: %v" , err )
227- }
228-
229- expected := []PortMapping {
230223 {
231- Port : "80/tcp" ,
232- Binding : PortBinding {
233- HostIP : "::1" ,
234- HostPort : "80" ,
224+ name : "square angled IPV6 with host port" ,
225+ spec : "[::1]:80:80" ,
226+ expected : []PortMapping {
227+ {
228+ Port : "80/tcp" ,
229+ Binding : PortBinding {
230+ HostIP : "::1" ,
231+ HostPort : "80" ,
232+ },
233+ },
234+ },
235+ },
236+ {
237+ name : "IPV6 without host port" ,
238+ spec : "2001:4860:0:2001::68::333" ,
239+ expected : []PortMapping {
240+ {
241+ Port : "333/tcp" ,
242+ Binding : PortBinding {
243+ HostIP : "2001:4860:0:2001::68" ,
244+ HostPort : "" ,
245+ },
246+ },
247+ },
248+ },
249+ {
250+ name : "IPV6 with host port" ,
251+ spec : "::1:80:80" ,
252+ expected : []PortMapping {
253+ {
254+ Port : "80/tcp" ,
255+ Binding : PortBinding {
256+ HostIP : "::1" ,
257+ HostPort : "80" ,
258+ },
259+ },
260+ },
261+ },
262+ {
263+ name : ":: IPV6, without host port" ,
264+ spec : "::::80" ,
265+ expected : []PortMapping {
266+ {
267+ Port : "80/tcp" ,
268+ Binding : PortBinding {
269+ HostIP : "::" ,
270+ HostPort : "" ,
271+ },
272+ },
235273 },
236274 },
237275 }
238- if ! reflect .DeepEqual (expected , portMappings ) {
239- t .Fatalf ("wrong port mappings: got=%v, want=%v" , portMappings , expected )
276+ for _ , c := range cases {
277+ t .Run (c .name , func (t * testing.T ) {
278+ portMappings , err := ParsePortSpec (c .spec )
279+ if err != nil {
280+ t .Fatalf ("expected nil error, got: %v" , err )
281+ }
282+ if ! reflect .DeepEqual (c .expected , portMappings ) {
283+ t .Fatalf ("wrong port mappings: got=%v, want=%v" , portMappings , c .expected )
284+ }
285+ })
240286 }
241287}
242288
0 commit comments