Skip to content

Commit e03a5a2

Browse files
committed
Generate non-overlapping and non-mergable CIDRs at best effort (#8587)
1 parent 73b17fb commit e03a5a2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

internal/testutil/fixture/fixture.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func (f *Fixture) RandomIPv4Prefixes(n int) []netip.Prefix {
7979
)
8080

8181
for _, ip := range ips {
82-
bits := int(f.RandomUint64(24)) + 8
82+
const MinBits = 16
83+
bits := int(f.RandomUint64(32-MinBits)) + MinBits
8384
p, err := ip.Prefix(bits)
8485
if err != nil {
8586
panic("unreachable: it should always be a valid IP prefix")
@@ -118,7 +119,8 @@ func (f *Fixture) RandomIPv6Prefixes(n int) []netip.Prefix {
118119
)
119120

120121
for _, ip := range ips {
121-
bits := int(f.RandomUint64(120)) + 8
122+
const MinBits = 32
123+
bits := int(f.RandomUint64(128-MinBits)) + MinBits
122124
p, err := ip.Prefix(bits)
123125
if err != nil {
124126
panic("unreachable: it should always be a valid IP prefix")

0 commit comments

Comments
 (0)