diff --git a/CHANGELOG.md b/CHANGELOG.md index a551483f..14fbb65a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ separate changelogs for each crate were used. If you need to refer to these old - `TestRunner::new` has been removed, since its only purpose was for advanced configuration that's no longer applicable. Use `TestRunner::default` instead. ([#620](https://github.com/heroku/libcnb.rs/pull/620)) - `LogOutput` no longer exposes `stdout_raw` and `stderr_raw`. ([#607](https://github.com/heroku/libcnb.rs/pull/607)) - Improved wording of panic error messages. ([#619](https://github.com/heroku/libcnb.rs/pull/619) and [#620](https://github.com/heroku/libcnb.rs/pull/620)) + - If a test with an expected result of `PackResult::Failure` unexpectedly succeeds, the built app image is now correctly cleaned up. ([#625](https://github.com/heroku/libcnb.rs/pull/625)) - `libcnb-package`: buildpack target directory now contains the target triple. Users that implicitly rely on the output directory need to adapt. The output of `cargo libcnb package` will refer to the new locations. ([#580](https://github.com/heroku/libcnb.rs/pull/580)) - `libherokubuildpack`: Switch the `flate2` decompression backend from `miniz_oxide` to `zlib`. ([#593](https://github.com/heroku/libcnb.rs/pull/593)) - Bump minimum external dependency versions. ([#587](https://github.com/heroku/libcnb.rs/pull/587)) diff --git a/libcnb-test/src/test_runner.rs b/libcnb-test/src/test_runner.rs index cb481762..d88c9c2d 100644 --- a/libcnb-test/src/test_runner.rs +++ b/libcnb-test/src/test_runner.rs @@ -1,3 +1,4 @@ +use crate::docker::DockerRemoveImageCommand; use crate::pack::PackBuildCommand; use crate::util::CommandError; use crate::{ @@ -114,15 +115,21 @@ impl TestRunner { }; } - let output = match ( - &config.expected_pack_result, - util::run_command(pack_command), - ) { + let pack_result = util::run_command(pack_command); + + let output = match (&config.expected_pack_result, pack_result) { (PackResult::Success, Ok(output)) => output, (PackResult::Failure, Err(CommandError::NonZeroExitCode { stdout, stderr, .. })) => { LogOutput { stdout, stderr } } (PackResult::Failure, Ok(LogOutput { stdout, stderr })) => { + // Ordinarily the Docker image created by `pack build` will either be cleaned up by + // `TestContext::Drop` later on, or will not have been created in the first place, + // if the `pack build` was not successful. However, in the case of an unexpectedly + // successful `pack build` we have to clean this image up manually before `panic`ing. + util::run_command(DockerRemoveImageCommand::new(image_name)).unwrap_or_else( + |command_err| panic!("Error removing Docker image:\n\n{command_err}"), + ); panic!("The pack build was expected to fail, but did not:\n\n## stderr:\n\n{stderr}\n## stdout:\n\n{stdout}\n"); } (_, Err(command_err)) => {