From fa5468be4abe791787bf5330cb8098d28db14df5 Mon Sep 17 00:00:00 2001 From: veeso Date: Sat, 9 Jan 2021 14:29:30 +0100 Subject: [PATCH] Fixed time check tests --- src/filetransfer/ftp_transfer.rs | 22 +++++++--------------- src/utils/parser.rs | 31 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/filetransfer/ftp_transfer.rs b/src/filetransfer/ftp_transfer.rs index 3fecf55..5c94875 100644 --- a/src/filetransfer/ftp_transfer.rs +++ b/src/filetransfer/ftp_transfer.rs @@ -705,6 +705,7 @@ impl FileTransfer for FtpFileTransfer { mod tests { use super::*; + use crate::utils::fmt::fmt_time; use std::time::Duration; #[test] @@ -778,25 +779,16 @@ mod tests { assert_eq!(file.group, Some(9)); assert_eq!(file.unix_pex.unwrap(), (7, 5, 5)); assert_eq!( - file.last_access_time - .duration_since(SystemTime::UNIX_EPOCH) - .ok() - .unwrap(), - Duration::from_secs(1604593920) + fmt_time(file.last_access_time, "%m %d %M").as_str(), + "11 05 32" ); assert_eq!( - file.last_change_time - .duration_since(SystemTime::UNIX_EPOCH) - .ok() - .unwrap(), - Duration::from_secs(1604593920) + fmt_time(file.last_change_time, "%m %d %M").as_str(), + "11 05 32" ); assert_eq!( - file.creation_time - .duration_since(SystemTime::UNIX_EPOCH) - .ok() - .unwrap(), - Duration::from_secs(1604593920) + fmt_time(file.creation_time, "%m %d %M").as_str(), + "11 05 32" ); } else { panic!("Expected file, got directory"); diff --git a/src/utils/parser.rs b/src/utils/parser.rs index a502024..5f7f776 100644 --- a/src/utils/parser.rs +++ b/src/utils/parser.rs @@ -200,6 +200,7 @@ pub fn parse_datetime(tm: &str, fmt: &str) -> Result { mod tests { use super::*; + use crate::utils::fmt::fmt_time; #[test] fn test_utils_parse_remote_opt() { @@ -294,22 +295,24 @@ mod tests { fn test_utils_parse_lstime() { // Good cases assert_eq!( - parse_lstime("Nov 5 16:32", "%b %d %Y", "%b %d %H:%M") - .ok() - .unwrap() - .duration_since(SystemTime::UNIX_EPOCH) - .ok() - .unwrap(), - Duration::from_secs(1604593920) + fmt_time( + parse_lstime("Nov 5 16:32", "%b %d %Y", "%b %d %H:%M") + .ok() + .unwrap(), + "%m %d %M" + ) + .as_str(), + "11 05 32" ); assert_eq!( - parse_lstime("Dec 2 21:32", "%b %d %Y", "%b %d %H:%M") - .ok() - .unwrap() - .duration_since(SystemTime::UNIX_EPOCH) - .ok() - .unwrap(), - Duration::from_secs(1606944720) + fmt_time( + parse_lstime("Dec 2 21:32", "%b %d %Y", "%b %d %H:%M") + .ok() + .unwrap(), + "%m %d %M" + ) + .as_str(), + "12 02 32" ); assert_eq!( parse_lstime("Nov 5 2018", "%b %d %Y", "%b %d %H:%M")