(t *testing.T)
| 214 | } |
| 215 | |
| 216 | func TestComplete_DoubleCallIsNoop(t *testing.T) { |
| 217 | store, userID, _ := newStoreAndUser(t) |
| 218 | ctx := context.Background() |
| 219 | |
| 220 | hash := idempotency.HashBody([]byte(`{"a":1}`)) |
| 221 | first, _ := store.Claim(ctx, userID, "key-dbl", "/api/v1/send", hash) |
| 222 | if first.Outcome != idempotency.OutcomeAcquired { |
| 223 | t.Fatalf("first Outcome = %d", first.Outcome) |
| 224 | } |
| 225 | originalCached := idempotency.CachedResponse{StatusCode: 200, ContentType: "application/json", Body: []byte(`{"status":"sent"}`)} |
| 226 | _ = store.Complete(ctx, userID, "key-dbl", originalCached) |
| 227 | |
| 228 | // A buggy caller re-Completes with a different body. Must not |
| 229 | // overwrite the cached response. |
| 230 | _ = store.Complete(ctx, userID, "key-dbl", idempotency.CachedResponse{StatusCode: 500, Body: []byte("oops")}) |
| 231 | |
| 232 | replay, _ := store.Claim(ctx, userID, "key-dbl", "/api/v1/send", hash) |
| 233 | if replay.Outcome != idempotency.OutcomeReplay { |
| 234 | t.Fatalf("Outcome = %d", replay.Outcome) |
| 235 | } |
| 236 | if string(replay.Cached.Body) != string(originalCached.Body) { |
| 237 | t.Errorf("cached body = %q, want %q (Complete should be no-op after first call)", replay.Cached.Body, originalCached.Body) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func TestSweep_DeletesCompletedRowsPastTTL(t *testing.T) { |
| 242 | store, userID, pool := newStoreAndUser(t) |
nothing calls this directly
no test coverage detected