Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit 07e0e03

Browse files
Add test for replyDestination
Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 2b59e7c commit 07e0e03

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

handler/reservation/handler_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,33 @@ func TestEncodeToAttributes(t *testing.T) {
597597
})
598598
}
599599
}
600+
601+
func TestReplyDestination(t *testing.T) {
602+
tests := map[string]struct {
603+
directPeer net.Addr
604+
giaddr net.IP
605+
want net.Addr
606+
}{
607+
"direct peer": {
608+
directPeer: &net.UDPAddr{IP: net.IP{192, 168, 1, 100}, Port: 68},
609+
want: &net.UDPAddr{IP: net.IP{192, 168, 1, 100}, Port: 68},
610+
},
611+
"direct peer with unspecified giaddr": {
612+
directPeer: &net.UDPAddr{IP: net.IP{192, 168, 1, 99}, Port: 68},
613+
giaddr: net.IPv4zero,
614+
want: &net.UDPAddr{IP: net.IP{192, 168, 1, 99}, Port: 68},
615+
},
616+
"giaddr": {
617+
giaddr: net.IP{192, 168, 2, 1},
618+
want: &net.UDPAddr{IP: net.IP{192, 168, 2, 1}, Port: 67},
619+
},
620+
}
621+
for name, tt := range tests {
622+
t.Run(name, func(t *testing.T) {
623+
got := replyDestination(tt.directPeer, tt.giaddr)
624+
if diff := cmp.Diff(got, tt.want); diff != "" {
625+
t.Fatal(diff)
626+
}
627+
})
628+
}
629+
}

0 commit comments

Comments
 (0)