Skip to content

Commit 6009d68

Browse files
committed
tests: ignore the index while testing caches purging
1 parent d2a9e73 commit 6009d68

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tests/integration/purge_caches.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,32 @@ fn test_purge_caches() -> Result<(), Error> {
4848
Ok(())
4949
}
5050

51+
/// Define which files should be ignored when comparing the two workspaces. If there are expected
52+
/// changes, update the function to match them.
53+
fn should_ignore(base: &Path, path: &Path) -> bool {
54+
let components = match path.strip_prefix(base) {
55+
Ok(stripped) => stripped
56+
.components()
57+
.map(|component| component.as_os_str().to_string_lossy().to_string())
58+
.collect::<Vec<_>>(),
59+
Err(_) => return false,
60+
};
61+
62+
let components = components.iter().map(|c| c.as_str()).collect::<Vec<_>>();
63+
match components.as_slice() {
64+
// The indexes could be updated during the build. The index is not considered a cache
65+
// though, so it's fine to ignore it during the comparison.
66+
["cargo-home", "registry", "index", _, ".git", ..] => true,
67+
["cargo-home", "registry", "index", _, ".cargo-index-lock"] => true,
68+
["cargo-home", "registry", "index", _, ".last-updated"] => true,
69+
70+
_ => false,
71+
}
72+
}
73+
5174
#[derive(Debug, PartialEq, Eq)]
5275
struct WorkspaceContents {
76+
base: PathBuf,
5377
files: HashMap<PathBuf, Digest>,
5478
}
5579

@@ -69,7 +93,10 @@ impl WorkspaceContents {
6993
files.insert(entry.path().into(), sha.digest());
7094
}
7195

72-
Ok(Self { files })
96+
Ok(Self {
97+
base: path.into(),
98+
files,
99+
})
73100
}
74101

75102
fn assert_same(self, mut other: Self) {
@@ -78,6 +105,10 @@ impl WorkspaceContents {
78105
println!("=== start directory differences ===");
79106

80107
for (path, start_digest) in self.files.into_iter() {
108+
if should_ignore(&self.base, &path) {
109+
continue;
110+
}
111+
81112
if let Some(end_digest) = other.files.remove(&path) {
82113
if start_digest != end_digest {
83114
println!("file {} changed", path.display());
@@ -90,6 +121,10 @@ impl WorkspaceContents {
90121
}
91122

92123
for (path, _) in other.files.into_iter() {
124+
if should_ignore(&other.base, &path) {
125+
continue;
126+
}
127+
93128
println!("file {} was added", path.display());
94129
same = false;
95130
}

0 commit comments

Comments
 (0)