Expand description

libcnb-test   Docs Latest Version MSRV

An experimental integration testing framework for Cloud Native Buildpacks written in Rust with libcnb.rs.

Experimental

This crate is marked as experimental. It currently implements the most basic building blocks for writing integration tests with libcnb.rs. Its feature set is deliberately cut down to get ball rolling and get a better feel which features are required. See issues tagged with libcnb-test for possible future improvements. Please use the same tag for feature requests.

Example

// In $CRATE_ROOT/tests/integration_test.rs
use libcnb_test::{assert_contains, TestConfig, TestRunner};

// In your code you'll want to mark your function as a test with `#[test]`.
// It is removed here for compatibility with doctest so this code in the readme
// tests for compilation.
fn test() {
    TestRunner::default().run_test(
        TestConfig::new("heroku/builder:22", "test-fixtures/app"),
        |context| {
            assert_contains!(context.pack_stdout, "---> Maven Buildpack");
            assert_contains!(context.pack_stdout, "---> Installing Maven");
            assert_contains!(context.pack_stdout, "---> Running mvn package");

            context
                .prepare_container()
                .expose_port(12345)
                .start_with_default_process(|container| {
                    assert_eq!(
                        call_test_fixture_service(
                            container.address_for_port(12345).unwrap(),
                            "Hagbard Celine"
                        )
                        .unwrap(),
                        "enileC drabgaH"
                    );
                });
        },
    );
}

fn call_test_fixture_service(addr: std::net::SocketAddr, payload: &str) -> Result<String, ()> {
    unimplemented!()
}

Known issues

Macros

Asserts that left contains right.

Asserts that the provided value is empty.

Asserts that left does not contain right.

Structs

Context of a launched container.

Container log output.

Context for preparing a container.

Configuration for a test.

Context for a currently executing test.

Runner for libcnb integration tests.

Enums

References a Cloud Native Buildpack.

The profile to use when invoking Cargo.

Result of a pack execution.