Struct libcnb_test::BuildConfig
source · pub struct BuildConfig { /* private fields */ }
Expand description
Configuration for a test.
Implementations§
source§impl BuildConfig
impl BuildConfig
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 build 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.
§Example
use libcnb_test::{BuildConfig, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
|context| {
// ...
},
);
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 (and their ordering) to use when building the app.
Defaults to BuildpackReference::CurrentCrate
.
§Example
use libcnb::data::buildpack_id;
use libcnb_test::{BuildConfig, BuildpackReference, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/app").buildpacks([
BuildpackReference::CurrentCrate,
BuildpackReference::WorkspaceBuildpack(buildpack_id!("my-project/buildpack")),
BuildpackReference::Other(String::from("heroku/another-buildpack")),
]),
|context| {
// ...
},
);
sourcepub fn cargo_profile(&mut self, cargo_profile: CargoProfile) -> &mut Self
pub fn cargo_profile(&mut self, cargo_profile: CargoProfile) -> &mut Self
Sets the Cargo profile used when compiling the buildpack.
Defaults to CargoProfile::Dev
.
§Example
use libcnb_test::{BuildConfig, CargoProfile, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/app")
.cargo_profile(CargoProfile::Release),
|context| {
// ...
},
);
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
.
§Example
use libcnb_test::{BuildConfig, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/app")
.target_triple("x86_64-unknown-linux-musl"),
|context| {
// ...
},
);
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::{BuildConfig, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/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::{BuildConfig, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/app").envs([
("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::{BuildConfig, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/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 BuildConfig::new
call, but when sharing test
configuration, it might be necessary to change the app directory but keep everything else
the same.
§Example
use libcnb_test::{BuildConfig, TestRunner};
fn default_config() -> BuildConfig {
BuildConfig::new("heroku/builder:22", "tests/fixtures/app")
}
TestRunner::default().build(
default_config().app_dir("tests/fixtures/a-different-app"),
|context| {
// ...
},
);
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 assert against
error output. When passed PackResult::Failure
, the test will fail if the pack build
succeeds and vice-versa.
Defaults to PackResult::Success
.
§Example
use libcnb_test::{assert_contains, BuildConfig, PackResult, TestRunner};
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/app")
.expected_pack_result(PackResult::Failure),
|context| {
assert_contains!(context.pack_stderr, "ERROR: Invalid Procfile!");
},
);
Trait Implementations§
source§impl Clone for BuildConfig
impl Clone for BuildConfig
source§fn clone(&self) -> BuildConfig
fn clone(&self) -> BuildConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more