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

libcnb-test: Stop exposing raw output in LogOutput #607

Merged
merged 1 commit into from
Jul 26, 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
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(),
}
})
}