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’smock.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§
- Mock
Command Runner - A reusable, hand-rolled mock for
xianyun_executor::exec::CommandRunner. - Recorded
Exec Streamed Command Call - One recorded call to
MockCommandRunner::exec_streamed_command, captured regardless of whether an expectation matched it. SeeRecordedRunInRepositoryCallfor why this exists. - Recorded
RunCall - One recorded call to
MockCommandRunner::run, captured regardless of whether an expectation matched it. Exists becauseMatcher::Predicateonly sees(name, args), notopts. Carriesenv/timeoutrather than the fullOptions, sinceOptions::stdin(Box<dyn Read + Send>) isn’tCloneand doesn’t need recording for this purpose anyway – seeMockCommandRunner::recorded_run_calls. - Recorded
RunIn Repository Call - One recorded call to
MockCommandRunner::run_in_repository, captured regardless of whether an expectation matched it. Exists becauseMatcher::Predicateonly sees(name, args), notopts–OptionsandExecStreamedOptscarry fields (env, in particular) severalPORT_NOTES.mdfiles flagged as needing inspection that the expectation-matching system can’t offer directly. SeeMockCommandRunner::recorded_run_in_repository_calls.