Skip to main content

FakeEngine

Struct FakeEngine 

Source
pub struct FakeEngine { /* private fields */ }
Available on crate feature testing only.
Expand description

An in-memory Docker: up creates a project with scripted services, down removes it, and both raise the events Docker would. Clones share state, so a test can hand one to the code under test and inspect another.

A project’s name is read from the name: line of the head compose.yaml in the directory up is given, as Compose does for the files trestle renders. Its services default to a single healthy app; script sets others.

Implementations§

Source§

impl FakeEngine

Source

pub fn new() -> Self

An empty Docker host.

Source

pub fn script( &self, project: &str, services: impl IntoIterator<Item = (&'static str, Health)>, )

Give project these services, each reaching health once up.

Source

pub fn fail_up(&self, project: &str)

Make the next up of project fail, as an unhealthy --wait does.

Source

pub fn set_unavailable(&self, unavailable: bool)

Make every call fail as if the daemon were down (or back up with false).

Source

pub fn adopt(&self, project: &str)

Add a project as if something else had started it (e.g. a runtime that since died).

Source

pub fn add_network(&self, name: &str)

Declare the network name, as the first project joining it would.

Source

pub fn networks(&self) -> BTreeSet<String>

The networks that exist.

Source

pub fn projects(&self) -> BTreeSet<String>

The projects that exist.

Source

pub fn calls(&self) -> Vec<FakeCall>

Every call so far, in order.

Source

pub fn set_health(&self, project: &str, service: &str, health: Health)

Change the health of service in project, raising a health event.

Trait Implementations§

Source§

impl Clone for FakeEngine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComposeEngine for FakeEngine

Source§

fn up<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, dir: &'life1 Path, opts: &'life2 UpOptions, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create and start the project in dir (docker compose up -d).
Source§

fn down<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, dir: &'life1 Path, opts: &'life2 DownOptions, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stop and remove the project in dir (docker compose down).
Source§

fn ls<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ProjectStatus>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Every project Docker knows of, running or stopped (docker compose ls --all).
Source§

fn ps<'life0, 'life1, 'async_trait>( &'life0 self, project: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ServiceStatus>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The containers of project, running or stopped (docker compose ps --all).
Source§

fn logs<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, project: &'life1 str, _opts: &'life2 LogOptions, ) -> Pin<Box<dyn Future<Output = Result<EngineStream<LogLine>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The log lines of project’s containers (docker compose logs --timestamps).
Source§

fn events<'life0, 'life1, 'async_trait>( &'life0 self, filter: &'life1 EventFilter, ) -> Pin<Box<dyn Future<Output = Result<EngineStream<EngineEvent>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Container events of the projects filter picks, from now on (docker events).
Source§

fn network_rm<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove the network name; Ok(false) when it doesn’t exist or is still in use.
Source§

impl Default for FakeEngine

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.