diff options
author | Christopher Koch <chrisko@google.com> | 2019-04-03 21:02:28 -0700 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2019-04-04 01:41:05 -0700 |
commit | b40bd52ae58aee37cec9ef81008e24488350c98f (patch) | |
tree | d4255f100add3e70cfa8e15b1b826cd80243a915 /dhcpv4/option_routes_test.go | |
parent | 625d653f51917b167cc2e53ef8fe595e85dd5fa4 (diff) |
dhcpv4: add RFC3442 route options
Signed-off-by: Christopher Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv4/option_routes_test.go')
-rw-r--r-- | dhcpv4/option_routes_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/dhcpv4/option_routes_test.go b/dhcpv4/option_routes_test.go new file mode 100644 index 0000000..19e331b --- /dev/null +++ b/dhcpv4/option_routes_test.go @@ -0,0 +1,64 @@ +package dhcpv4 + +import ( + "net" + "reflect" + "testing" +) + +func mustParseIPNet(s string) *net.IPNet { + _, ipnet, err := net.ParseCIDR(s) + if err != nil { + panic(err) + } + return ipnet +} + +func TestParseRoutes(t *testing.T) { + for _, tt := range []struct { + p []byte + want Routes + err error + }{ + { + p: []byte{32, 10, 2, 3, 4, 0, 0, 0, 0}, + want: Routes{ + &Route{ + Dest: mustParseIPNet("10.2.3.4/32"), + Router: net.IP{0, 0, 0, 0}, + }, + }, + }, + { + p: []byte{0, 0, 0, 0, 0}, + want: Routes{ + &Route{ + Dest: mustParseIPNet("0.0.0.0/0"), + Router: net.IP{0, 0, 0, 0}, + }, + }, + }, + { + p: []byte{32, 10, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + want: Routes{ + &Route{ + Dest: mustParseIPNet("10.2.3.4/32"), + Router: net.IP{0, 0, 0, 0}, + }, + &Route{ + Dest: mustParseIPNet("0.0.0.0/0"), + Router: net.IP{0, 0, 0, 0}, + }, + }, + }, + } { + var r Routes + if err := r.FromBytes(tt.p); err != tt.err { + t.Errorf("FromBytes(%v) = %v, want %v", tt.p, err, tt.err) + } + + if !reflect.DeepEqual(r, tt.want) { + t.Errorf("FromBytes(%v) = %v, want %v", tt.p, r, tt.want) + } + } +} |