Struct libcnb_test::TestContext
source · [−]pub struct TestContext<'a> {
pub pack_stdout: String,
pub pack_stderr: String,
pub config: TestConfig,
/* private fields */
}
Expand description
Context for a currently executing test.
Fields
pack_stdout: String
Standard output of pack
, interpreted as an UTF-8 string.
pack_stderr: String
Standard error of pack
, interpreted as an UTF-8 string.
config: TestConfig
The configuration used for this integration test.
Implementations
sourceimpl<'a> TestContext<'a>
impl<'a> TestContext<'a>
sourcepub fn prepare_container(&self) -> PrepareContainerContext<'_>
pub fn prepare_container(&self) -> PrepareContainerContext<'_>
Prepares a new container with the image from the test.
This will not create nor run the container immediately. Use the returned
PrepareContainerContext
to configure the container, then call
start_with_default_process
on it
to actually create and start the container.
Example:
use libcnb_test::{TestConfig, TestRunner};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app"),
|context| {
context
.prepare_container()
.start_with_default_process(|container| {
// ...
});
},
);
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 subsequent integration test run.
This function behaves exactly like TestRunner::run_test
, but it will reuse the OCI image
from the previous test, causing the CNB lifecycle to restore any cached layers. It will use the
same TestRunner
as the previous test run.
This function allows testing of subsequent builds, including caching logic and buildpack behaviour when build environment variables change, stacks are upgraded and more.
Note that this function will consume the current context. This is because the image will be changed by the subsequent test, invalidating the context. Running a subsequent test must therefore be the last operation. You can nest subsequent runs if required.
Example
use libcnb_test::{assert_contains, TestConfig, TestRunner};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app"),
|context| {
assert_contains!(context.pack_stdout, "---> Installing gems");
let config = context.config.clone();
context.run_test(config, |context| {
assert_contains!(context.pack_stdout, "---> Using cached gems");
});
},
);
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for TestContext<'a>
impl<'a> !Send for TestContext<'a>
impl<'a> !Sync for TestContext<'a>
impl<'a> Unpin for TestContext<'a>
impl<'a> !UnwindSafe for TestContext<'a>
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