Skip to content

Commit

Permalink
test: avoid lossy string conversions
Browse files Browse the repository at this point in the history
We can be strict in tests.
  • Loading branch information
tamird committed Aug 24, 2023
1 parent ff8c124 commit 572d047
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
43 changes: 18 additions & 25 deletions aya-obj/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,15 +1642,12 @@ mod tests {

let prog_foo = obj.programs.get("foo").unwrap();

assert_matches!(
prog_foo,
Program {
license,
kernel_version: None,
section: ProgramSection::KProbe { .. },
..
} if license.to_str().unwrap() == "GPL"
);
assert_matches!(prog_foo, Program {
license,
kernel_version: None,
section: ProgramSection::KProbe { .. },
..
} => assert_eq!(license.to_str().unwrap(), "GPL"));

assert_matches!(
obj.functions.get(&prog_foo.function_key()),
Expand Down Expand Up @@ -1704,14 +1701,12 @@ mod tests {
let prog_bar = obj.programs.get("bar").unwrap();
let function_bar = obj.functions.get(&prog_bar.function_key()).unwrap();

assert_matches!(prog_foo,
Program {
license,
kernel_version: None,
section: ProgramSection::KProbe { .. },
..
} if license.to_string_lossy() == "GPL"
);
assert_matches!(prog_foo, Program {
license,
kernel_version: None,
section: ProgramSection::KProbe { .. },
..
} => assert_eq!(license.to_str().unwrap(), "GPL"));
assert_matches!(
function_foo,
Function {
Expand All @@ -1724,14 +1719,12 @@ mod tests {
} if name == "foo" && instructions.len() == 1
);

assert_matches!(prog_bar,
Program {
license,
kernel_version: None,
section: ProgramSection::KProbe { .. },
..
} if license.to_string_lossy() == "GPL"
);
assert_matches!(prog_bar, Program {
license,
kernel_version: None,
section: ProgramSection::KProbe { .. },
..
} => assert_eq!(license.to_str().unwrap(), "GPL"));
assert_matches!(
function_bar,
Function {
Expand Down
2 changes: 1 addition & 1 deletion aya/src/sys/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,6 @@ mod tests {
TCA_BPF_NAME as u16
);
let name = CStr::from_bytes_with_nul(inner.data).unwrap();
assert_eq!(name.to_string_lossy(), "foo");
assert_eq!(name.to_str().unwrap(), "foo");
}
}

0 comments on commit 572d047

Please sign in to comment.