Browse code

Added test cases for no port passed to nat.ParsePortSpecs and negative port number passed

Docker-DCO-1.1-Signed-off-by: Rajdeep due <dua_rajdeep@yahoo.com> (github: rajdeepd)

Rajdeep Dua authored on 2014/08/02 03:11:34
Showing 1 changed files
... ...
@@ -89,6 +89,41 @@ func TestParseNetworkOptsPublic(t *testing.T) {
89 89
 	}
90 90
 }
91 91
 
92
+func TestParseNetworkOptsPublicNoPort(t *testing.T) {
93
+	ports, bindings, err := nat.ParsePortSpecs([]string{"192.168.1.100"})
94
+
95
+	if err == nil {
96
+		t.Logf("Expected error Invalid containerPort")
97
+		t.Fail()
98
+	}
99
+	if ports != nil {
100
+		t.Logf("Expected nil got %s", ports)
101
+		t.Fail()
102
+	}
103
+	if bindings != nil {
104
+		t.Logf("Expected nil got %s", bindings)
105
+		t.Fail()
106
+	}
107
+}
108
+
109
+func TestParseNetworkOptsNegativePorts(t *testing.T) {
110
+	ports, bindings, err := nat.ParsePortSpecs([]string{"192.168.1.100:-1:-1"})
111
+
112
+	if err == nil {
113
+		t.Fail()
114
+	}
115
+	t.Logf("%v", len(ports))
116
+	t.Logf("%v", bindings)
117
+	if len(ports) != 0 {
118
+		t.Logf("Expected nil got %s", len(ports))
119
+		t.Fail()
120
+	}
121
+	if len(bindings) != 0 {
122
+		t.Logf("Expected 0 got %s", len(bindings))
123
+		t.Fail()
124
+	}
125
+}
126
+
92 127
 func TestParseNetworkOptsUdp(t *testing.T) {
93 128
 	ports, bindings, err := nat.ParsePortSpecs([]string{"192.168.1.100::6000/udp"})
94 129
 	if err != nil {