From 944fca4dfd53000f967b68c2b6c373b912681ac6 Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Fri, 29 Mar 2019 20:50:44 +0100 Subject: [PATCH] add IP assignment idempotency test --- wireguard_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wireguard_test.go b/wireguard_test.go index 7f71d1b..6f672b1 100644 --- a/wireguard_test.go +++ b/wireguard_test.go @@ -85,3 +85,15 @@ func Test_wgState_assignOverlayAddr_no_obvious_collisions(t *testing.T) { assignments[wg.OverlayAddr.String()] = n } } + +// This should ensure the obvious fact that the same name should map to the same IP if called twice. +func Test_wgState_assignOverlayAddr_repeatable(t *testing.T) { + ipnet := &net.IPNet{IP: net.ParseIP("10.0.0.0"), Mask: net.CIDRMask(24, 32)} + wg1 := &wgState{} + wg1.assignOverlayAddr(ipnet, "test") + wg2 := &wgState{} + wg2.assignOverlayAddr(ipnet, "test") + if wg1.OverlayAddr.String() != wg2.OverlayAddr.String() { + t.Errorf("assignOverlayAddr() %s != %s", wg1.OverlayAddr, wg2.OverlayAddr) + } +}