From 6f4d624ed352974d5d9496fc25a46b4ad95e6070 Mon Sep 17 00:00:00 2001 From: "Sean P. Kelly" Date: Thu, 1 Aug 2024 20:20:55 +0000 Subject: [PATCH] testsys: update log reader to use AsyncBufRead --- tools/testsys/src/logs.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testsys/src/logs.rs b/tools/testsys/src/logs.rs index d63dd81bf..c71516051 100644 --- a/tools/testsys/src/logs.rs +++ b/tools/testsys/src/logs.rs @@ -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; @@ -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()}),