(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func TestReAddExpiredItem(t *testing.T) { |
| 66 | deleteChan := make(chan string, 1) |
| 67 | exp := &FakeExpirationPolicy{ |
| 68 | NeverExpire: sets.NewString(), |
| 69 | RetrieveKeyFunc: func(obj interface{}) (string, error) { |
| 70 | return obj.(*TimestampedEntry).Obj.(testStoreObject).id, nil |
| 71 | }, |
| 72 | } |
| 73 | ttlStore := NewFakeExpirationStore( |
| 74 | testStoreKeyFunc, deleteChan, exp, clock.RealClock{}) |
| 75 | testKey := "foo" |
| 76 | testObj := testStoreObject{id: testKey, val: "bar"} |
| 77 | err := ttlStore.Add(testObj) |
| 78 | if err != nil { |
| 79 | t.Errorf("Unable to add obj %#v", testObj) |
| 80 | } |
| 81 | |
| 82 | // This get will expire the item. |
| 83 | item, exists, err := ttlStore.Get(testObj) |
| 84 | if err != nil { |
| 85 | t.Errorf("Failed to get from store, %v", err) |
| 86 | } |
| 87 | if exists || item != nil { |
| 88 | t.Errorf("Got unexpected item %#v", item) |
| 89 | } |
| 90 | |
| 91 | key, _ := testStoreKeyFunc(testObj) |
| 92 | differentValue := "different_bar" |
| 93 | err = ttlStore.Add( |
| 94 | testStoreObject{id: testKey, val: differentValue}) |
| 95 | if err != nil { |
| 96 | t.Errorf("Failed to add second value") |
| 97 | } |
| 98 | |
| 99 | select { |
| 100 | case delKey := <-deleteChan: |
| 101 | if delKey != key { |
| 102 | t.Errorf("Unexpected delete for key %s", key) |
| 103 | } |
| 104 | case <-time.After(wait.ForeverTestTimeout): |
| 105 | t.Errorf("Unexpected timeout waiting on delete") |
| 106 | } |
| 107 | exp.NeverExpire = sets.NewString(testKey) |
| 108 | item, exists, err = ttlStore.GetByKey(testKey) |
| 109 | if err != nil { |
| 110 | t.Errorf("Failed to get from store, %v", err) |
| 111 | } |
| 112 | if !exists || item == nil || item.(testStoreObject).val != differentValue { |
| 113 | t.Errorf("Got unexpected item %#v", item) |
| 114 | } |
| 115 | close(deleteChan) |
| 116 | } |
| 117 | |
| 118 | func TestTTLList(t *testing.T) { |
| 119 | testObjs := []testStoreObject{ |
nothing calls this directly
no test coverage detected