github.com/cilium/cilium@v1.16.2/pkg/clustermesh/idsmgr_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package clustermesh 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/cilium/cilium/pkg/clustermesh/types" 12 ) 13 14 func TestClusterIDsManagerProvisioner(t *testing.T) { 15 mgr := idsMgrProvider(idsMgrProviderParams{}) 16 require.NotNil(t, mgr, "A non-nil instance of the default implementation should be returned") 17 require.NoError(t, mgr.ReserveClusterID(10), "Reserving a cluster ID should succeed") 18 19 mgr2 := idsMgrProvider(idsMgrProviderParams{Manager: mgr}) 20 require.Equal(t, mgr, mgr2, "The specified implementation should be propagated") 21 require.NoError(t, mgr.ReserveClusterID(11), "Reserving a cluster ID should succeed") 22 } 23 24 func TestClusterMeshUsedIDs(t *testing.T) { 25 mgr := NewClusterMeshUsedIDs(localClusterID) 26 27 require.NoError(t, mgr.ReserveClusterID(10), "Reserving a cluster ID should succeed") 28 require.NoError(t, mgr.ReserveClusterID(250), "Reserving another cluster ID should succeed") 29 require.Error(t, mgr.ReserveClusterID(250), "Attempting to reserve again the same cluster ID should fail") 30 31 mgr.ReleaseClusterID(250) 32 require.NoError(t, mgr.ReserveClusterID(250), "Reserving a released cluster ID should succeed") 33 34 require.Error(t, mgr.ReserveClusterID(types.ClusterIDUnset), "Reserving ClusterID 0 should fail") 35 mgr.ReleaseClusterID(types.ClusterIDUnset) 36 require.Error(t, mgr.ReserveClusterID(types.ClusterIDUnset), "Releasing ClusterID 0 should be a no-op") 37 38 require.Error(t, mgr.ReserveClusterID(localClusterID), "Reserving the local ClusterID should fail") 39 }