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

Function testClientSideCache

store/redis_test.go:226–255  ·  view source on GitHub ↗
(t *testing.T, store *RedisRefreshTokenStore)

Source from the content-addressed store, hash-verified

224}
225
226func testClientSideCache(t *testing.T, store *RedisRefreshTokenStore) {
227 ctx := context.Background()
228 token := "test-token-cache"
229 userData := "cache-test-data"
230 expiry := time.Now().Add(time.Hour)
231
232 // Set token
233 err := store.Set(ctx, token, userData, expiry)
234 assert.NoError(t, err, "Set should not return error")
235
236 // First get (should populate cache)
237 start1 := time.Now()
238 retrievedData1, err := store.Get(ctx, token)
239 duration1 := time.Since(start1)
240 assert.NoError(t, err, "First Get should not return error")
241 assert.Equal(t, userData, retrievedData1, "First retrieved data should match stored data")
242
243 // Second get (should use cache and be faster)
244 start2 := time.Now()
245 retrievedData2, err := store.Get(ctx, token)
246 duration2 := time.Since(start2)
247 assert.NoError(t, err, "Second Get should not return error")
248 assert.Equal(t, userData, retrievedData2, "Second retrieved data should match stored data")
249
250 // Note: Cache performance test might be flaky in CI environments
251 t.Logf("First get took: %v, Second get took: %v", duration1, duration2)
252
253 // Clean up test data
254 _ = store.client.Do(ctx, store.client.B().Del().Key(store.buildKey(token)).Build())
255}
256
257func TestRedisRefreshTokenStore_ConnectionFailure(t *testing.T) {
258 // Test with invalid Redis configuration

Calls 3

buildKeyMethod · 0.80
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…