From 4cb2cfed9ffd8a10e5a47b41b26313dd94a86dc1 Mon Sep 17 00:00:00 2001 From: Rajdeep Dua Date: Fri, 1 Aug 2014 23:41:34 +0530 Subject: [PATCH] Added test cases for no port passed to nat.ParsePortSpecs and negative port number passed Docker-DCO-1.1-Signed-off-by: Rajdeep due (github: rajdeepd) --- daemon/container_unit_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/daemon/container_unit_test.go b/daemon/container_unit_test.go index 7520017c10..1b1b934f42 100644 --- a/daemon/container_unit_test.go +++ b/daemon/container_unit_test.go @@ -89,6 +89,41 @@ func TestParseNetworkOptsPublic(t *testing.T) { } } +func TestParseNetworkOptsPublicNoPort(t *testing.T) { + ports, bindings, err := nat.ParsePortSpecs([]string{"192.168.1.100"}) + + if err == nil { + t.Logf("Expected error Invalid containerPort") + t.Fail() + } + if ports != nil { + t.Logf("Expected nil got %s", ports) + t.Fail() + } + if bindings != nil { + t.Logf("Expected nil got %s", bindings) + t.Fail() + } +} + +func TestParseNetworkOptsNegativePorts(t *testing.T) { + ports, bindings, err := nat.ParsePortSpecs([]string{"192.168.1.100:-1:-1"}) + + if err == nil { + t.Fail() + } + t.Logf("%v", len(ports)) + t.Logf("%v", bindings) + if len(ports) != 0 { + t.Logf("Expected nil got %s", len(ports)) + t.Fail() + } + if len(bindings) != 0 { + t.Logf("Expected 0 got %s", len(bindings)) + t.Fail() + } +} + func TestParseNetworkOptsUdp(t *testing.T) { ports, bindings, err := nat.ParsePortSpecs([]string{"192.168.1.100::6000/udp"}) if err != nil {