Skip to content

Commit 4ef2112

Browse files
committed
test: separate how tests log
1 parent 7ccb730 commit 4ef2112

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

crates/wykies-server-test-helper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = "Provides supporting code for running integration tests"
88
[dependencies]
99
anyhow.workspace = true
1010
argon2 = { workspace = true, features = ["std"] }
11+
chrono.workspace = true
1112
rand = { workspace = true, features = ["std_rng"] }
1213
serde.workspace = true
1314
sqlx = { workspace = true, features = ["runtime-tokio", "macros", "mysql", "chrono", "migrate"] }

crates/wykies-server-test-helper/src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use argon2::PasswordHasher;
66
use serde::de::DeserializeOwned;
77
use sqlx::{Connection, Executor};
88
use std::fmt::Debug;
9+
use std::fs::{create_dir_all, File};
910
use std::ops::Deref;
11+
use std::path::PathBuf;
1012
use std::sync::LazyLock;
1113
use uuid::Uuid;
1214
use wykies_server::Configuration;
@@ -19,7 +21,7 @@ use wykies_shared::{
1921
db_types::{DbConnection, DbPool},
2022
host_branch::HostBranchPair,
2123
req_args::LoginReqArgs,
22-
telemetry::{self, get_subscriber, init_subscriber},
24+
telemetry::{get_subscriber, init_subscriber},
2325
uac::Username,
2426
};
2527
use wykies_time::Seconds;
@@ -33,13 +35,26 @@ pub static TRACING: LazyLock<String> = LazyLock::new(|| {
3335
let default_filter_level = "info".to_string();
3436
let subscriber_name = "test".to_string();
3537
if std::env::var("TEST_LOG").is_ok() {
36-
let log_file_name = format!("server_tests{}", Uuid::new_v4());
37-
let (file, path) = telemetry::create_trace_file(&log_file_name).unwrap();
38+
let log_file_name = format!(
39+
"{}_server_tests{}.log",
40+
chrono::Local::now().format("%Y-%m-%dT%H-%M-%S"),
41+
Uuid::new_v4()
42+
);
43+
let log_folder = PathBuf::from("traces");
44+
create_dir_all(&log_folder)
45+
.context("Failed to create logging folder")
46+
.unwrap();
47+
let file_path = log_folder.join(&log_file_name);
48+
let file = File::create(&file_path)
49+
.with_context(|| format!("Failed to create log file: {file_path:?}"))
50+
.unwrap();
51+
3852
let subscriber = get_subscriber(subscriber_name, default_filter_level, file);
3953
init_subscriber(subscriber).unwrap();
4054
format!(
4155
"Traces for tests being written to: {:?}",
42-
path.canonicalize()
56+
file_path
57+
.canonicalize()
4358
.context("trace file canonicalization failed")
4459
.unwrap()
4560
)

0 commit comments

Comments
 (0)