Struct libcnb_test::TestRunner
source · [−]pub struct TestRunner { /* private fields */ }Expand description
Runner for libcnb integration tests.
Dependencies
Integration tests require external tools to be available on the host to run:
Example
use libcnb_test::{TestConfig, BuildpackReference, assert_contains, TestRunner};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app").buildpacks(vec![
BuildpackReference::Other(String::from("heroku/openjdk")),
BuildpackReference::Crate,
]),
|context| {
assert_contains!(context.pack_stdout, "---> Maven Buildpack");
assert_contains!(context.pack_stdout, "---> Installing Maven");
assert_contains!(context.pack_stdout, "---> Running mvn package");
context
.prepare_container()
.expose_port(12345)
.start_with_default_process(|container| {
assert_eq!(
call_test_fixture_service(
container.address_for_port(12345).unwrap(),
"Hagbard Celine"
)
.unwrap(),
"enileC drabgaH"
);
});
},
);Implementations
sourceimpl TestRunner
impl TestRunner
sourcepub fn new(tokio_runtime: Runtime, docker: Docker) -> Self
pub fn new(tokio_runtime: Runtime, docker: Docker) -> Self
Creates a new runner that uses the given Tokio runtime and Docker connection.
This function is meant for advanced use-cases where fine control over the Tokio runtime
and/or Docker connection is required. For the common use-cases, use Runner::default.
sourcepub fn run_test<C: Borrow<TestConfig>, F: FnOnce(TestContext<'_>)>(
&self,
config: C,
f: F
)
pub fn run_test<C: Borrow<TestConfig>, F: FnOnce(TestContext<'_>)>(
&self,
config: C,
f: F
)
Starts a new integration test run.
This function copies the application to a temporary directory, cross-compiles this crate,
packages it as a buildpack and then invokes pack
to build a new Docker image with the buildpacks specified by the passed TestConfig.
Since this function is supposed to only be used in integration tests, failures are not
signalled via Result values. Instead, this function panics whenever an unexpected error
occurred to simplify testing code.
Panics
- When the app could not be copied
- When this crate could not be packaged as a buildpack
- When the
packcommand unexpectedly fails
Example
use libcnb_test::{assert_contains, TestRunner, TestConfig};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app"),
|context| {
assert_contains!(context.pack_stdout, "---> Ruby Buildpack");
assert_contains!(context.pack_stdout, "---> Installing bundler");
assert_contains!(context.pack_stdout, "---> Installing gems");
},
)Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for TestRunner
impl Send for TestRunner
impl Sync for TestRunner
impl Unpin for TestRunner
impl !UnwindSafe for TestRunner
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more