Skip to content

Commit 5b033ed

Browse files
authored
Merge pull request #57 from besolov/issue-56
issue-56 fix incorrect SortPortMap behaviour in case of empty binding
2 parents 97c2040 + 9885905 commit 5b033ed

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

nat/sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s portMapSorter) Less(i, j int) bool {
5858
func SortPortMap(ports []Port, bindings PortMap) {
5959
s := portMapSorter{}
6060
for _, p := range ports {
61-
if binding, ok := bindings[p]; ok {
61+
if binding, ok := bindings[p]; ok && len(binding) > 0 {
6262
for _, b := range binding {
6363
s = append(s, portMapEntry{port: p, binding: b})
6464
}

nat/sort_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func TestSortPortMap(t *testing.T) {
4646
Port("22/tcp"),
4747
Port("22/udp"),
4848
Port("8000/tcp"),
49+
Port("8443/tcp"),
4950
Port("6379/tcp"),
5051
Port("9999/tcp"),
5152
}
@@ -57,6 +58,7 @@ func TestSortPortMap(t *testing.T) {
5758
Port("8000/tcp"): []PortBinding{
5859
{},
5960
},
61+
Port("8443/tcp"): []PortBinding{},
6062
Port("6379/tcp"): []PortBinding{
6163
{},
6264
{HostIP: "0.0.0.0", HostPort: "32749"},
@@ -70,6 +72,7 @@ func TestSortPortMap(t *testing.T) {
7072
if !reflect.DeepEqual(ports, []Port{
7173
Port("9999/tcp"),
7274
Port("6379/tcp"),
75+
Port("8443/tcp"),
7376
Port("8000/tcp"),
7477
Port("22/tcp"),
7578
Port("22/udp"),

0 commit comments

Comments
 (0)