From 466c847426859272786aaf4838659972e14ecaa0 Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Wed, 13 Nov 2024 13:54:13 +0100 Subject: [PATCH] Mock the local time in the test case --- src/slurmjobs.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/slurmjobs.rs b/src/slurmjobs.rs index 22b3cd2..590968f 100644 --- a/src/slurmjobs.rs +++ b/src/slurmjobs.rs @@ -58,7 +58,8 @@ pub fn show_slurm_jobs(window: &Option, span: &Option) { } Ok(sacct_output) => { let mut writer = io::stdout(); - format_jobs(&mut writer, &sacct_output, &field_names); + let local = time::now_local(); + format_jobs(&mut writer, &sacct_output, &field_names, &local); } } } @@ -130,7 +131,7 @@ fn check_ymd(s: &str) -> bool { return k == 3; } -fn format_jobs(writer: &mut dyn io::Write, sacct_output: &str, field_names: &[&str]) { +fn format_jobs(writer: &mut dyn io::Write, sacct_output: &str, field_names: &[&str], local: &libc::tm) { // Fields that are dates that may be reinterpreted before transmission. let date_fields = HashSet::from(["Start", "End", "Submit"]); @@ -163,7 +164,6 @@ fn format_jobs(writer: &mut dyn io::Write, sacct_output: &str, field_names: &[&s // is bound to lead to problems eventually, so reformat. If parsing // fails, just transmit the date and let the consumer deal with it. if let Ok(mut t) = time::parse_date_and_time_no_tzo(&val) { - let local = time::now_local(); t.tm_gmtoff = local.tm_gmtoff; t.tm_isdst = local.tm_isdst; // If t.tm_zone is not null then it must point to static data, so @@ -285,7 +285,11 @@ pub fn test_format_jobs() { "#; let mut output = Vec::new(); - format_jobs(&mut output, sacct_output, &field_names); + let mut local = time::now_local(); + // The output below depends on us being in UTC+01:00 and not in dst so mock that. + local.tm_gmtoff = 3600; + local.tm_isdst = 0; + format_jobs(&mut output, sacct_output, &field_names, &local); // The golang `sacctd` output for the above input. let expected = r#"v=0.1.0,JobID=973821,JobIDRaw=973821,User=ec-aaaaa,Account=ec85,State=COMPLETED,Start=2024-11-13T11:08:00+01:00,End=2024-11-13T13:07:24+01:00,ElapsedRaw=7164,ReqCPUS=6,ReqMem=10000M,ReqNodes=1,Submit=2024-11-13T08:30:40+01:00,SystemCPU=22:53.824,TimelimitRaw=400,UserCPU=11:06:33,NodeList=c1-28,Partition=normal,"AllocTRES=billing=6,cpu=6,mem=10000M,node=1",JobName=command