package iptools import ( "fmt" "net/netip" "testing" "time" ) 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", 24*time.Hour, 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) } } }