(t *testing.T)
| 169 | } |
| 170 | |
| 171 | func TestCachePin(t *testing.T) { |
| 172 | c, create := setup(t) |
| 173 | |
| 174 | _, err := c.Get("/", create) |
| 175 | require.NoError(t, err) |
| 176 | |
| 177 | // Pin a nonexistent item to show nothing happens |
| 178 | c.Pin("notfound") |
| 179 | |
| 180 | c.mu.Lock() |
| 181 | entry := c.cache["/"] |
| 182 | assert.Equal(t, 1, len(c.cache)) |
| 183 | c.mu.Unlock() |
| 184 | |
| 185 | c.cacheExpire() |
| 186 | |
| 187 | c.mu.Lock() |
| 188 | assert.Equal(t, 1, len(c.cache)) |
| 189 | c.mu.Unlock() |
| 190 | |
| 191 | // Pin the entry and check it does not get expired |
| 192 | c.Pin("/") |
| 193 | |
| 194 | // Reset last used to make the item expirable |
| 195 | c.mu.Lock() |
| 196 | entry.lastUsed = time.Now().Add(-c.expireDuration - 60*time.Second) |
| 197 | c.mu.Unlock() |
| 198 | |
| 199 | c.cacheExpire() |
| 200 | |
| 201 | c.mu.Lock() |
| 202 | assert.Equal(t, 1, len(c.cache)) |
| 203 | c.mu.Unlock() |
| 204 | |
| 205 | // Unpin the entry and check it does get expired now |
| 206 | c.Unpin("/") |
| 207 | |
| 208 | // Reset last used |
| 209 | c.mu.Lock() |
| 210 | entry.lastUsed = time.Now().Add(-c.expireDuration - 60*time.Second) |
| 211 | c.mu.Unlock() |
| 212 | |
| 213 | c.cacheExpire() |
| 214 | |
| 215 | c.mu.Lock() |
| 216 | assert.Equal(t, 0, len(c.cache)) |
| 217 | c.mu.Unlock() |
| 218 | } |
| 219 | |
| 220 | func TestClear(t *testing.T) { |
| 221 | c, create := setup(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…