MCPcopy
hub / github.com/appleboy/gin-jwt / TestInMemoryRefreshTokenStore_Cleanup

Function TestInMemoryRefreshTokenStore_Cleanup

store/memory_test.go:191–250  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

189}
190
191func TestInMemoryRefreshTokenStore_Cleanup(t *testing.T) {
192 store := NewInMemoryRefreshTokenStore()
193
194 // Add some tokens: 2 valid, 2 expired
195 validExpiry := time.Now().Add(time.Hour)
196 expiredExpiry := time.Now().Add(-time.Hour)
197
198 err := store.Set(context.Background(), "valid1", &User{ID: "1"}, validExpiry)
199 assert.NoError(t, err)
200 err = store.Set(context.Background(), "valid2", &User{ID: "2"}, validExpiry)
201 assert.NoError(t, err)
202 err = store.Set(context.Background(), "expired1", &User{ID: "3"}, expiredExpiry)
203 assert.NoError(t, err)
204 err = store.Set(context.Background(), "expired2", &User{ID: "4"}, expiredExpiry)
205 assert.NoError(t, err)
206
207 // Verify initial count
208 count, _ := store.Count(context.Background())
209 if count != 4 {
210 t.Fatalf("Expected initial count to be 4, got %d", count)
211 }
212
213 // Cleanup expired tokens
214 cleaned, err := store.Cleanup(context.Background())
215 if err != nil {
216 t.Fatalf("Cleanup() returned error: %v", err)
217 }
218
219 if cleaned != 2 {
220 t.Fatalf("Expected 2 tokens to be cleaned up, got %d", cleaned)
221 }
222
223 // Verify final count
224 count, _ = store.Count(context.Background())
225 if count != 2 {
226 t.Fatalf("Expected final count to be 2, got %d", count)
227 }
228
229 // Verify valid tokens still exist
230 _, err = store.Get(context.Background(), "valid1")
231 if err != nil {
232 t.Fatalf("valid1 token should still exist: %v", err)
233 }
234
235 _, err = store.Get(context.Background(), "valid2")
236 if err != nil {
237 t.Fatalf("valid2 token should still exist: %v", err)
238 }
239
240 // Verify expired tokens are gone
241 _, err = store.Get(context.Background(), "expired1")
242 if err != ErrRefreshTokenNotFound {
243 t.Fatalf("expired1 token should be gone: %v", err)
244 }
245
246 _, err = store.Get(context.Background(), "expired2")
247 if err != ErrRefreshTokenNotFound {
248 t.Fatalf("expired2 token should be gone: %v", err)

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
CountMethod · 0.95
CleanupMethod · 0.95
GetMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…