Skip to content

Commit

Permalink
netutil: imp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Apr 1, 2024
1 parent e221b7e commit 33cce10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion netutil/reversed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package netutil

import (
"math"
"net"
"net/netip"
"strconv"
Expand Down Expand Up @@ -402,7 +403,7 @@ func isV4ARPALabel(label string) (ok bool) {
val = val*10 + int(c-'0')
}

return val <= 255
return val <= math.MaxUint8
}
}

Expand Down
12 changes: 11 additions & 1 deletion netutil/reversed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ func TestExtractReversedAddr(t *testing.T) {
name: "partial_v4",
domain: ipv4NetRevGood,
wantErr: "",
}, {
want: netip.PrefixFrom(testIPv4PartPref.Addr(), testIPv4PartPref.Bits()+8),
name: "partial_v4_zero_label",
domain: "0." + ipv4NetRevGood,
wantErr: "",
}, {
want: testIPv4Pref,
name: "whole_v4_within_domain",
Expand All @@ -582,7 +587,7 @@ func TestExtractReversedAddr(t *testing.T) {
}, {
want: testIPv4PartPref,
name: "partial_v4_within_domain",
domain: "a." + ipv4NetRevGood,
domain: "abc." + ipv4NetRevGood,
wantErr: "",
}, {
want: testIPv4PartPref,
Expand All @@ -594,6 +599,11 @@ func TestExtractReversedAddr(t *testing.T) {
name: "overflow_v4_within_domain",
domain: "a.256." + ipv4NetRevGood,
wantErr: "",
}, {
want: testIPv4PartPref,
name: "partial_v4_leading_zero_label",
domain: "05." + ipv4NetRevGood,
wantErr: "",
}, {
want: emptyV4Pref,
name: "empty_v4",
Expand Down

0 comments on commit 33cce10

Please sign in to comment.