@@ -50,6 +50,54 @@ type testCase struct {
5050 instance * linodego.Instance
5151}
5252
53+ func TestComputeStableIPv6PodCIDR (t * testing.T ) {
54+ for _ , tc := range []struct {
55+ name string
56+ baseCIDR string
57+ desiredMask int
58+ wantCIDR string
59+ wantOK bool
60+ }{
61+ {name : "nil base" , baseCIDR : "" , desiredMask : 112 , wantOK : false },
62+ {name : "non-/112 desired" , baseCIDR : "2300:5800:2:1::/64" , desiredMask : 120 , wantOK : false },
63+ {name : "ipv4 base" , baseCIDR : "10.0.0.0/24" , desiredMask : 112 , wantOK : false },
64+ {name : "non-/64 ipv6 base (/56)" , baseCIDR : "2300:5800:2::/56" , desiredMask : 112 , wantOK : false },
65+ {name : "success /64 -> mnemonic /112" , baseCIDR : "2300:5800:2:1::/64" , desiredMask : 112 , wantCIDR : "2300:5800:2:1:0:c::/112" , wantOK : true },
66+ } {
67+ t .Run (tc .name , func (t * testing.T ) {
68+ var baseNet * net.IPNet
69+ if tc .baseCIDR != "" {
70+ _ , parsed , err := net .ParseCIDR (tc .baseCIDR )
71+ if err != nil {
72+ t .Fatalf ("parse base cidr: %v" , err )
73+ }
74+ baseNet = parsed
75+ }
76+ got , ok := getIPv6PodCIDR (baseNet , tc .desiredMask )
77+ if ok != tc .wantOK {
78+ t .Fatalf ("ok mismatch: got %v want %v (gotCIDR=%v)" , ok , tc .wantOK , func () string {
79+ if got != nil {
80+ return got .String ()
81+ }
82+ return ""
83+ }())
84+ }
85+ if ! tc .wantOK {
86+ if got != nil {
87+ t .Fatalf ("expected nil cidr on failure, got %v" , got .String ())
88+ }
89+ return
90+ }
91+ if got == nil {
92+ t .Fatalf ("expected non-nil cidr" )
93+ }
94+ if got .String () != tc .wantCIDR {
95+ t .Fatalf ("cidr mismatch: got %s want %s" , got .String (), tc .wantCIDR )
96+ }
97+ })
98+ }
99+ }
100+
53101func TestGetIPv6RangeFromLinodeInterface (t * testing.T ) {
54102 for _ , tc := range []struct {
55103 iface linodego.LinodeInterface
0 commit comments