From 9885905e989f4d8cc9f42d3549c5be9c27e4460d Mon Sep 17 00:00:00 2001 From: Roman Besolov Date: Sun, 13 Jan 2019 12:30:03 +0300 Subject: [PATCH] issue-56 fix incorrect SortPortMap behaviour in case of empty binding Signed-off-by: Roman Besolov --- nat/sort.go | 2 +- nat/sort_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/nat/sort.go b/nat/sort.go index ce950171e..79817edfc 100644 --- a/nat/sort.go +++ b/nat/sort.go @@ -58,7 +58,7 @@ func (s portMapSorter) Less(i, j int) bool { func SortPortMap(ports []Port, bindings PortMap) { s := portMapSorter{} for _, p := range ports { - if binding, ok := bindings[p]; ok { + if binding, ok := bindings[p]; ok && len(binding) > 0 { for _, b := range binding { s = append(s, portMapEntry{port: p, binding: b}) } diff --git a/nat/sort_test.go b/nat/sort_test.go index 88ed91115..b0de0ac2d 100644 --- a/nat/sort_test.go +++ b/nat/sort_test.go @@ -46,6 +46,7 @@ func TestSortPortMap(t *testing.T) { Port("22/tcp"), Port("22/udp"), Port("8000/tcp"), + Port("8443/tcp"), Port("6379/tcp"), Port("9999/tcp"), } @@ -57,6 +58,7 @@ func TestSortPortMap(t *testing.T) { Port("8000/tcp"): []PortBinding{ {}, }, + Port("8443/tcp"): []PortBinding{}, Port("6379/tcp"): []PortBinding{ {}, {HostIP: "0.0.0.0", HostPort: "32749"}, @@ -70,6 +72,7 @@ func TestSortPortMap(t *testing.T) { if !reflect.DeepEqual(ports, []Port{ Port("9999/tcp"), Port("6379/tcp"), + Port("8443/tcp"), Port("8000/tcp"), Port("22/tcp"), Port("22/udp"),