Skip to main content

BinProcessBuilder

Struct BinProcessBuilder 

Source
pub struct BinProcessBuilder { /* private fields */ }
Expand description

Start a running process of a binary.

All tracing events emitted by your binary in JSON over stdout will be processed by BinProcess and then emitted to the tests stdout in the default human readable tracing format. To ensure any WARN/ERROR’s from your test logic are visible, BinProcess will setup its own subscriber that outputs to the tests stdout in the default human readable format. If you set your own subscriber before constructing a BinProcess that will take preference instead.

Dropping the BinProcess will trigger a panic unless BinProcess::shutdown_and_then_consume_events or BinProcess::consume_remaining_events has been called. This is done to avoid missing important assertions run by those methods.

§Which constructor to use:

A guide to constructing BinProcess based on your use case:

§You are writing an integration test or bench and the binary you want to run is defined in the same package as the test or bench you are writing.

Use BinProcessBuilder::from_path like this:

BinProcessBuilder::from_path(bin_path!("cooldb"))
    .with_args(vec!["--log-format".to_owned(), "json".to_owned()])
    .start()
    .await;

Using from_path instead of from_cargo_name here is faster and more robust as BinProcess does not need to invoke Cargo.

§You are writing an integration test or bench and the binary you want to test is in the same

workspace but in a different package to the test or bench you are writing. Use BinProcessBuilder::from_cargo_name like this:

BinProcessBuilder::from_cargo_name("cooldb".to_owned(), None)
    .with_args(vec!["--log-format".to_owned(), "json".to_owned()])
    .start()
    .await;

§You are writing an example or other binary within a package

Use BinProcessBuilder::from_cargo_name like this:

BinProcessBuilder::from_cargo_name("cooldb".to_owned(), None)
    .with_args(vec!["--log-format".to_owned(), "json".to_owned()])
    .start()
    .await;

§You need to compile the binary with an arbitrary profile

Use BinProcessBuilder::from_cargo_name like this:

BinProcessBuilder::from_cargo_name("cooldb".to_owned(), Some("profilename".to_owned()))
    .with_args(vec!["--log-format".to_owned(), "json".to_owned()])
    .start()
    .await;

§You have an arbitrary pre-compiled binary to run

Use BinProcessBuilder::from_path like this:

BinProcessBuilder::from_path(PathBuf::from("some/path/to/precompiled/cooldb"))
    .with_args(vec!["--log-format".to_owned(), "json".to_owned()])
    .start()
    .await;

Implementations§

Source§

impl BinProcessBuilder

Source

pub fn from_path(bin_path: PathBuf) -> Self

Start the binary specified in bin_path.

Make sure to also call with_args or with_env_vars to enable the tracing JSON logger to stdout if that is not the default.

Source

pub fn from_cargo_name(name: String, profile: Option<String>) -> Self

Prefer BinProcessBuilder::from_path where possible as it is faster and more robust.

Start the binary named cargo_bin_name in the current workspace in a new process. A BinProcess is returned which can be used to interact with the process.

The crate will be compiled with the Cargo profile specified in cargo_profile.

  • When it is Some(_) the value specified is used.
  • When it is None it will use “release” if tokio-bin-process was compiled in a release derived profile or “dev” if it was compiled in a dev derived profile.

The reason None will only ever result in a “release” or “dev” profile is due to a limitation on what profile information Cargo exposes to us.

Make sure to also call with_args or with_env_vars to enable the tracing JSON logger to stdout if that is not the default.

Source

pub fn with_log_name(self, log_name: Option<String>) -> Self

log_name is prepended to the logs that BinProcess forwards to stdout. This helps to differentiate between tracing logs generated by the test itself and the process under test. The log name must be <= 10 characters.

Source

pub fn with_args(self, args: Vec<String>) -> Self

The args will be used as the args to the binary. The args should give the desired setup for the given integration test.

Source

pub fn with_env_vars(self, env_vars: Vec<(String, String)>) -> Self

The env_vars will be used as the env vars given to the binary. The env vars should give the desired setup for the given integration test.

Source

pub async fn start(self) -> BinProcess

Start the binary specified by from_path or from_cargo_name

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.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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