(t *testing.T)
| 189 | } |
| 190 | |
| 191 | func 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…