summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2025-01-09 14:20:35 +0100
committerSebastian Holmin <sebastian.holmin@mullvad.net>2025-01-09 14:20:35 +0100
commitb01de0b0898a8104d2991278d899e9e673b03517 (patch)
tree059006326e531c66762b064b7a43e4a59ebcc9d7
parentaf606551507a95671264979c8a5ca537b33e8a3c (diff)
parenta88510aca8c2b45abb4e13443b31cd1944dc0d4a (diff)
downloadmullvadvpn-b01de0b0898a8104d2991278d899e9e673b03517.tar.xz
mullvadvpn-b01de0b0898a8104d2991278d899e9e673b03517.zip
Merge branch 'start-of-settingsjson-is-missing-from-debug-print-in-test-des-1610'
-rw-r--r--test/test-runner/src/logging.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/test/test-runner/src/logging.rs b/test/test-runner/src/logging.rs
index 2fb8939002..706ff2eed3 100644
--- a/test/test-runner/src/logging.rs
+++ b/test/test-runner/src/logging.rs
@@ -78,7 +78,7 @@ async fn read_settings_file() -> Result<String, Error> {
let mut settings_path = mullvad_paths::get_default_settings_dir()
.map_err(|error| Error::Logs(format!("{}", error)))?;
settings_path.push("settings.json");
- read_truncated(&settings_path)
+ read_truncated(&settings_path, None)
.await
.map_err(|error| Error::Logs(format!("{}: {}", settings_path.display(), error)))
}
@@ -91,7 +91,7 @@ async fn read_log_files() -> Result<Vec<Result<LogFile, Error>>, Error> {
.map_err(|error| Error::Logs(format!("{}", error)))?;
let mut log_files = Vec::new();
for path in paths {
- let log_file = read_truncated(&path)
+ let log_file = read_truncated(&path, Some(TRUNCATE_LOG_FILE_LINES))
.await
.map_err(|error| Error::Logs(format!("{}: {}", path.display(), error)))
.map(|content| LogFile {
@@ -123,17 +123,19 @@ async fn list_logs<T: AsRef<Path>>(log_dir: T) -> Result<Vec<PathBuf>, Error> {
Ok(paths)
}
-async fn read_truncated<T: AsRef<Path>>(path: T) -> io::Result<String> {
+/// Read the contents of a file to string, optionally truncating the result by given amount of lines.
+async fn read_truncated<T: AsRef<Path>>(
+ path: T,
+ truncate_lines: Option<usize>,
+) -> io::Result<String> {
let mut output = vec![];
let reader = BufReader::new(File::open(path).await?);
let mut lines = reader.lines();
while let Some(line) = lines.next_line().await? {
output.push(line);
}
- if output.len() > TRUNCATE_LOG_FILE_LINES {
- let drop_count = output.len() - TRUNCATE_LOG_FILE_LINES;
- // not the most efficient
- output.drain(0..drop_count);
+ if let Some(max_number_of_lines) = truncate_lines {
+ output.truncate(max_number_of_lines);
}
Ok(output.join("\n"))
}