pub struct MockCommandRunner { /* private fields */ }Expand description
A reusable, hand-rolled mock for xianyun_executor::exec::CommandRunner.
See the module-level documentation for the matching/exhaustion model.
Construct with MockCommandRunner::new, queue expectations with the
expect_* methods, exercise it through the CommandRunner trait, and
either call MockCommandRunner::verify explicitly or let it drop at
the end of the test.
Implementations§
Source§impl MockCommandRunner
impl MockCommandRunner
pub fn new() -> Self
Sourcepub fn expect_run(&self, name: &str, args: &[&str], result: ExecResult)
pub fn expect_run(&self, name: &str, args: &[&str], result: ExecResult)
Queues an exact-match, one-shot (called exactly once) expectation.
Sourcepub fn expect_run_matching(
&self,
name: &str,
predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static,
result: ExecResult,
)
pub fn expect_run_matching( &self, name: &str, predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static, result: ExecResult, )
Queues a predicate-matched, one-shot expectation – the
equivalent of testify’s mock.MatchedBy. predicate is
evaluated against the call’s arguments.
Sourcepub fn expect_run_repeating(
&self,
name: &str,
args: &[&str],
responder: impl Fn() -> ExecResult + Send + Sync + 'static,
)
pub fn expect_run_repeating( &self, name: &str, args: &[&str], responder: impl Fn() -> ExecResult + Send + Sync + 'static, )
Queues an exact-match expectation that may match any number
of times (including zero) – the equivalent of testify’s
.Maybe(). responder is invoked fresh on every matching
call, so it can return a fallible value type with no Clone
bound.
Sourcepub fn expect_read_stdout(
&self,
name: &str,
args: &[&str],
result: Result<String, ExecError>,
)
pub fn expect_read_stdout( &self, name: &str, args: &[&str], result: Result<String, ExecError>, )
Queues an exact-match, one-shot (called exactly once) expectation.
Sourcepub fn expect_read_stdout_matching(
&self,
name: &str,
predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static,
result: Result<String, ExecError>,
)
pub fn expect_read_stdout_matching( &self, name: &str, predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static, result: Result<String, ExecError>, )
Queues a predicate-matched, one-shot expectation – the
equivalent of testify’s mock.MatchedBy. predicate is
evaluated against the call’s arguments.
Sourcepub fn expect_read_stdout_repeating(
&self,
name: &str,
args: &[&str],
responder: impl Fn() -> Result<String, ExecError> + Send + Sync + 'static,
)
pub fn expect_read_stdout_repeating( &self, name: &str, args: &[&str], responder: impl Fn() -> Result<String, ExecError> + Send + Sync + 'static, )
Queues an exact-match expectation that may match any number
of times (including zero) – the equivalent of testify’s
.Maybe(). responder is invoked fresh on every matching
call, so it can return a fallible value type with no Clone
bound.
Sourcepub fn expect_run_sudo(
&self,
name: &str,
args: &[&str],
result: Result<(), ExecError>,
)
pub fn expect_run_sudo( &self, name: &str, args: &[&str], result: Result<(), ExecError>, )
Queues an exact-match, one-shot (called exactly once) expectation.
Sourcepub fn expect_run_sudo_matching(
&self,
name: &str,
predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static,
result: Result<(), ExecError>,
)
pub fn expect_run_sudo_matching( &self, name: &str, predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static, result: Result<(), ExecError>, )
Queues a predicate-matched, one-shot expectation – the
equivalent of testify’s mock.MatchedBy. predicate is
evaluated against the call’s arguments.
Sourcepub fn expect_run_sudo_repeating(
&self,
name: &str,
args: &[&str],
responder: impl Fn() -> Result<(), ExecError> + Send + Sync + 'static,
)
pub fn expect_run_sudo_repeating( &self, name: &str, args: &[&str], responder: impl Fn() -> Result<(), ExecError> + Send + Sync + 'static, )
Queues an exact-match expectation that may match any number
of times (including zero) – the equivalent of testify’s
.Maybe(). responder is invoked fresh on every matching
call, so it can return a fallible value type with no Clone
bound.
Sourcepub fn expect_check(
&self,
name: &str,
args: &[&str],
result: Result<bool, ExecError>,
)
pub fn expect_check( &self, name: &str, args: &[&str], result: Result<bool, ExecError>, )
Queues an exact-match, one-shot (called exactly once) expectation.
Sourcepub fn expect_check_matching(
&self,
name: &str,
predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static,
result: Result<bool, ExecError>,
)
pub fn expect_check_matching( &self, name: &str, predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static, result: Result<bool, ExecError>, )
Queues a predicate-matched, one-shot expectation – the
equivalent of testify’s mock.MatchedBy. predicate is
evaluated against the call’s arguments.
Sourcepub fn expect_check_repeating(
&self,
name: &str,
args: &[&str],
responder: impl Fn() -> Result<bool, ExecError> + Send + Sync + 'static,
)
pub fn expect_check_repeating( &self, name: &str, args: &[&str], responder: impl Fn() -> Result<bool, ExecError> + Send + Sync + 'static, )
Queues an exact-match expectation that may match any number
of times (including zero) – the equivalent of testify’s
.Maybe(). responder is invoked fresh on every matching
call, so it can return a fallible value type with no Clone
bound.
Sourcepub fn expect_exec_streamed_command(
&self,
name: &str,
args: &[&str],
result: Result<(), ExecError>,
)
pub fn expect_exec_streamed_command( &self, name: &str, args: &[&str], result: Result<(), ExecError>, )
Queues an exact-match, one-shot (called exactly once) expectation.
Sourcepub fn expect_exec_streamed_command_matching(
&self,
name: &str,
predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static,
result: Result<(), ExecError>,
)
pub fn expect_exec_streamed_command_matching( &self, name: &str, predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static, result: Result<(), ExecError>, )
Queues a predicate-matched, one-shot expectation – the
equivalent of testify’s mock.MatchedBy. predicate is
evaluated against the call’s arguments.
Sourcepub fn expect_exec_streamed_command_repeating(
&self,
name: &str,
args: &[&str],
responder: impl Fn() -> Result<(), ExecError> + Send + Sync + 'static,
)
pub fn expect_exec_streamed_command_repeating( &self, name: &str, args: &[&str], responder: impl Fn() -> Result<(), ExecError> + Send + Sync + 'static, )
Queues an exact-match expectation that may match any number
of times (including zero) – the equivalent of testify’s
.Maybe(). responder is invoked fresh on every matching
call, so it can return a fallible value type with no Clone
bound.
Sourcepub fn expect_run_in_repository(
&self,
name: &str,
args: &[&str],
result: Result<(), ExecError>,
)
pub fn expect_run_in_repository( &self, name: &str, args: &[&str], result: Result<(), ExecError>, )
Queues an exact-match, one-shot (called exactly once) expectation.
Sourcepub fn expect_run_in_repository_matching(
&self,
name: &str,
predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static,
result: Result<(), ExecError>,
)
pub fn expect_run_in_repository_matching( &self, name: &str, predicate: impl Fn(&[String]) -> bool + Send + Sync + 'static, result: Result<(), ExecError>, )
Queues a predicate-matched, one-shot expectation – the
equivalent of testify’s mock.MatchedBy. predicate is
evaluated against the call’s arguments.
Sourcepub fn expect_run_in_repository_repeating(
&self,
name: &str,
args: &[&str],
responder: impl Fn() -> Result<(), ExecError> + Send + Sync + 'static,
)
pub fn expect_run_in_repository_repeating( &self, name: &str, args: &[&str], responder: impl Fn() -> Result<(), ExecError> + Send + Sync + 'static, )
Queues an exact-match expectation that may match any number
of times (including zero) – the equivalent of testify’s
.Maybe(). responder is invoked fresh on every matching
call, so it can return a fallible value type with no Clone
bound.
Sourcepub fn expect_look_path(&self, file: &str, result: Result<PathBuf, ExecError>)
pub fn expect_look_path(&self, file: &str, result: Result<PathBuf, ExecError>)
Queues an exact-match, one-shot expectation for look_path(file).
look_path has no args slice (it takes a single file), so it
is not covered by the mock_method macro above.
§Panics
Panics if another thread poisoned this mock’s internal lock by panicking while holding it.
Sourcepub fn expect_look_path_repeating(
&self,
file: &str,
responder: impl Fn() -> Result<PathBuf, ExecError> + Send + Sync + 'static,
)
pub fn expect_look_path_repeating( &self, file: &str, responder: impl Fn() -> Result<PathBuf, ExecError> + Send + Sync + 'static, )
Queues a look_path(file) expectation that may match any number
of times.
§Panics
Panics if another thread poisoned this mock’s internal lock by panicking while holding it.
Sourcepub fn recorded_run_calls(&self) -> Vec<RecordedRunCall>
pub fn recorded_run_calls(&self) -> Vec<RecordedRunCall>
Returns every recorded call to run, in call order, regardless of
whether an expectation matched it. Use this to assert on opts
(particularly opts.env) – the one thing expect_run_matching’s
predicate can’t see. This mirrors run_in_repository/
exec_streamed_command’s own recorded-calls accessors; run only
grew one once a real bug (xianyun-backends::kubectl::Client
never wiring KUBECONFIG into Options::env) went undetected
because nothing could assert on run’s opts – see
crates/xianyun-backends/PORT_NOTES.md.
§Panics
Panics if another thread poisoned this mock’s internal lock by panicking while holding it.
Sourcepub fn recorded_run_in_repository_calls(
&self,
) -> Vec<RecordedRunInRepositoryCall>
pub fn recorded_run_in_repository_calls( &self, ) -> Vec<RecordedRunInRepositoryCall>
Returns every recorded call to run_in_repository, in call order,
regardless of whether an expectation matched it. Use this to
assert on opts (particularly opts.env) – the one thing
expect_run_in_repository_matching’s predicate can’t see.
§Panics
Panics if another thread poisoned this mock’s internal lock by panicking while holding it.
Sourcepub fn recorded_exec_streamed_command_calls(
&self,
) -> Vec<RecordedExecStreamedCommandCall>
pub fn recorded_exec_streamed_command_calls( &self, ) -> Vec<RecordedExecStreamedCommandCall>
Returns every recorded call to exec_streamed_command, in call
order, regardless of whether an expectation matched it. Use this
to assert on opts (particularly opts.env) – the one thing
expect_exec_streamed_command_matching’s predicate can’t see.
§Panics
Panics if another thread poisoned this mock’s internal lock by panicking while holding it.
Sourcepub fn verify(&self)
pub fn verify(&self)
Checks every queued expectation across every mocked method and
panics, listing them, if any one-shot (non-repeating) expectation
was never fully consumed. Safe to call multiple times: only the
first call can panic, since matched expectations are removed from
their queues as they’re consumed. Also run implicitly on
Drop if not called explicitly (skipped if the test is already
panicking, to avoid a double panic during unwind).
§Panics
Panics if any one-shot expectation across any mocked method was never fully consumed, or if another thread poisoned this mock’s internal lock by panicking while holding it.
Trait Implementations§
Source§impl CommandRunner for MockCommandRunner
impl CommandRunner for MockCommandRunner
fn run(&self, name: &str, args: &[String], opts: Option<Options>) -> ExecResult
fn read_stdout(&self, name: &str, args: &[String]) -> Result<String, ExecError>
fn run_sudo(&self, name: &str, args: &[String]) -> Result<(), ExecError>
fn check(&self, name: &str, args: &[String]) -> Result<bool, ExecError>
fn exec_streamed_command( &self, opts: Option<ExecStreamedOpts>, name: &str, args: &[String], ) -> Result<(), ExecError>
fn look_path(&self, file: &str) -> Result<PathBuf, ExecError>
fn run_in_repository( &self, repo_dir: &str, name: &str, args: &[String], opts: Option<ExecStreamedOpts>, ) -> Result<(), ExecError>
Source§impl Default for MockCommandRunner
impl Default for MockCommandRunner
Source§impl Drop for MockCommandRunner
impl Drop for MockCommandRunner
Auto Trait Implementations§
impl !Freeze for MockCommandRunner
impl RefUnwindSafe for MockCommandRunner
impl Send for MockCommandRunner
impl Sync for MockCommandRunner
impl Unpin for MockCommandRunner
impl UnsafeUnpin for MockCommandRunner
impl UnwindSafe for MockCommandRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more