Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more integration tests to libcnb-test #717

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "compile-error"
version = "0.0.0"
publish = false

[workspace]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api = "0.8"

[buildpack]
id = "libcnb-test/compile-error"
version = "0.0.0"

[[stacks]]
id = "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
compile_error!("Example compile error");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "one"
name = "component-a"
version = "0.0.0"
publish = false

[workspace]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "two"
name = "component-b"
version = "0.0.0"
publish = false

[workspace]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
api = "0.8"

[buildpack]
id = "libcnb-test/composite-missing-package-toml"
version = "0.0.0"

[[order]]

[[order.group]]
id = "libcnb-test/a"
version = "0.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ version = "0.0.0"
[[order.group]]
id = "libcnb-test/b"
version = "0.0.0"

[[order.group]]
id = "heroku/procfile"
version = "2.0.2"
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ uri = "libcnb:libcnb-test/a"
[[dependencies]]
uri = "libcnb:libcnb-test/b"

[[dependencies]]
uri = "docker://docker.io/heroku/procfile-cnb:2.0.2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
api = "0.8"

[buildpack]
id = "libcnb-test/invalid-buildpack-toml"
version = "0.0.0"

[[order]]

[[order.group]]
id = "libcnb-test/a"
# `version` is a required field, but is missing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
# `name` and `version` are a required fields, but are missing.

[workspace]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api = "0.8"

[buildpack]
id = "libcnb-test/invalid-cargo-toml"
version = "0.0.0"

[[stacks]]
id = "*"
224 changes: 182 additions & 42 deletions libcnb-test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ use std::{env, fs, panic, thread};
const PROCFILE_URL: &str = "heroku/procfile";
const TEST_PORT: u16 = 12345;

// Note: Since the `libcnb-test` crate isn't a buildpack itself, we can't test a successful
// build using `BuildpackReference::CurrentCrate` here, but we still have test coverage of it
// thanks to the integration tests under `examples/` and `test-buildpacks/`.

#[test]
#[ignore = "integration test"]
fn basic_build() {
fn build_other_buildpack() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/procfile")
.buildpacks([BuildpackReference::Other(String::from(PROCFILE_URL))]),
Expand All @@ -43,6 +47,73 @@ fn basic_build() {
);
}

#[test]
#[ignore = "integration test"]
fn build_workspace_component_buildpack() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/a")),
]),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
indoc! {"
Buildpack A
"}
);
},
);
}

#[test]
#[ignore = "integration test"]
fn build_workspace_composite_buildpack() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/procfile").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/composite")),
]),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
indoc! {"
Buildpack A
Buildpack B

[Discovering process types]
Procfile declares types -> web, worker, echo-args
"}
);
},
);
}

#[test]
#[ignore = "integration test"]
fn build_multiple_buildpacks() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/procfile").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/b")),
BuildpackReference::Other(String::from(PROCFILE_URL)),
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/a")),
]),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
indoc! {"
Buildpack B

[Discovering process types]
Procfile declares types -> web, worker, echo-args
Buildpack A
"}
);
},
);
}

#[test]
#[ignore = "integration test"]
fn rebuild() {
Expand All @@ -64,7 +135,7 @@ fn rebuild() {

#[test]
#[ignore = "integration test"]
fn buildpack_packaging_failure() {
fn packaging_failure_missing_buildpack_toml() {
let err = panic::catch_unwind(|| {
TestRunner::default().build(BuildConfig::new("invalid!", "tests/fixtures/empty"), |_| {
unreachable!("The test should panic prior to the TestContext being invoked.");
Expand All @@ -81,6 +152,114 @@ fn buildpack_packaging_failure() {
);
}

#[test]
#[ignore = "integration test"]
// TODO: Fix the implementation to return the correct error message (that the buildpack.toml doesn't match the schema):
// https://github.com/heroku/libcnb.rs/issues/708
#[should_panic(
expected = "Could not package directory as buildpack! No buildpack with id `libcnb-test/invalid-buildpack-toml` exists in the workspace at"
)]
fn packaging_failure_invalid_buildpack_toml() {
TestRunner::default().build(
BuildConfig::new("invalid!", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!(
"libcnb-test/invalid-buildpack-toml"
)),
]),
|_| {
unreachable!("The test should panic prior to the TestContext being invoked.");
},
);
}

#[test]
#[ignore = "integration test"]
// TODO: Fix the implementation to return the correct error message. Has the same cause as:
// https://github.com/heroku/libcnb.rs/issues/704
#[should_panic(
expected = "Test references buildpack `libcnb-test/composite-missing-package-toml`, but this directory wasn't packaged as a buildpack. This is an internal libcnb-test error, please report any occurrences"
)]
fn packaging_failure_composite_buildpack_missing_package_toml() {
TestRunner::default().build(
BuildConfig::new("invalid!", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!(
"libcnb-test/composite-missing-package-toml"
)),
]),
|_| {
unreachable!("The test should panic prior to the TestContext being invoked.");
},
);
}

