Skip to content

Commit

Permalink
tests: Use similar-asserts
Browse files Browse the repository at this point in the history
I was using this in the previous composefs rust code
and I find it useful. Prep for more testing work.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Dec 8, 2024
1 parent 5049efb commit 1c66049
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ zerocopy = "0.8.13"
zstd = "0.13.2"

[dev-dependencies]
similar-asserts = "1.6.0"

[profile.dev.package.sha2]
# this is *really* slow otherwise
Expand Down
2 changes: 1 addition & 1 deletion src/bin/composefs-pivot-sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn test_parse() {
}
let digest = "8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52";
let digest_bytes = hex::decode(digest).unwrap();
assert_eq!(
similar_asserts::assert_eq!(
parse_composefs_cmdline(format!("composefs={digest}").as_bytes())
.unwrap()
.as_slice(),
Expand Down
14 changes: 7 additions & 7 deletions src/dumpfile_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,15 +784,15 @@ mod tests {
#[test]
fn test_xattr() {
let v = Xattr::parse("foo=bar").unwrap();
assert_eq!(v.key.as_bytes(), b"foo");
assert_eq!(&*v.value, b"bar");
similar_asserts::assert_eq!(v.key.as_bytes(), b"foo");
similar_asserts::assert_eq!(&*v.value, b"bar");
// Invalid embedded NUL in keys
assert!(Xattr::parse("foo\0bar=baz").is_err());
assert!(Xattr::parse("foo\x00bar=baz").is_err());
// But embedded NUL in values is OK
let v = Xattr::parse("security.selinux=bar\x00").unwrap();
assert_eq!(v.key.as_bytes(), b"security.selinux");
assert_eq!(&*v.value, b"bar\0");
similar_asserts::assert_eq!(v.key.as_bytes(), b"security.selinux");
similar_asserts::assert_eq!(&*v.value, b"bar\0");
}

#[test]
Expand Down Expand Up @@ -829,9 +829,9 @@ mod tests {
if line != serialized {
dbg!(&line, &e, &serialized);
}
assert_eq!(line, serialized);
similar_asserts::assert_eq!(line, serialized);
let e2 = Entry::parse(&serialized).unwrap();
assert_eq!(e, e2);
similar_asserts::assert_eq!(e, e2);
}
}

Expand Down Expand Up @@ -875,7 +875,7 @@ mod tests {
Ok(())
})
.unwrap();
assert_eq!(SPECIAL_DUMP, &entries);
similar_asserts::assert_eq!(SPECIAL_DUMP, &entries);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/fsverity/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod tests {
#[test]
fn test_digest() -> Result<()> {
let digest = FsVerityHasher::hash(b"hello world");
assert_eq!(
similar_asserts::assert_eq!(
digest,
[
30, 46, 170, 66, 2, 215, 80, 164, 17, 116, 238, 69, 73, 112, 185, 44, 27, 194, 249,
Expand Down
2 changes: 1 addition & 1 deletion src/oci/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn assert_files(fs: &FileSystem, expected: &[&str]) -> Result<()> {
.map(|line| line.unwrap().split_once(' ').unwrap().0.into())
.collect();

assert_eq!(actual, expected);
similar_asserts::assert_eq!(actual, expected);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion tests/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn test_layer() -> Result<()> {
while let Some(entry) = oci::tar::get_entry(&mut split_stream)? {
writeln!(dump, "{}", entry)?;
}
assert_eq!(dump, "\
similar_asserts::assert_eq!(dump, "\
/file0 0 100700 1 0 0 0 0.0 - - -
/file4095 4095 100700 1 0 0 0 0.0 53/72beb83c78537c8970c8361e3254119fafdf1763854ecd57d3f0fe2da7c719 - 5372beb83c78537c8970c8361e3254119fafdf1763854ecd57d3f0fe2da7c719
/file4096 4096 100700 1 0 0 0 0.0 ba/bc284ee4ffe7f449377fbf6692715b43aec7bc39c094a95878904d34bac97e - babc284ee4ffe7f449377fbf6692715b43aec7bc39c094a95878904d34bac97e
Expand Down

0 comments on commit 1c66049

Please sign in to comment.