mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Move to go 1.17 (#12868)
Also ensure that the go 1.17 breaking changes to net.ParseCIDR don't make us choke on stored CIDRs that were acceptable to older Go versions.
This commit is contained in:
35
helper/parseip/parseip_test.go
Normal file
35
helper/parseip/parseip_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package parseip
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_TrimLeadingZeroes(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"127.0.0.1", "127.0.0.1"},
|
||||
{"010.010.20.5", "10.10.20.5"},
|
||||
{"1.1.1.010", "1.1.1.10"},
|
||||
{"64:ff9b::192.00.002.33", "64:ff9b::192.0.2.33"},
|
||||
{"2001:db8:122:344:c0:2:2100::", "2001:db8:122:344:c0:2:2100::"},
|
||||
{"2001:db8:122:344::192.0.2.033", "2001:db8:122:344::192.0.2.33"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := trimLeadingZeroesIP(tt.in); got != tt.want {
|
||||
t.Errorf("trimLeadingZeroesIP() = %v, want %v", got, tt.want)
|
||||
}
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
// Non-CIDR addresses are ignored.
|
||||
if got := TrimLeadingZeroesCIDR(tt.in); got != tt.in {
|
||||
t.Errorf("TrimLeadingZeroesCIDR() = %v, want %v", got, tt.in)
|
||||
}
|
||||
want := tt.want + "/32"
|
||||
if got := TrimLeadingZeroesCIDR(tt.in + "/32"); got != want {
|
||||
t.Errorf("TrimLeadingZeroesCIDR() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user