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

Configuration for a test.

Implementations§

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", "test-fixtures/app"),
    |context| {
        // ...
    },
);

Sets the buildpacks (and their ordering) to use when building the app.

Defaults to BuildpackReference::Crate.

Example
use libcnb_test::{BuildConfig, BuildpackReference, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "test-fixtures/app").buildpacks(vec![
        BuildpackReference::Other(String::from("heroku/another-buildpack")),
        BuildpackReference::Crate,
    ]),
    |context| {
        // ...
    },
);

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", "test-fixtures/app")
        .cargo_profile(CargoProfile::Release),
    |context| {
        // ...
    },
);

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", "test-fixtures/app")
        .target_triple("x86_64-unknown-linux-musl"),
    |context| {
        // ...
    },
);

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", "test-fixtures/app")
        .env("ENV_VAR_ONE", "VALUE ONE")
        .env("ENV_VAR_TWO", "SOME OTHER VALUE"),
    |context| {
        // ...
    },
);

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", "test-fixtures/app").envs(vec![
        ("ENV_VAR_ONE", "VALUE ONE"),
        ("ENV_VAR_TWO", "SOME OTHER VALUE"),
    ]),
    |context| {
        // ...
    },
);

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", "test-fixtures/app").app_dir_preprocessor(|app_dir| {
        std::fs::remove_file(app_dir.join("Procfile")).unwrap();
    }),
    |context| {
        // ...
    },
);

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", "test-fixtures/app")
}

TestRunner::default().build(
    default_config().app_dir("test-fixtures/a-different-app"),
    |context| {
        // ...
    },
);

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", "test-fixtures/app")
        .expected_pack_result(PackResult::Failure),
    |context| {
        assert_contains!(context.pack_stderr, "ERROR: Invalid Procfile!");
    },
);

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more