Skip to content

Commit

Permalink
libcnb-test: Stop exposing raw output in LogOutput (#607)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edmorley authored Jul 26, 2023
1 parent 39fa928 commit cd1291e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketAddr>`. ([#605](https://github.com/heroku/libcnb.rs/pull/605))
- `libcnb-test`:
- `ContainerContext::address_for_port` now returns `SocketAddr` directly instead of `Option<SocketAddr>`. ([#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))
Expand Down
17 changes: 8 additions & 9 deletions libcnb-test/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use tokio_stream::{Stream, StreamExt};
/// Container log output.
#[derive(Debug, Default)]
pub struct LogOutput {
pub stdout_raw: Vec<u8>,
pub stderr_raw: Vec<u8>,
pub stdout: String,
pub stderr: String,
}
Expand All @@ -19,25 +17,26 @@ pub(crate) async fn consume_container_log_output<
.collect::<Result<Vec<bollard::container::LogOutput>, 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}")
}
}
}

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(),
}
})
}

0 comments on commit cd1291e

Please sign in to comment.