github.com/cilium/cilium@v1.16.2/pkg/ipam/metrics/mock/mock_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package mock
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestMock(t *testing.T) {
    13  	api := NewMockMetrics()
    14  	api.AllocationAttempt("createInterfaceAndAllocateIP", "foo", "s-1", 0)
    15  	require.Equal(t, int64(1), api.GetAllocationAttempts("createInterfaceAndAllocateIP", "foo", "s-1"))
    16  	api.AddIPAllocation("s-1", 10)
    17  	api.AddIPAllocation("s-1", 20)
    18  	require.Equal(t, int64(30), api.IPAllocations("s-1"))
    19  	api.SetAllocatedIPs("used", 200)
    20  	require.Equal(t, 200, api.AllocatedIPs("used"))
    21  	api.SetAvailableInterfaces(10)
    22  	require.Equal(t, 10, api.AvailableInterfaces())
    23  	api.SetInterfaceCandidates(10)
    24  	require.Equal(t, 10, api.InterfaceCandidates())
    25  	api.SetEmptyInterfaceSlots(10)
    26  	require.Equal(t, 10, api.EmptyInterfaceSlots())
    27  	api.SetNodes("at-capacity", 5)
    28  	require.Equal(t, 5, api.Nodes("at-capacity"))
    29  	api.IncResyncCount()
    30  	require.Equal(t, int64(1), api.ResyncCount())
    31  }