| 81 | } |
| 82 | |
| 83 | func testBasicOperations(t *testing.T, store *RedisRefreshTokenStore) { |
| 84 | ctx := context.Background() |
| 85 | token := "test-token-basic" |
| 86 | userData := map[string]any{ |
| 87 | "user_id": 123, |
| 88 | "username": "testuser", |
| 89 | } |
| 90 | expiry := time.Now().Add(time.Hour) |
| 91 | |
| 92 | // Test Set |
| 93 | err := store.Set(ctx, token, userData, expiry) |
| 94 | assert.NoError(t, err, "Set should not return error") |
| 95 | |
| 96 | // Test Get |
| 97 | retrievedData, err := store.Get(ctx, token) |
| 98 | assert.NoError(t, err, "Get should not return error") |
| 99 | assert.Equal(t, userData, retrievedData, "Retrieved data should match stored data") |
| 100 | |
| 101 | // Test Delete |
| 102 | err = store.Delete(ctx, token) |
| 103 | assert.NoError(t, err, "Delete should not return error") |
| 104 | |
| 105 | // Verify deletion |
| 106 | _, err = store.Get(ctx, token) |
| 107 | assert.ErrorIs(t, err, core.ErrRefreshTokenNotFound, "Token should not be found after deletion") |
| 108 | |
| 109 | // Test empty token |
| 110 | err = store.Set(ctx, "", userData, expiry) |
| 111 | assert.Error(t, err, "Set with empty token should return error") |
| 112 | |
| 113 | _, err = store.Get(ctx, "") |
| 114 | assert.ErrorIs( |
| 115 | t, |
| 116 | err, |
| 117 | core.ErrRefreshTokenNotFound, |
| 118 | "Get with empty token should return not found error", |
| 119 | ) |
| 120 | |
| 121 | err = store.Delete(ctx, "") |
| 122 | assert.NoError(t, err, "Delete with empty token should not return error") |
| 123 | |
| 124 | // Test ping |
| 125 | err = store.Ping() |
| 126 | assert.NoError(t, err, "Ping should not return error") |
| 127 | |
| 128 | // Clean up test data |
| 129 | _ = store.client.Do(ctx, store.client.B().Del().Key(store.buildKey(token)).Build()) |
| 130 | } |
| 131 | |
| 132 | func testExpiration(t *testing.T, store *RedisRefreshTokenStore) { |
| 133 | ctx := context.Background() |