From 572d047e37111b732be49ef3ad6fb16f70aa4063 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 11 Aug 2023 10:20:38 -0400 Subject: [PATCH] test: avoid lossy string conversions We can be strict in tests. --- aya-obj/src/obj.rs | 43 ++++++++++++++++++------------------------ aya/src/sys/netlink.rs | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 70375df2..73d87e68 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -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()), @@ -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 { @@ -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 { diff --git a/aya/src/sys/netlink.rs b/aya/src/sys/netlink.rs index ac302f50..a7b24902 100644 --- a/aya/src/sys/netlink.rs +++ b/aya/src/sys/netlink.rs @@ -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"); } }