Browse code

added test, gofmtd

Signed-off-by: shuai-z <zs.broccoli@gmail.com>

shuai-z authored on 2014/10/21 14:27:47
Showing 2 changed files
... ...
@@ -14,7 +14,7 @@ type portMap struct {
14 14
 
15 15
 func newPortMap() *portMap {
16 16
 	return &portMap{
17
-		p: map[int]struct{}{},
17
+		p:    map[int]struct{}{},
18 18
 		last: EndPortRange,
19 19
 	}
20 20
 }
... ...
@@ -214,3 +214,19 @@ func TestPortAllocation(t *testing.T) {
214 214
 		t.Fatal("Requesting a dynamic port should never allocate a used port")
215 215
 	}
216 216
 }
217
+
218
+func TestNoDuplicateBPR(t *testing.T) {
219
+	defer reset()
220
+
221
+	if port, err := RequestPort(defaultIP, "tcp", BeginPortRange); err != nil {
222
+		t.Fatal(err)
223
+	} else if port != BeginPortRange {
224
+		t.Fatalf("Expected port %d got %d", BeginPortRange, port)
225
+	}
226
+
227
+	if port, err := RequestPort(defaultIP, "tcp", 0); err != nil {
228
+		t.Fatal(err)
229
+	} else if port == BeginPortRange {
230
+		t.Fatalf("Acquire(0) allocated the same port twice: %d", port)
231
+	}
232
+}