-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package ipam | ||
|
||
import ( | ||
"context" | ||
"net/netip" | ||
"testing" | ||
) | ||
|
||
func FuzzIpamer_AcquireIP(f *testing.F) { | ||
ctx := context.Background() | ||
tests := []struct { | ||
name string | ||
prefixCIDR string | ||
want string | ||
}{ | ||
{ | ||
name: "Acquire next IP regularly", | ||
prefixCIDR: "192.168.1.0/24", | ||
want: "192.168.1.1", | ||
}, | ||
{ | ||
name: "Acquire next IPv6 regularly", | ||
prefixCIDR: "2001:db8:85a3::/124", | ||
want: "2001:db8:85a3::1", | ||
}, | ||
{ | ||
name: "Want next IP, but network is full", | ||
prefixCIDR: "192.168.4.0/32", | ||
want: "", | ||
}, | ||
{ | ||
name: "Want next IPv6, but network is full", | ||
prefixCIDR: "2001:db8:85a3::/128", | ||
want: "", | ||
}, | ||
} | ||
for _, tc := range tests { | ||
tc := tc | ||
f.Add(tc.prefixCIDR, tc.want) | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, prefixCIDR, want string) { | ||
ipam := New() | ||
p, err := ipam.NewPrefix(ctx, prefixCIDR) | ||
|
||
if err == nil { | ||
prefix, err := netip.ParsePrefix(prefixCIDR) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if prefix.Masked().String() != p.String() { | ||
if err != nil { | ||
t.Errorf("%q not equal %q", prefix.Masked().String(), p.String()) | ||
} | ||
} | ||
ip, err := ipam.AcquireIP(ctx, p.Cidr) | ||
if err == nil && want != "" && want != ip.IP.String() { | ||
if err != nil { | ||
t.Errorf("%q not equal %q", want, ip.IP.String()) | ||
} | ||
} | ||
} | ||
}) | ||
} |
3 changes: 3 additions & 0 deletions
3
...uzz/FuzzIpamer_AcquireIP/00e15d22123489fd226477045221a413abf1174857875133adc429e5e59623f1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
go test fuzz v1 | ||
string("0") | ||
string("0") |