Skip to content

Commit

Permalink
added tests for remove and is_storage_updated fn
Browse files Browse the repository at this point in the history
Signed-off-by: Pushkar Mishra <[email protected]>
  • Loading branch information
Pushkarm029 committed Apr 19, 2024
1 parent f874f79 commit 150366a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions fs-storage/src/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,15 @@ mod tests {
FileStorage::new("TestStorage".to_string(), &storage_path);

file_storage.set("key1".to_string(), "value1".to_string());
file_storage.set("key1".to_string(), "value2".to_string());
file_storage.set("key2".to_string(), "value2".to_string());

assert!(file_storage.remove(&"key1".to_string()).is_ok());
let data_read: BTreeMap<_, _> = file_storage
.read_fs()
.expect("Failed to read data from disk");

assert_eq!(data_read.len(), 1);
assert_eq!(data_read.get("key1").map(|v| v.as_str()), Some("value2"))
assert_eq!(data_read.get("key2").map(|v| v.as_str()), Some("value2"))
}

#[test]
Expand All @@ -225,4 +226,28 @@ mod tests {
}
assert_eq!(storage_path.exists(), false);
}

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

let mut file_storage =
FileStorage::new("TestStorage".to_string(), &storage_path);

file_storage.set("key1".to_string(), "value1".to_string());
assert_eq!(file_storage.is_storage_updated().unwrap(), false);

std::thread::sleep(std::time::Duration::from_secs(1));

// External data manipulation
let mut file_storage1 =
FileStorage::new("TestStorage".to_string(), &storage_path);

file_storage1.set("key1".to_string(), "value3".to_string());
assert_eq!(file_storage1.is_storage_updated().unwrap(), false);

assert_eq!(file_storage.is_storage_updated().unwrap(), true);
}
}

0 comments on commit 150366a

Please sign in to comment.