MCPcopy
hub / github.com/kubernetes/client-go / TestHeap_ListKeys

Function TestHeap_ListKeys

tools/cache/heap_test.go:339–366  ·  view source on GitHub ↗

TestHeap_ListKeys tests Heap.ListKeys function. Scenario is the same as TestHeap_list.

(t *testing.T)

Source from the content-addressed store, hash-verified

337// TestHeap_ListKeys tests Heap.ListKeys function. Scenario is the same as
338// TestHeap_list.
339func TestHeap_ListKeys(t *testing.T) {
340 h := NewHeap(testHeapObjectKeyFunc, compareInts)
341 list := h.ListKeys()
342 if len(list) != 0 {
343 t.Errorf("expected an empty list")
344 }
345
346 items := map[string]int{
347 "foo": 10,
348 "bar": 1,
349 "bal": 30,
350 "baz": 11,
351 "faz": 30,
352 }
353 for k, v := range items {
354 h.Add(mkHeapObj(k, v))
355 }
356 list = h.ListKeys()
357 if len(list) != len(items) {
358 t.Errorf("expected %d items, got %d", len(items), len(list))
359 }
360 for _, key := range list {
361 _, ok := items[key]
362 if !ok {
363 t.Errorf("unexpected item in the list: %v", key)
364 }
365 }
366}
367
368// TestHeapAddAfterClose tests that heap returns an error if anything is added
369// after it is closed.

Callers

nothing calls this directly

Calls 5

ListKeysMethod · 0.95
AddMethod · 0.95
NewHeapFunction · 0.85
mkHeapObjFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected