pub struct MockRunner { /* private fields */ }Expand description
Test runner that records every call and returns scripted responses.
Calls not registered with MockRunner::with return exit code 0 with
empty output. Runner::run_as_root behaves as if sudo is on PATH
unless MockRunner::without_sudo is used, independent of the host.
Implementations§
Source§impl MockRunner
impl MockRunner
Sourcepub fn without_sudo(self) -> Self
pub fn without_sudo(self) -> Self
Behave as a host without sudo: root commands run directly.
Sourcepub fn with(self, cmd: &str, args: &[&str], resp: MockResponse) -> Self
pub fn with(self, cmd: &str, args: &[&str], resp: MockResponse) -> Self
Register a scripted response. cmd and args must match exactly.
Trait Implementations§
Source§impl Default for MockRunner
impl Default for MockRunner
Source§impl Runner for MockRunner
impl Runner for MockRunner
Source§fn run(&self, cmd: &str, args: &[&str]) -> Result<RunOutcome, Error>
fn run(&self, cmd: &str, args: &[&str]) -> Result<RunOutcome, Error>
Run
cmd with args. Returns a RunOutcome on success, or an I/O
error if the process could not be spawned at all.Source§fn run_as_root(&self, cmd: &str, args: &[&str]) -> Result<RunOutcome, Error>
fn run_as_root(&self, cmd: &str, args: &[&str]) -> Result<RunOutcome, Error>
Run
cmd with root privileges: through sudo when it is on PATH,
otherwise directly. Containers and minimal installs often run as root
with no sudo at all; a non-root user without sudo gets the
manager’s own permission error.Auto Trait Implementations§
impl !Freeze for MockRunner
impl RefUnwindSafe for MockRunner
impl Send for MockRunner
impl Sync for MockRunner
impl Unpin for MockRunner
impl UnsafeUnpin for MockRunner
impl UnwindSafe for MockRunner
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
Mutably borrows from an owned value. Read more