From a06c393716e0f163b861516fcef47db437734ed4 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 27 Aug 2024 22:14:20 -0700 Subject: [PATCH] tests: use canonicalized paths in `TestBackend` In `TestBackend`, we simply use the path as key to look up the storage in memory. That means we can't rely on the file system to look find the same path given two different representaitons of the same path. We therefore need to canonicalize the paths if we want to allow the caller to pass in different paths for the same real path. --- lib/testutils/src/test_backend.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/testutils/src/test_backend.rs b/lib/testutils/src/test_backend.rs index fe3cd9dee..c4e9ac115 100644 --- a/lib/testutils/src/test_backend.rs +++ b/lib/testutils/src/test_backend.rs @@ -57,6 +57,10 @@ const CHANGE_ID_LENGTH: usize = 16; static BACKEND_DATA: OnceLock>>>> = OnceLock::new(); +// Keyed by canonical store path. Since we just use the path as a key, we can't +// rely on on the file system to resolve two different uncanonicalized paths to +// the same real path (as we would if we just used the path with `std::fs` +// functions). fn backend_data() -> &'static Mutex>>> { BACKEND_DATA.get_or_init(|| Mutex::new(HashMap::new())) } @@ -95,7 +99,7 @@ impl TestBackend { backend_data() .lock() .unwrap() - .insert(store_path.to_path_buf(), data.clone()); + .insert(store_path.canonicalize().unwrap(), data.clone()); TestBackend { root_commit_id, root_change_id, @@ -108,7 +112,7 @@ impl TestBackend { let data = backend_data() .lock() .unwrap() - .get(store_path) + .get(&store_path.canonicalize().unwrap()) .unwrap() .clone(); let root_commit_id = CommitId::from_bytes(&[0; HASH_LENGTH]);