Skip to content

Commit

Permalink
try to isolate the error
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Jun 11, 2024
1 parent 3831efc commit e932049
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions fs-storage/src/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,31 +359,38 @@ mod tests {
assert!(!storage_path.exists());
}

use std::io::Write;

#[test]
fn test_file_metadata_timestamp_updated() {
// Create a temporary file
let temp_dir =
TempDir::new("tmp").expect("Failed to create temporary directory");
let storage_path = temp_dir.path().join("teststorage.txt");
let storage_path = temp_dir.path().join("test_storage.txt");

let mut file_storage =
FileStorage::new("TestStorage".to_string(), &storage_path).unwrap();
file_storage.write_fs().unwrap();
// Write to the file using write_all adn flush
let mut file =
fs::File::create(&storage_path).expect("Failed to create file");
file.write_all(b"test1")
.expect("Failed to write to file");
file.flush().expect("Failed to flush file");

file_storage.set("key1".to_string(), "value1".to_string());
let before_write = fs::metadata(&storage_path)
.unwrap()
let timestamp_before = fs::metadata(&storage_path)
.expect("Failed to get metadata")
.modified()
.unwrap();
file_storage.write_fs().unwrap();
let after_write = fs::metadata(&storage_path)
.unwrap()
.expect("Failed to get modified time");

// write to the file again
file.write_all(b"test2")
.expect("Failed to write to file");
file.flush().expect("Failed to flush file");

let timestamp_after = fs::metadata(&storage_path)
.expect("Failed to get metadata")
.modified()
.unwrap();
println!(
"before_write: {:?}, after_write: {:?}",
before_write, after_write
);
assert!(before_write < after_write);
.expect("Failed to get modified time");

assert!(timestamp_after > timestamp_before);
}

#[test]
Expand Down

0 comments on commit e932049

Please sign in to comment.