Struct libcnb_test::IntegrationTest
source · [−]pub struct IntegrationTest { /* private fields */ }Expand description
Main type for libcnb integration tests.
Dependencies
Integration tests require external tools to be available on the host to run:
Example
use libcnb_test::{IntegrationTest, BuildpackReference, assert_contains};
IntegrationTest::new("heroku/buildpacks:20", "test-fixtures/app")
.buildpacks(vec![
BuildpackReference::Other(String::from("heroku/openjdk")),
BuildpackReference::Crate,
])
.run_test(|context| {
assert_contains!(context.pack_stdout, "---> Maven Buildpack");
assert_contains!(context.pack_stdout, "---> Installing Maven");
assert_contains!(context.pack_stdout, "---> Running mvn package");
context.start_container(&[12345], |container| {
assert_eq!(
call_test_fixture_service(
container.address_for_port(12345).unwrap(),
"Hagbard Celine"
)
.unwrap(),
"enileC drabgaH"
);
});
});Implementations
sourceimpl IntegrationTest
impl IntegrationTest
sourcepub fn new(builder_name: impl Into<String>, app_dir: impl AsRef<Path>) -> Self
pub fn new(builder_name: impl Into<String>, app_dir: impl AsRef<Path>) -> Self
Creates a new integration test.
Panics
- When the connection to Docker failed
- When the internal Tokio runtime could not be created
sourcepub fn buildpacks(
&mut self,
buildpacks: impl Into<Vec<BuildpackReference>>
) -> &mut Self
pub fn buildpacks(
&mut self,
buildpacks: impl Into<Vec<BuildpackReference>>
) -> &mut Self
Sets the buildpacks order.
Defaults to BuildpackReference::Crate.
sourcepub fn target_triple(&mut self, target_triple: impl Into<String>) -> &mut Self
pub fn target_triple(&mut self, target_triple: impl Into<String>) -> &mut Self
Sets the target triple.
Defaults to x86_64-unknown-linux-musl.
sourcepub fn run_test<F: FnOnce(IntegrationTestContext<'_>)>(&mut self, f: F)
pub fn run_test<F: FnOnce(IntegrationTestContext<'_>)>(&mut self, f: F)
Starts a new integration test run.
This function will copy 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 this integration test instance.
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 packed as a buildpack
- When the “pack” command unexpectedly fails
Example
use libcnb_test::{IntegrationTest, assert_contains};
IntegrationTest::new("heroku/buildpacks:20", "test-fixtures/app")
.run_test(|context| {
assert_contains!(context.pack_stdout, "---> Ruby Buildpack");
assert_contains!(context.pack_stdout, "---> Installing bundler");
assert_contains!(context.pack_stdout, "---> Installing gems");
})Auto Trait Implementations
impl !RefUnwindSafe for IntegrationTest
impl Send for IntegrationTest
impl Sync for IntegrationTest
impl Unpin for IntegrationTest
impl !UnwindSafe for IntegrationTest
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub 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