Skip to content

Commit 1f7220b

Browse files
committed
nat: remove redundant type-conversions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent fc83585 commit 1f7220b

2 files changed

Lines changed: 38 additions & 48 deletions

File tree

nat/nat_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,15 @@ func TestParsePortSpecs(t *testing.T) {
367367
t.Fatalf("Error while processing ParsePortSpecs: %s", err)
368368
}
369369

370-
if _, ok := portMap[Port("1234/tcp")]; !ok {
370+
if _, ok := portMap["1234/tcp"]; !ok {
371371
t.Fatal("1234/tcp was not parsed properly")
372372
}
373373

374-
if _, ok := portMap[Port("2345/udp")]; !ok {
374+
if _, ok := portMap["2345/udp"]; !ok {
375375
t.Fatal("2345/udp was not parsed properly")
376376
}
377377

378-
if _, ok := portMap[Port("3456/sctp")]; !ok {
378+
if _, ok := portMap["3456/sctp"]; !ok {
379379
t.Fatal("3456/sctp was not parsed properly")
380380
}
381381

@@ -398,15 +398,15 @@ func TestParsePortSpecs(t *testing.T) {
398398
t.Fatalf("Error while processing ParsePortSpecs: %s", err)
399399
}
400400

401-
if _, ok := portMap[Port("1234/tcp")]; !ok {
401+
if _, ok := portMap["1234/tcp"]; !ok {
402402
t.Fatal("1234/tcp was not parsed properly")
403403
}
404404

405-
if _, ok := portMap[Port("2345/udp")]; !ok {
405+
if _, ok := portMap["2345/udp"]; !ok {
406406
t.Fatal("2345/udp was not parsed properly")
407407
}
408408

409-
if _, ok := portMap[Port("3456/sctp")]; !ok {
409+
if _, ok := portMap["3456/sctp"]; !ok {
410410
t.Fatal("3456/sctp was not parsed properly")
411411
}
412412

@@ -431,15 +431,15 @@ func TestParsePortSpecs(t *testing.T) {
431431
t.Fatalf("Error while processing ParsePortSpecs: %s", err)
432432
}
433433

434-
if _, ok := portMap[Port("1234/tcp")]; !ok {
434+
if _, ok := portMap["1234/tcp"]; !ok {
435435
t.Fatal("1234/tcp was not parsed properly")
436436
}
437437

438-
if _, ok := portMap[Port("2345/udp")]; !ok {
438+
if _, ok := portMap["2345/udp"]; !ok {
439439
t.Fatal("2345/udp was not parsed properly")
440440
}
441441

442-
if _, ok := portMap[Port("3456/sctp")]; !ok {
442+
if _, ok := portMap["3456/sctp"]; !ok {
443443
t.Fatal("3456/sctp was not parsed properly")
444444
}
445445

@@ -478,15 +478,15 @@ func TestParsePortSpecsWithRange(t *testing.T) {
478478
t.Fatalf("Error while processing ParsePortSpecs: %s", err)
479479
}
480480

481-
if _, ok := portMap[Port("1235/tcp")]; !ok {
481+
if _, ok := portMap["1235/tcp"]; !ok {
482482
t.Fatal("1234/tcp was not parsed properly")
483483
}
484484

485-
if _, ok := portMap[Port("2346/udp")]; !ok {
485+
if _, ok := portMap["2346/udp"]; !ok {
486486
t.Fatal("2345/udp was not parsed properly")
487487
}
488488

489-
if _, ok := portMap[Port("3456/sctp")]; !ok {
489+
if _, ok := portMap["3456/sctp"]; !ok {
490490
t.Fatal("3456/sctp was not parsed properly")
491491
}
492492

@@ -509,15 +509,15 @@ func TestParsePortSpecsWithRange(t *testing.T) {
509509
t.Fatalf("Error while processing ParsePortSpecs: %s", err)
510510
}
511511

512-
if _, ok := portMap[Port("1235/tcp")]; !ok {
512+
if _, ok := portMap["1235/tcp"]; !ok {
513513
t.Fatal("1234/tcp was not parsed properly")
514514
}
515515

516-
if _, ok := portMap[Port("2346/udp")]; !ok {
516+
if _, ok := portMap["2346/udp"]; !ok {
517517
t.Fatal("2345/udp was not parsed properly")
518518
}
519519

520-
if _, ok := portMap[Port("3456/sctp")]; !ok {
520+
if _, ok := portMap["3456/sctp"]; !ok {
521521
t.Fatal("3456/sctp was not parsed properly")
522522
}
523523

@@ -541,15 +541,15 @@ func TestParsePortSpecsWithRange(t *testing.T) {
541541
t.Fatalf("Error while processing ParsePortSpecs: %s", err)
542542
}
543543

544-
if _, ok := portMap[Port("1235/tcp")]; !ok {
544+
if _, ok := portMap["1235/tcp"]; !ok {
545545
t.Fatal("1234/tcp was not parsed properly")
546546
}
547547

548-
if _, ok := portMap[Port("2346/udp")]; !ok {
548+
if _, ok := portMap["2346/udp"]; !ok {
549549
t.Fatal("2345/udp was not parsed properly")
550550
}
551551

552-
if _, ok := portMap[Port("3456/sctp")]; !ok {
552+
if _, ok := portMap["3456/sctp"]; !ok {
553553
t.Fatal("3456/sctp was not parsed properly")
554554
}
555555

nat/sort_test.go

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,61 @@
11
package nat
22

33
import (
4-
"fmt"
54
"reflect"
65
"testing"
76
)
87

98
func TestSortUniquePorts(t *testing.T) {
109
ports := []Port{
11-
Port("6379/tcp"),
12-
Port("22/tcp"),
10+
"6379/tcp",
11+
"22/tcp",
1312
}
1413

1514
Sort(ports, func(ip, jp Port) bool {
1615
return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp")
1716
})
1817

1918
first := ports[0]
20-
if fmt.Sprint(first) != "22/tcp" {
21-
t.Log(fmt.Sprint(first))
19+
if string(first) != "22/tcp" {
20+
t.Log(first)
2221
t.Fail()
2322
}
2423
}
2524

2625
func TestSortSamePortWithDifferentProto(t *testing.T) {
2726
ports := []Port{
28-
Port("8888/tcp"),
29-
Port("8888/udp"),
30-
Port("6379/tcp"),
31-
Port("6379/udp"),
27+
"8888/tcp",
28+
"8888/udp",
29+
"6379/tcp",
30+
"6379/udp",
3231
}
3332

3433
Sort(ports, func(ip, jp Port) bool {
3534
return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp")
3635
})
3736

3837
first := ports[0]
39-
if fmt.Sprint(first) != "6379/tcp" {
38+
if string(first) != "6379/tcp" {
4039
t.Fail()
4140
}
4241
}
4342

4443
func TestSortPortMap(t *testing.T) {
4544
ports := []Port{
46-
Port("22/tcp"),
47-
Port("22/udp"),
48-
Port("8000/tcp"),
49-
Port("8443/tcp"),
50-
Port("6379/tcp"),
51-
Port("9999/tcp"),
45+
"22/tcp",
46+
"22/udp",
47+
"8000/tcp",
48+
"8443/tcp",
49+
"6379/tcp",
50+
"9999/tcp",
5251
}
5352

5453
portMap := PortMap{
55-
Port("22/tcp"): []PortBinding{
56-
{},
57-
},
58-
Port("8000/tcp"): []PortBinding{
59-
{},
60-
},
61-
Port("8443/tcp"): []PortBinding{},
62-
Port("6379/tcp"): []PortBinding{
63-
{},
64-
{HostIP: "0.0.0.0", HostPort: "32749"},
65-
},
66-
Port("9999/tcp"): []PortBinding{
67-
{HostIP: "0.0.0.0", HostPort: "40000"},
68-
},
54+
"22/tcp": []PortBinding{{}},
55+
"8000/tcp": []PortBinding{{}},
56+
"8443/tcp": []PortBinding{},
57+
"6379/tcp": []PortBinding{{}, {HostIP: "0.0.0.0", HostPort: "32749"}},
58+
"9999/tcp": []PortBinding{{HostIP: "0.0.0.0", HostPort: "40000"}},
6959
}
7060

7161
SortPortMap(ports, portMap)

0 commit comments

Comments
 (0)