github.com/cilium/cilium@v1.16.2/pkg/mcastmanager/mcastmanager_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package mcastmanager 5 6 import ( 7 "net/netip" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 "github.com/vishvananda/netlink" 12 ) 13 14 func TestAddRemoveEndpoint(t *testing.T) { 15 ifaces, err := netlink.LinkList() 16 require.Nil(t, err) 17 18 if len(ifaces) == 0 { 19 t.Skip("no interfaces to test") 20 } 21 22 mgr := New(ifaces[0].Attrs().Name) 23 24 // Add first endpoint 25 mgr.AddAddress(netip.MustParseAddr("f00d::1234")) 26 27 require.Len(t, mgr.state, 1) 28 _, ok := mgr.state[netip.MustParseAddr("ff02::1:ff00:1234")] 29 require.Equal(t, true, ok) 30 31 // Add another endpoint that shares the same maddr 32 mgr.AddAddress(netip.MustParseAddr("f00d:aabb::1234")) 33 34 require.Len(t, mgr.state, 1) 35 36 // Remove the first endpoint 37 mgr.RemoveAddress(netip.MustParseAddr("f00d::1234")) 38 39 require.Len(t, mgr.state, 1) 40 _, ok = mgr.state[netip.MustParseAddr("ff02::1:ff00:1234")] 41 require.Equal(t, true, ok) 42 43 // Remove the second endpoint 44 mgr.RemoveAddress(netip.MustParseAddr("f00d:aabb::1234")) 45 46 require.Len(t, mgr.state, 0) 47 _, ok = mgr.state[netip.MustParseAddr("ff02::1:ff00:1234")] 48 require.Equal(t, false, ok) 49 } 50 51 func TestAddRemoveNil(t *testing.T) { 52 ifaces, err := netlink.LinkList() 53 require.Nil(t, err) 54 55 if len(ifaces) == 0 { 56 t.Skip("no interfaces to test") 57 } 58 59 var ( 60 iface = ifaces[0] 61 mgr = New(iface.Attrs().Name) 62 ) 63 64 mgr.AddAddress(netip.Addr{}) 65 require.Len(t, mgr.state, 0) 66 mgr.RemoveAddress(netip.Addr{}) 67 require.Len(t, mgr.state, 0) 68 }