2023-05-03 02:57:04 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2023-05-06 05:21:27 +00:00
|
|
|
p, err := NewPool("cluster", r)
|
2023-05-03 02:57:04 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|