summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_routes_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4/option_routes_test.go')
-rw-r--r--dhcpv4/option_routes_test.go64
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)
+ }
+ }
+}