test: avoid lossy string conversions

We can be strict in tests.
reviewable/pr742/r9
Tamir Duberstein 1 year ago
parent ff8c124770
commit 572d047e37
No known key found for this signature in database

@ -1642,15 +1642,12 @@ mod tests {
let prog_foo = obj.programs.get("foo").unwrap(); let prog_foo = obj.programs.get("foo").unwrap();
assert_matches!( assert_matches!(prog_foo, Program {
prog_foo,
Program {
license, license,
kernel_version: None, kernel_version: None,
section: ProgramSection::KProbe { .. }, section: ProgramSection::KProbe { .. },
.. ..
} if license.to_str().unwrap() == "GPL" } => assert_eq!(license.to_str().unwrap(), "GPL"));
);
assert_matches!( assert_matches!(
obj.functions.get(&prog_foo.function_key()), obj.functions.get(&prog_foo.function_key()),
@ -1704,14 +1701,12 @@ mod tests {
let prog_bar = obj.programs.get("bar").unwrap(); let prog_bar = obj.programs.get("bar").unwrap();
let function_bar = obj.functions.get(&prog_bar.function_key()).unwrap(); let function_bar = obj.functions.get(&prog_bar.function_key()).unwrap();
assert_matches!(prog_foo, assert_matches!(prog_foo, Program {
Program {
license, license,
kernel_version: None, kernel_version: None,
section: ProgramSection::KProbe { .. }, section: ProgramSection::KProbe { .. },
.. ..
} if license.to_string_lossy() == "GPL" } => assert_eq!(license.to_str().unwrap(), "GPL"));
);
assert_matches!( assert_matches!(
function_foo, function_foo,
Function { Function {
@ -1724,14 +1719,12 @@ mod tests {
} if name == "foo" && instructions.len() == 1 } if name == "foo" && instructions.len() == 1
); );
assert_matches!(prog_bar, assert_matches!(prog_bar, Program {
Program {
license, license,
kernel_version: None, kernel_version: None,
section: ProgramSection::KProbe { .. }, section: ProgramSection::KProbe { .. },
.. ..
} if license.to_string_lossy() == "GPL" } => assert_eq!(license.to_str().unwrap(), "GPL"));
);
assert_matches!( assert_matches!(
function_bar, function_bar,
Function { Function {

@ -742,6 +742,6 @@ mod tests {
TCA_BPF_NAME as u16 TCA_BPF_NAME as u16
); );
let name = CStr::from_bytes_with_nul(inner.data).unwrap(); let name = CStr::from_bytes_with_nul(inner.data).unwrap();
assert_eq!(name.to_string_lossy(), "foo"); assert_eq!(name.to_str().unwrap(), "foo");
} }
} }

Loading…
Cancel
Save