#[test]
#[ignore = "integration test"]
// TODO: Fix the implementation to return the correct error message. Has the same cause as:
// https://github.com/heroku/libcnb.rs/issues/704
#[should_panic(
expected = "Test references buildpack `libcnb-test/invalid-cargo-toml`, but this directory wasn't packaged as a buildpack. This is an internal libcnb-test error, please report any occurrences"
)]
fn packaging_failure_invalid_cargo_toml() {
TestRunner::default().build(
BuildConfig::new("invalid!", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/invalid-cargo-toml")),
]),
|_| {
unreachable!("The test should panic prior to the TestContext being invoked.");
},
);
}

#[test]
#[ignore = "integration test"]
// TODO: Fix the implementation to return the correct error message. Has the same cause as:
// https://github.com/heroku/libcnb.rs/issues/704
#[should_panic(
expected = "Test references buildpack `libcnb-test/compile-error`, but this directory wasn't packaged as a buildpack. This is an internal libcnb-test error, please report any occurrences"
)]
fn packaging_failure_compile_error() {
TestRunner::default().build(
BuildConfig::new("invalid!", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/compile-error")),
]),
|_| {
unreachable!("The test should panic prior to the TestContext being invoked.");
},
);
}

#[test]
#[ignore = "integration test"]
fn packaging_failure_non_existent_workspace_buildpack() {
let err = panic::catch_unwind(|| {
TestRunner::default().build(
BuildConfig::new("invalid!", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("non-existent")),
]),
|_| {
unreachable!("The test should panic prior to the TestContext being invoked.");
},
);
})
.unwrap_err();

assert_eq!(
err.downcast_ref::<String>().unwrap(),
&format!(
"Could not package directory as buildpack! No buildpack with id `non-existent` exists in the workspace at {}",
// There is currently no env var for determining the workspace root directly:
// https://github.com/rust-lang/cargo/issues/3946
env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.unwrap()
.join("../")
.canonicalize()
.unwrap()
.display()
)
);
}

#[test]
#[ignore = "integration test"]
#[should_panic(expected = "Error performing pack build:
Expand Down Expand Up @@ -257,7 +436,7 @@ pack command failed with exit code 1!
ERROR: image 'libcnbtest_")]
fn download_sbom_files_failure() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/empty")
BuildConfig::new("invalid!", "tests/fixtures/empty")
.buildpacks(Vec::new())
.expected_pack_result(PackResult::Failure),
|context| {
Expand Down Expand Up @@ -526,42 +705,3 @@ fn address_for_port_when_container_crashed() {
"}
);
}

#[test]
#[ignore = "integration test"]
fn basic_build_with_libcnb_reference_to_single_buildpack() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/a")),
]),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
indoc! {"
Buildpack A
"}
);
},
);
}

#[test]
#[ignore = "integration test"]
fn basic_build_with_libcnb_reference_to_composite_buildpack() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "tests/fixtures/empty").buildpacks([
BuildpackReference::WorkspaceBuildpack(buildpack_id!("libcnb-test/composite")),
]),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
indoc! {"
Buildpack A
Buildpack B
"}
);
},
);
}