MCPcopy
hub / github.com/coocood/freecache / TestOverwrite

Function TestOverwrite

cache_test.go:131–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

129}
130
131func TestOverwrite(t *testing.T) {
132 cache := NewCache(1024)
133 key := []byte("abcd")
134 var val []byte
135 cache.Set(key, val, 0)
136 val = []byte("efgh")
137 cache.Set(key, val, 0)
138 val = append(val, 'i')
139 cache.Set(key, val, 0)
140 if count := cache.OverwriteCount(); count != 0 {
141 t.Error("overwrite count is", count, "expected ", 0)
142 }
143 res, _ := cache.Get(key)
144 if string(res) != string(val) {
145 t.Error(string(res))
146 }
147 val = append(val, 'j')
148 cache.Set(key, val, 0)
149 res, _ = cache.Get(key)
150 if string(res) != string(val) {
151 t.Error(string(res), "aaa")
152 }
153 val = append(val, 'k')
154 cache.Set(key, val, 0)
155 res, _ = cache.Get(key)
156 if string(res) != "efghijk" {
157 t.Error(string(res))
158 }
159 val = append(val, 'l')
160 cache.Set(key, val, 0)
161 res, _ = cache.Get(key)
162 if string(res) != "efghijkl" {
163 t.Error(string(res))
164 }
165 val = append(val, 'm')
166 cache.Set(key, val, 0)
167 if count := cache.OverwriteCount(); count != 3 {
168 t.Error("overwrite count is", count, "expected ", 3)
169 }
170}
171
172func TestGetOrSet(t *testing.T) {
173 cache := NewCache(1024)

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
OverwriteCountMethod · 0.95
GetMethod · 0.95
NewCacheFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…