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

Function TestTTLExpirationBasic

tools/cache/expiration_cache_test.go:29–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestTTLExpirationBasic(t *testing.T) {
30 testObj := testStoreObject{id: "foo", val: "bar"}
31 deleteChan := make(chan string, 1)
32 ttlStore := NewFakeExpirationStore(
33 testStoreKeyFunc, deleteChan,
34 &FakeExpirationPolicy{
35 NeverExpire: sets.NewString(),
36 RetrieveKeyFunc: func(obj interface{}) (string, error) {
37 return obj.(*TimestampedEntry).Obj.(testStoreObject).id, nil
38 },
39 },
40 clock.RealClock{},
41 )
42 err := ttlStore.Add(testObj)
43 if err != nil {
44 t.Errorf("Unable to add obj %#v", testObj)
45 }
46 item, exists, err := ttlStore.Get(testObj)
47 if err != nil {
48 t.Errorf("Failed to get from store, %v", err)
49 }
50 if exists || item != nil {
51 t.Errorf("Got unexpected item %#v", item)
52 }
53 key, _ := testStoreKeyFunc(testObj)
54 select {
55 case delKey := <-deleteChan:
56 if delKey != key {
57 t.Errorf("Unexpected delete for key %s", key)
58 }
59 case <-time.After(wait.ForeverTestTimeout):
60 t.Errorf("Unexpected timeout waiting on delete")
61 }
62 close(deleteChan)
63}
64
65func TestReAddExpiredItem(t *testing.T) {
66 deleteChan := make(chan string, 1)

Callers

nothing calls this directly

Calls 5

NewFakeExpirationStoreFunction · 0.85
testStoreKeyFuncFunction · 0.85
AddMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected