| @@ -1,7 +1,7 @@ | |||||
| use crate::config::ProtocolKind; | use crate::config::ProtocolKind; | ||||
| use crate::protocols; | use crate::protocols; | ||||
| use anyhow::{Context, Result}; | use anyhow::{Context, Result}; | ||||
| use chrono::Utc; | |||||
| use chrono::Local; | |||||
| use reqwest::Client; | use reqwest::Client; | ||||
| use reqwest::header::HeaderMap; | use reqwest::header::HeaderMap; | ||||
| use serde::Serialize; | use serde::Serialize; | ||||
| @@ -102,7 +102,7 @@ impl RawDebugConfig { | |||||
| } | } | ||||
| async fn write_debug_file(&self, response_kind: &str, contents: &str) -> Result<PathBuf> { | async fn write_debug_file(&self, response_kind: &str, contents: &str) -> Result<PathBuf> { | ||||
| let now = Utc::now(); | |||||
| let now = Local::now(); | |||||
| let dated_output_dir = self.output_dir.join(now.format("%Y%m%d").to_string()); | let dated_output_dir = self.output_dir.join(now.format("%Y%m%d").to_string()); | ||||
| tokio::fs::create_dir_all(&dated_output_dir) | tokio::fs::create_dir_all(&dated_output_dir) | ||||
| .await | .await | ||||
| @@ -113,7 +113,7 @@ impl RawDebugConfig { | |||||
| ) | ) | ||||
| })?; | })?; | ||||
| let sequence = self.counter.fetch_add(1, Ordering::Relaxed) + 1; | let sequence = self.counter.fetch_add(1, Ordering::Relaxed) + 1; | ||||
| let timestamp = now.format("%Y%m%dT%H%M%S%.3fZ"); | |||||
| let timestamp = now.format("%Y%m%dT%H%M%S%.3f%z"); | |||||
| let filename = format!( | let filename = format!( | ||||
| "{}-{}-{sequence:06}-{}.txt", | "{}-{}-{sequence:06}-{}.txt", | ||||
| self.prefix, | self.prefix, | ||||
| @@ -324,4 +324,25 @@ mod tests { | |||||
| assert!(components[0].chars().all(|ch| ch.is_ascii_digit())); | assert!(components[0].chars().all(|ch| ch.is_ascii_digit())); | ||||
| assert!(components[1].ends_with("-response-kind.txt")); | assert!(components[1].ends_with("-response-kind.txt")); | ||||
| } | } | ||||
| #[tokio::test] | |||||
| async fn raw_debug_uses_local_time_for_directory_and_filename() { | |||||
| let temp_dir = tempfile::tempdir().expect("create temp dir"); | |||||
| let raw_debug = RawDebugConfig::new(temp_dir.path().join("debug"), "model/test".into()); | |||||
| let path = raw_debug | |||||
| .write_response("response-kind", "body") | |||||
| .await | |||||
| .expect("write debug response"); | |||||
| let local_now = chrono::Local::now(); | |||||
| let local_date = local_now.format("%Y%m%d").to_string(); | |||||
| let local_hour_prefix = local_now.format("%Y%m%dT%H").to_string(); | |||||
| let filename = path.file_name().expect("debug filename").to_string_lossy(); | |||||
| assert!(path.starts_with(temp_dir.path().join("debug").join(local_date))); | |||||
| assert!(filename.contains(&local_hour_prefix)); | |||||
| assert!(filename.contains(&local_now.format("%z").to_string())); | |||||
| assert!(!filename.contains('Z')); | |||||
| } | |||||
| } | } | ||||