MCPcopy
hub / github.com/cilium/cilium / TestSelectID

Function TestSelectID

pkg/allocator/allocator_test.go:257–280  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

255}
256
257func TestSelectID(t *testing.T) {
258 minID, maxID := idpool.ID(1), idpool.ID(5)
259 backend := newDummyBackend()
260 a, err := NewAllocator(hivetest.Logger(t), TestAllocatorKey(""), backend, WithMin(minID), WithMax(maxID))
261 require.NoError(t, err)
262 require.NotNil(t, a)
263
264 // allocate all available IDs
265 for i := minID; i <= maxID; i++ {
266 id, val, unmaskedID := a.selectAvailableID()
267 require.NotEqual(t, idpool.NoID, id)
268 require.Equal(t, id.String(), val)
269 require.Equal(t, unmaskedID, id)
270 a.mainCache.mutex.Lock()
271 a.mainCache.cache[id] = TestAllocatorKey(fmt.Sprintf("key-%d", i))
272 a.mainCache.mutex.Unlock()
273 }
274
275 // we should be out of IDs
276 id, val, unmaskedID := a.selectAvailableID()
277 require.Equal(t, idpool.ID(0), id)
278 require.Equal(t, unmaskedID, id)
279 require.Empty(t, val)
280}
281
282func TestPrefixMask(t *testing.T) {
283 minID, maxID := idpool.ID(1), idpool.ID(5)

Callers

nothing calls this directly

Calls 13

selectAvailableIDMethod · 0.95
IDTypeAlias · 0.92
newDummyBackendFunction · 0.85
NewAllocatorFunction · 0.85
WithMinFunction · 0.85
WithMaxFunction · 0.85
TestAllocatorKeyTypeAlias · 0.70
LoggerMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…