Skip to main content

MockCommandRunner

Struct MockCommandRunner 

Source
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

Source

pub fn new() -> Self

Source

pub fn expect_run(&self, name: &str, args: &[&str], result: ExecResult)

Queues an exact-match, one-shot (called exactly once) expectation.

Source

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.

Source

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.

Source

pub fn expect_read_stdout( &self, name: &str, args: &[&str], result: Result<String, ExecError>, )

Queues an exact-match, one-shot (called exactly once) expectation.

Source

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.

Source

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.

Source

pub fn expect_run_sudo( &self, name: &str, args: &[&str], result: Result<(), ExecError>, )

Queues an exact-match, one-shot (called exactly once) expectation.

Source

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.

Source

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.

Source

pub fn expect_check( &self, name: &str, args: &[&str], result: Result<bool, ExecError>, )

Queues an exact-match, one-shot (called exactly once) expectation.

Source

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.

Source

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.

Source

pub fn expect_exec_streamed_command( &self, name: &str, args: &[&str], result: Result<(), ExecError>, )

Queues an exact-match, one-shot (called exactly once) expectation.

Source

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.

Source

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.

Source

pub fn expect_run_in_repository( &self, name: &str, args: &[&str], result: Result<(), ExecError>, )

Queues an exact-match, one-shot (called exactly once) expectation.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn run(&self, name: &str, args: &[String], opts: Option<Options>) -> ExecResult

Source§

fn read_stdout(&self, name: &str, args: &[String]) -> Result<String, ExecError>

Source§

fn run_sudo(&self, name: &str, args: &[String]) -> Result<(), ExecError>

Source§

fn check(&self, name: &str, args: &[String]) -> Result<bool, ExecError>

Source§

fn exec_streamed_command( &self, opts: Option<ExecStreamedOpts>, name: &str, args: &[String], ) -> Result<(), ExecError>

Source§

fn look_path(&self, file: &str) -> Result<PathBuf, ExecError>

Source§

fn run_in_repository( &self, repo_dir: &str, name: &str, args: &[String], opts: Option<ExecStreamedOpts>, ) -> Result<(), ExecError>

Source§

impl Default for MockCommandRunner

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for MockCommandRunner

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more