Struct libcnb_test::BuildConfig

source ·
pub struct BuildConfig { /* private fields */ }
Expand description

Configuration for a test.

Implementations§

source§

impl BuildConfig

source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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| {
        // ...
    },
);
source

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

source§

fn clone(&self) -> BuildConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.