Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion src/root/ifconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ fn run_command(cmd: &str, args: &[&str]) -> Result<bool> {
mod tests {
use std::{
path::{Path, PathBuf},
time::{SystemTime, UNIX_EPOCH},
time::{Duration, SystemTime, UNIX_EPOCH},
};

use super::*;
Expand Down Expand Up @@ -684,6 +684,59 @@ mod tests {
fs::remove_dir_all(&dir).expect("temp test directory should be removable");
}

const LIST_FILES_MTIME_CHILD_ENV: &str = "ROXY_LIST_FILES_MTIME_CHILD";

#[test]
fn list_files_formats_modified_time_in_local_timezone() {
if std::env::var_os(LIST_FILES_MTIME_CHILD_ENV).is_some() {
let dir = make_temp_test_dir("list-mtime");
let file_path = dir.join("fixed.yaml");
write_text_file(&file_path, "fixed");

let ts = UNIX_EPOCH + Duration::from_secs(1_700_000_000);
let file = OpenOptions::new()
.write(true)
.open(&file_path)
.expect("test file should be openable for timestamp update");
file.set_modified(ts)
.expect("test file modified time should be settable");

let listed = list_files(
dir.to_str().expect("temp path should be valid utf-8"),
None,
false,
)
.expect("listing files should succeed");
assert_eq!(
listed,
vec![(
5,
"2023/11/14 22:13:20".to_string(),
"fixed.yaml".to_string()
)]
);

fs::remove_dir_all(&dir).expect("temp test directory should be removable");
return;
}

let output = std::process::Command::new(
std::env::current_exe().expect("current test executable should be available"),
)
.arg("list_files_formats_modified_time_in_local_timezone")
.env(LIST_FILES_MTIME_CHILD_ENV, "1")
.env("TZ", "UTC")
.output()
.expect("child test process should run");

assert!(
output.status.success(),
"child test process should pass\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}

#[test]
fn list_files_fails_for_missing_directory() {
let dir = make_temp_test_dir("list-missing");
Expand Down