kdhcp/iptools/pool_test.go

37 lines
663 B
Go

package iptools
import (
"fmt"
"net/netip"
"testing"
)
var (
poolTestIP1 = netip.MustParseAddr("192.168.4.1")
poolTestIP2 = netip.MustParseAddr("192.168.4.32")
)
func TestBasicPool(t *testing.T) {
r := &Range{
Start: poolTestIP1,
End: poolTestIP2,
}
p, err := NewPool("cluster", r)
if err != nil {
t.Fatal(err)
}
if len(p.Available) != 32 {
t.Fatalf("have %d available leases, want %d", len(p.Available), 32)
}
for i := range p.Available {
l := p.Available[i]
expectedName := fmt.Sprintf("cluster%02d", l.Addr.As4()[3])
if l.HostName != expectedName {
t.Fatalf("have hostname %s, want %s", l.HostName, expectedName)
}
}
}