Skip to content

Commit

Permalink
testsys: update log reader to use AsyncBufRead
Browse files Browse the repository at this point in the history
  • Loading branch information
cbgbt authored and gthao313 committed Aug 2, 2024
1 parent e98905a commit 6f4d624
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tools/testsys/src/logs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::{self, Result};
use clap::Parser;
use futures::TryStreamExt;
use snafu::OptionExt;
use futures::{AsyncBufReadExt, TryStreamExt};
use snafu::{OptionExt, ResultExt};
use testsys_model::test_manager::{ResourceState, TestManager};
use unescape::unescape;

Expand Down Expand Up @@ -29,15 +29,15 @@ impl Logs {
pub(crate) async fn run(self, client: TestManager) -> Result<()> {
match (self.test, self.resource, self.resource_state) {
(Some(test), None, None) => {
let mut logs = client.test_logs(test, self.follow).await?;
while let Some(line) = logs.try_next().await? {
println!("{}", unescape(&String::from_utf8_lossy(&line)).context(error::InvalidSnafu{what: "Unable to unescape log string"})?);
let mut logs = client.test_logs(test, self.follow).await?.lines();
while let Some(line) = logs.try_next().await.context(error::IOSnafu { what: "Failed to read test logs".to_string()})? {
println!("{}", unescape(&line).context(error::InvalidSnafu { what: "Unable to unescape log string"})?);
}
}
(None, Some(resource), Some(state)) => {
let mut logs = client.resource_logs(resource, state, self.follow).await?;
while let Some(line) = logs.try_next().await? {
println!("{}", unescape(&String::from_utf8_lossy(&line)).context(error::InvalidSnafu{what: "Unable to unescape log string"})?);
let mut logs = client.resource_logs(resource, state, self.follow).await?.lines();
while let Some(line) = logs.try_next().await.context(error::IOSnafu { what: "Failed to read test logs".to_string()})? {
println!("{}", unescape(&line).context(error::InvalidSnafu { what: "Unable to unescape log string"})?);
}
}
_ => return Err(error::Error::Invalid{what: "Invalid arguments were provided. Exactly one of `--test` or `--resource` must be given.".to_string()}),
Expand Down

0 comments on commit 6f4d624

Please sign in to comment.