Struct libcnb_test::TestConfig
source · [−]pub struct TestConfig { /* private fields */ }Expand description
Configuration for a test.
Implementations
sourceimpl TestConfig
impl TestConfig
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 test configuration.
If the app_dir parameter is a relative path, it is treated as relative to the Cargo
manifest directory (CARGO_MANIFEST_DIR),
i.e. the package’s root directory.
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 used when compiling the buildpack.
Defaults to x86_64-unknown-linux-musl.
sourcepub fn env(&mut self, k: impl Into<String>, v: impl Into<String>) -> &mut Self
pub fn env(&mut self, k: impl Into<String>, v: impl Into<String>) -> &mut Self
Inserts or updates an environment variable mapping for the build process.
Note: This does not set this environment variable for running containers, it’s only available during the build.
Example
use libcnb_test::{TestConfig, TestRunner};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app")
.env("ENV_VAR_ONE", "VALUE ONE")
.env("ENV_VAR_TWO", "SOME OTHER VALUE"),
|context| {
// ...
},
)sourcepub fn envs<K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>>(
&mut self,
envs: I
) -> &mut Self
pub fn envs<K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>>(
&mut self,
envs: I
) -> &mut Self
Adds or updates multiple environment variable mappings for the build process.
Note: This does not set environment variables for running containers, they’re only available during the build.
Example
use libcnb_test::{TestConfig, TestRunner};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app").envs(vec![
("ENV_VAR_ONE", "VALUE ONE"),
("ENV_VAR_TWO", "SOME OTHER VALUE"),
]),
|context| {
// ...
},
);sourcepub fn app_dir_preprocessor<F: 'static + Fn(PathBuf)>(
&mut self,
f: F
) -> &mut Self
pub fn app_dir_preprocessor<F: 'static + Fn(PathBuf)>(
&mut self,
f: F
) -> &mut Self
Sets an app directory preprocessor function.
It will be run after the app directory has been copied for the current integration test run, the changes will not affect other integration test runs.
Generally, we suggest using dedicated test fixtures. However, in some cases it is more economical to slightly modify a fixture programmatically before a test instead.
Example
use libcnb_test::{TestConfig, TestRunner};
TestRunner::default().run_test(
TestConfig::new("heroku/builder:22", "test-fixtures/app").app_dir_preprocessor(
|app_dir| std::fs::remove_file(app_dir.join("Procfile")).unwrap(),
),
|context| {
// ...
},
);sourcepub fn app_dir<P: Into<PathBuf>>(&mut self, path: P) -> &mut Self
pub fn app_dir<P: Into<PathBuf>>(&mut self, path: P) -> &mut Self
Sets the app directory.
The app directory is normally set in the TestConfig::new call, but when sharing test
configuration, it might be necessary to change the app directory but keep everything else
the same.
sourcepub fn expected_pack_result(&mut self, pack_result: PackResult) -> &mut Self
pub fn expected_pack_result(&mut self, pack_result: PackResult) -> &mut Self
Set the expected pack command result.
In some cases, users might want to explicitly test that a build fails and asserting against
error output. When passed PackResult::Failure, the test will fail if the pack build
succeeds and vice-versa.
Defaults to PackResult::Success
Trait Implementations
sourceimpl Clone for TestConfig
impl Clone for TestConfig
sourcefn clone(&self) -> TestConfig
fn clone(&self) -> TestConfig
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
Auto Trait Implementations
impl !RefUnwindSafe for TestConfig
impl !Send for TestConfig
impl !Sync for TestConfig
impl Unpin for TestConfig
impl !UnwindSafe for TestConfig
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