Repository navigation
Commit 900cbb5
fix(rueidiscompatmock): make Cache() mockable via the expectation queue (#1023)
`rueidiscompatmock` now supports mocking client-side caching.
`Cache(ttl)` commands dispatch through the existing `Expect*`
expectation queue instead of panicking with `unexpected call to DoCache`
(issue #972). The new `DoCache` stub reuses the same ordered queue as
`Do`/`DoMulti`, so no `Expect*` API changed and the TTL argument is
deliberately not matched (documented in the README).
Design notes:
- The fix lives in `rueidiscompatmock` only; `rueidiscompat` and the
root `mock/` package are untouched. This follows the maintainer's
direction on #1021 instead of the rejected interface-ization of
`CacheCompat`.
- `DoMultiCache` is not stubbed: the `rueidiscompat` cache surface never
calls it (verified against the receiver block in
`rueidiscompat/adapter.go`).
Validated with the module's full test suite including `-race`. Eight new
`TestCacheCompat*` tests cover dispatch through both adapter entry
points, multi-command queues, `Cacheable`-wrapped commands, nil/error
results, TTL irrelevance, and unmatched-command reporting.
Fixes #972.
Related: #1021
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Test-helper only; no production Redis client or auth/data path
changes. Matching origin (cache vs plain) is a behavior change for
existing mock tests that mix Cache() with unmarked Expect* calls.
>
> **Overview**
> Makes `rueidiscompat.Cache(ttl)` commands mockable in
`rueidiscompatmock` instead of panicking on `DoCache`. Cached calls
reuse the existing `Expect*` queue; TTL is not matched.
>
> Matching is origin-aware: `ExpectGet("k").ViaCache()` only matches
`rdb.Cache(ttl).Get(...)`, and unmarked expectations only match plain
calls. Unordered matching still prefers the origin-specific entry rather
than the first same-command expectation.
>
> `ViaCache()` is added on all expected-result types. Unmatched cache
calls report `via cache` in the error. `DoMultiCache` is not stubbed.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
def365b. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: SomSamantray <>
Co-authored-by: Rueian <rueiancsie@gmail.com>1 parent 12cec18 commit 900cbb5
4 files changed
Lines changed: 547 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
49 | 80 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
| |||
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
556 | | - | |
| 557 | + | |
557 | 558 | | |
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
561 | 562 | | |
562 | | - | |
| 563 | + | |
563 | 564 | | |
564 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
565 | 579 | | |
566 | 580 | | |
567 | | - | |
| 581 | + | |
568 | 582 | | |
569 | 583 | | |
570 | 584 | | |
571 | 585 | | |
572 | | - | |
| 586 | + | |
573 | 587 | | |
574 | | - | |
| 588 | + | |
575 | 589 | | |
576 | 590 | | |
577 | 591 | | |
| |||
588 | 602 | | |
589 | 603 | | |
590 | 604 | | |
591 | | - | |
| 605 | + | |
592 | 606 | | |
593 | | - | |
| 607 | + | |
594 | 608 | | |
595 | 609 | | |
596 | 610 | | |
| |||
604 | 618 | | |
605 | 619 | | |
606 | 620 | | |
607 | | - | |
| 621 | + | |
608 | 622 | | |
609 | 623 | | |
610 | 624 | | |
611 | 625 | | |
612 | | - | |
| 626 | + | |
613 | 627 | | |
614 | 628 | | |
615 | 629 | | |
616 | 630 | | |
617 | 631 | | |
618 | | - | |
| 632 | + | |
619 | 633 | | |
620 | 634 | | |
621 | 635 | | |
622 | 636 | | |
623 | 637 | | |
624 | 638 | | |
625 | | - | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
626 | 643 | | |
627 | 644 | | |
628 | 645 | | |
| |||
0 commit comments