50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package server
|
|
|
|
import "testing"
|
|
|
|
func TestAllocatePreferredUsesStablePort(t *testing.T) {
|
|
first := NewPortPool(10000, 10010)
|
|
second := NewPortPool(10000, 10010)
|
|
|
|
firstPort, err := first.AllocatePreferred("king73.taylor-co.com")
|
|
if err != nil {
|
|
t.Fatalf("first allocate: %v", err)
|
|
}
|
|
|
|
secondPort, err := second.AllocatePreferred("king73.taylor-co.com")
|
|
if err != nil {
|
|
t.Fatalf("second allocate: %v", err)
|
|
}
|
|
|
|
if firstPort != secondPort {
|
|
t.Fatalf("expected stable port, got %d and %d", firstPort, secondPort)
|
|
}
|
|
}
|
|
|
|
func TestAllocatePreferredProbesOnCollision(t *testing.T) {
|
|
pool := NewPortPool(10000, 10001)
|
|
|
|
firstPort, err := pool.AllocatePreferred("king73.taylor-co.com")
|
|
if err != nil {
|
|
t.Fatalf("first allocate: %v", err)
|
|
}
|
|
|
|
secondPort, err := pool.AllocatePreferred("king73.taylor-co.com")
|
|
if err != nil {
|
|
t.Fatalf("second allocate: %v", err)
|
|
}
|
|
|
|
if firstPort == secondPort {
|
|
t.Fatalf("expected collision probe to choose a different port, got %d", secondPort)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeDomain(t *testing.T) {
|
|
got := SanitizeDomain(" King73.Taylor-Co.com:443/path ")
|
|
want := "king73-taylor-co-com-443-path"
|
|
|
|
if got != want {
|
|
t.Fatalf("SanitizeDomain() = %q, want %q", got, want)
|
|
}
|
|
}
|