Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Assert that loading from cache does not over-write files.
  • Loading branch information
schneems committed Oct 16, 2024
1 parent 77fca26 commit f53b4de
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions commons/src/cache/app_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,31 @@ mod tests {
assert_eq!(layer_name!("cache_my_input"), layer);
}

#[test]
fn test_load_doesnot_clobber_files() {
let tmpdir = tempfile::tempdir().unwrap();
let cache_path = tmpdir.path().join("cache");
let app_path = tmpdir.path().join("app");
fs_err::create_dir_all(&cache_path).unwrap();
fs_err::create_dir_all(&app_path).unwrap();

fs_err::write(app_path.join("a.txt"), "app").unwrap();
fs_err::write(cache_path.join("a.txt"), "cache").unwrap();

let store = AppCache {
path: app_path.clone(),
cache: cache_path,
limit: Byte::from_u64(512),
keep_path: KeepPath::Runtime,
cache_state: CacheState::NewEmpty,
};

store.load().unwrap();

let contents = fs_err::read_to_string(app_path.join("a.txt")).unwrap();
assert_eq!("app", contents);
}

#[test]
fn test_copying_back_to_cache() {
let tmpdir = tempfile::tempdir().unwrap();
Expand Down

0 comments on commit f53b4de

Please sign in to comment.