Skip to main content

Crate xianyun_testutil

Crate xianyun_testutil 

Source
Expand description

Shared test-support mocks for xianyun-* crates.

This crate exists because xianyun_executor::exec::CommandRunner is a pub trait implemented by clients across several crates (xianyun-backends, xianyun-cluster, xianyun-deploy, …), but xianyun-executor’s own hand-rolled mock (exec::mock::MockCommandRunner) is pub(crate) and cannot be reused outside that crate. Rather than leave every downstream crate to hand-roll (and slowly diverge) its own copy – as xianyun-backends’s testutil.rs already had to – this crate provides one shared, more capable implementation as a workspace-relative dev-dependency.

Compared to the hand-rolled mocks it replaces, MockCommandRunner adds two capabilities several PORT_NOTES.md files flagged as missing:

  • Predicate matching (expect_*_matching), the equivalent of testify’s mock.MatchedBy, for expectations that need to inspect arguments rather than match them exactly (e.g. a --timeout=<dur> value that shrinks across calls).
  • Repeating expectations (expect_*_repeating), the equivalent of testify’s .Maybe(), for expectations that may match any number of times (including zero) rather than exactly once.

Every expectation is queued per CommandRunner method and matched FIFO: when a call arrives, the first non-exhausted queued expectation for that method whose matcher accepts the call’s (name, args) wins. Exact-match, one-shot expectations behave exactly like the mocks this crate replaces (queue in the order you expect calls, first in first served). Calling MockCommandRunner::verify – or simply letting the mock drop – panics if any one-shot expectation was never fully consumed; an unexpected call (nothing queued matches) always panics immediately with a diagnostic listing what was queued.

Structs§

MockCommandRunner
A reusable, hand-rolled mock for xianyun_executor::exec::CommandRunner.
RecordedExecStreamedCommandCall
One recorded call to MockCommandRunner::exec_streamed_command, captured regardless of whether an expectation matched it. See RecordedRunInRepositoryCall for why this exists.
RecordedRunCall
One recorded call to MockCommandRunner::run, captured regardless of whether an expectation matched it. Exists because Matcher::Predicate only sees (name, args), not opts. Carries env/timeout rather than the full Options, since Options::stdin (Box<dyn Read + Send>) isn’t Clone and doesn’t need recording for this purpose anyway – see MockCommandRunner::recorded_run_calls.
RecordedRunInRepositoryCall
One recorded call to MockCommandRunner::run_in_repository, captured regardless of whether an expectation matched it. Exists because Matcher::Predicate only sees (name, args), not opts – Options and ExecStreamedOpts carry fields (env, in particular) several PORT_NOTES.md files flagged as needing inspection that the expectation-matching system can’t offer directly. See MockCommandRunner::recorded_run_in_repository_calls.