added test, gofmtd

Signed-off-by: shuai-z <zs.broccoli@gmail.com>
This commit is contained in:
shuai-z 2014-10-21 13:27:47 +08:00
parent 9451cf39ef
commit 2c2edabca5
2 changed files with 17 additions and 1 deletions

View File

@ -14,7 +14,7 @@ type portMap struct {
func newPortMap() *portMap {
return &portMap{
p: map[int]struct{}{},
p: map[int]struct{}{},
last: EndPortRange,
}
}

View File

@ -214,3 +214,19 @@ func TestPortAllocation(t *testing.T) {
t.Fatal("Requesting a dynamic port should never allocate a used port")
}
}
func TestNoDuplicateBPR(t *testing.T) {
defer reset()
if port, err := RequestPort(defaultIP, "tcp", BeginPortRange); err != nil {
t.Fatal(err)
} else if port != BeginPortRange {
t.Fatalf("Expected port %d got %d", BeginPortRange, port)
}
if port, err := RequestPort(defaultIP, "tcp", 0); err != nil {
t.Fatal(err)
} else if port == BeginPortRange {
t.Fatalf("Acquire(0) allocated the same port twice: %d", port)
}
}