From 67d30b8ad6e8b8479623ef86d15d1acee109fa88 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Fri, 21 Jul 2023 13:05:56 +0100 Subject: [PATCH] Stop exposing raw output in `LogOutput` Since: - There are no common use-cases that require raw output, and buildpacks in the wild aren't using these fields (checked using GitHub code search). - It saves beginners from having to think about which `LogOutput` field they should be using. This cleanup has been split out of the future Bollard migration PR. --- CHANGELOG.md | 4 +++- libcnb-test/src/log.rs | 17 ++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e026530..6a411542 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,9 @@ separate changelogs for each crate were used. If you need to refer to these old ### Changed -- `libcnb-test`: `ContainerContext::address_for_port` now returns `SocketAddr` directly instead of `Option`. ([#605](https://github.com/heroku/libcnb.rs/pull/605)) +- `libcnb-test`: + - `ContainerContext::address_for_port` now returns `SocketAddr` directly instead of `Option`. ([#605](https://github.com/heroku/libcnb.rs/pull/605)) + - `LogOutput` no longer exposes `stdout_raw` and `stderr_raw`. ([#607](https://github.com/heroku/libcnb.rs/pull/607)) - `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/log.rs b/libcnb-test/src/log.rs index e8f34de5..ad192c9e 100644 --- a/libcnb-test/src/log.rs +++ b/libcnb-test/src/log.rs @@ -3,8 +3,6 @@ use tokio_stream::{Stream, StreamExt}; /// Container log output. #[derive(Debug, Default)] pub struct LogOutput { - pub stdout_raw: Vec, - pub stderr_raw: Vec, pub stdout: String, pub stderr: String, } @@ -19,15 +17,16 @@ pub(crate) async fn consume_container_log_output< .collect::, E>>() .await .map(|log_output_chunks| { - let mut acc = LogOutput::default(); + let mut stdout_raw = Vec::new(); + let mut stderr_raw = Vec::new(); for log_output_chunk in log_output_chunks { match log_output_chunk { bollard::container::LogOutput::StdOut { message } => { - acc.stdout_raw.append(&mut message.to_vec()); + stdout_raw.append(&mut message.to_vec()); } bollard::container::LogOutput::StdErr { message } => { - acc.stderr_raw.append(&mut message.to_vec()); + stderr_raw.append(&mut message.to_vec()); } unimplemented_message => { unimplemented!("message unimplemented: {unimplemented_message}") @@ -35,9 +34,9 @@ pub(crate) async fn consume_container_log_output< } } - acc.stdout = String::from_utf8_lossy(&acc.stdout_raw).to_string(); - acc.stderr = String::from_utf8_lossy(&acc.stderr_raw).to_string(); - - acc + LogOutput { + stdout: String::from_utf8_lossy(&stdout_raw).to_string(), + stderr: String::from_utf8_lossy(&stderr_raw).to_string(), + } }) }