mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-23 00:44:25 +01:00
Store relay states in a slice for consistent ordering (#1422)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/slackhq/nebula/config"
|
||||
"github.com/slackhq/nebula/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHostMap_MakePrimary(t *testing.T) {
|
||||
@@ -225,3 +226,31 @@ func TestHostMap_reload(t *testing.T) {
|
||||
c.ReloadConfigString("preferred_ranges: [1.1.1.1/32]")
|
||||
assert.EqualValues(t, []string{"1.1.1.1/32"}, toS(hm.GetPreferredRanges()))
|
||||
}
|
||||
|
||||
func TestHostMap_RelayState(t *testing.T) {
|
||||
h1 := &HostInfo{vpnIp: netip.MustParseAddr("0.0.0.1"), localIndexId: 1}
|
||||
a1 := netip.MustParseAddr("::1")
|
||||
a2 := netip.MustParseAddr("2001::1")
|
||||
|
||||
h1.relayState.InsertRelayTo(a1)
|
||||
assert.Equal(t, h1.relayState.relays, []netip.Addr{a1})
|
||||
h1.relayState.InsertRelayTo(a2)
|
||||
assert.Equal(t, h1.relayState.relays, []netip.Addr{a1, a2})
|
||||
// Ensure that the first relay added is the first one returned in the copy
|
||||
currentRelays := h1.relayState.CopyRelayIps()
|
||||
require.Len(t, currentRelays, 2)
|
||||
assert.Equal(t, currentRelays[0], a1)
|
||||
|
||||
// Deleting the last one in the list works ok
|
||||
h1.relayState.DeleteRelay(a2)
|
||||
assert.Equal(t, h1.relayState.relays, []netip.Addr{a1})
|
||||
|
||||
// Deleting an element not in the list works ok
|
||||
h1.relayState.DeleteRelay(a2)
|
||||
assert.Equal(t, h1.relayState.relays, []netip.Addr{a1})
|
||||
|
||||
// Deleting the only element in the list works ok
|
||||
h1.relayState.DeleteRelay(a1)
|
||||
assert.Equal(t, h1.relayState.relays, []netip.Addr{})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user