From 8f401820f540b8492476d074e0acb20533cbd6de Mon Sep 17 00:00:00 2001 From: Costin Lupu Date: Mon, 8 Jan 2024 18:44:38 +0100 Subject: [PATCH] Fix errors reported by Clippy (part 1 - automated) These changes are created automatically with `cargo clippy --fix --allow-dirty`. Signed-off-by: Costin Lupu --- src/common/document_errors.rs | 20 +++--- src/common/logger.rs | 8 +-- src/common/mod.rs | 2 +- src/enclave_proc/connection_listener.rs | 2 +- src/enclave_proc/socket.rs | 6 +- tests/test_dev_driver.rs | 82 ++++++++++----------- tests/test_nitro_cli_args.rs | 94 ++++++++++++------------- tests/tests.rs | 12 ++-- 8 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/common/document_errors.rs b/src/common/document_errors.rs index 3244a741..460e019f 100644 --- a/src/common/document_errors.rs +++ b/src/common/document_errors.rs @@ -84,7 +84,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Missing mandatory argument. User did not provide the `{}` argument.", - additional_info.get(0).unwrap_or(&info_placeholder) + additional_info.first().unwrap_or(&info_placeholder) ) .as_str(), ); @@ -93,7 +93,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Conflicting arguments. User provided both `{}` and `{}`.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder) ) .as_str(), @@ -103,7 +103,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Invalid argument provided. The parameter `{}` is not a valid integer (`{}`)", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder) ) .as_str(), @@ -160,7 +160,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "\nFile: '{}', failing operation: '{}'.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder), ) .as_str(), @@ -171,7 +171,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Invalid CPU configuration. User provided `{}` contains same CPU(s) (CPU(s) {}) multiple times.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder), ) .as_str(), @@ -181,7 +181,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "No such CPU available in the pool. User provided `{}` contains CPU {}, which is not available in the pool.\nYou can add a specific CPU to the CPU pool by editing the `cpu_pool` value from '/etc/nitro_enclaves/allocator.yaml' and then enable the nitro-enclaves-allocator.service.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder), ).as_str(), ); @@ -190,7 +190,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Insufficient CPUs available in the pool. User provided `{}` is {}, which is more than the configured CPU pool size.\nYou can increase the CPU pool size by editing the `cpu_count` value from '/etc/nitro_enclaves/allocator.yaml' and then enable the nitro-enclaves-allocator.service.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder), ).as_str(), ); @@ -209,7 +209,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Insufficient memory requested. User provided `{}` is {} MB, but based on the EIF file size, the minimum memory should be {} MB", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder), additional_info.get(2).unwrap_or(&info_placeholder) ).as_str(), @@ -218,7 +218,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Insufficient memory requested. User provided `{}` is {} MB, and memory should be greater than 0 MB.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder) ).as_str(), ); @@ -228,7 +228,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) -> ret.push_str( format!( "Insufficient memory available. User provided `{}` is {} MB, which is more than the available hugepage memory.\nYou can increase the available memory by editing the `memory_mib` value from '/etc/nitro_enclaves/allocator.yaml' and then restart the nitro-enclaves-allocator.service.", - additional_info.get(0).unwrap_or(&info_placeholder), + additional_info.first().unwrap_or(&info_placeholder), additional_info.get(1).unwrap_or(&info_placeholder) ).as_str(), ); diff --git a/src/common/logger.rs b/src/common/logger.rs index 8fe7f6c1..3f1eb4da 100644 --- a/src/common/logger.rs +++ b/src/common/logger.rs @@ -300,7 +300,7 @@ mod tests { let _ = fs::remove_dir_all(tmp_log_dir); } else { // Only remove the log file - let _ = fs::remove_file(&format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME)); + let _ = fs::remove_file(format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME)); } // Reset old environment variable value if necessary @@ -324,19 +324,19 @@ mod tests { let _ = fs::create_dir(tmp_log_dir); let log_writer = EnclaveProcLogWriter::new().unwrap(); - let _ = log_writer.update_logger_id("new-logger-id").unwrap(); + log_writer.update_logger_id("new-logger-id").unwrap(); let lock_result = log_writer.logger_id.lock(); assert!(lock_result.unwrap().eq("new-logger-id")); - let _ = log_writer.update_logger_id("").unwrap(); + log_writer.update_logger_id("").unwrap(); if !path_existed { // Remove whole `tmp_log_dir` if necessary let _ = fs::remove_dir_all(tmp_log_dir); } else { // Only remove the log file - let _ = fs::remove_file(&format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME)); + let _ = fs::remove_file(format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME)); } // Reset old environment variable value if necessary diff --git a/src/common/mod.rs b/src/common/mod.rs index 90c63ce5..c4d7caa1 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -573,7 +573,7 @@ mod tests { const TMP_DIR_STR: &str = "./tmp_sock_dir"; fn unset_envvar(varname: &String) { - let _ = unsafe { + unsafe { libc::unsetenv(varname.as_ptr() as *const c_char); }; } diff --git a/src/enclave_proc/connection_listener.rs b/src/enclave_proc/connection_listener.rs index 562b7f13..173b63c8 100644 --- a/src/enclave_proc/connection_listener.rs +++ b/src/enclave_proc/connection_listener.rs @@ -393,7 +393,7 @@ mod tests { &mut cli_evt, ); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); } } diff --git a/src/enclave_proc/socket.rs b/src/enclave_proc/socket.rs index 270ce8a7..0e60a8fc 100644 --- a/src/enclave_proc/socket.rs +++ b/src/enclave_proc/socket.rs @@ -240,7 +240,7 @@ mod tests { /// expected ones. #[test] fn test_enclaveprocsock_init() { - let socket = EnclaveProcSock::new(&DUMMY_ENCLAVE_ID.to_string()); + let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID); assert!(socket.is_ok()); @@ -260,7 +260,7 @@ mod tests { /// trigger a `socket.requested_remove` change. #[test] fn test_start_monitoring() { - let socket = EnclaveProcSock::new(&DUMMY_ENCLAVE_ID.to_string()); + let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID); assert!(socket.is_ok()); @@ -289,7 +289,7 @@ mod tests { /// that the listener thread joins. #[test] fn test_close() { - let socket = EnclaveProcSock::new(&DUMMY_ENCLAVE_ID.to_string()); + let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID); assert!(socket.is_ok()); diff --git a/tests/test_dev_driver.rs b/tests/test_dev_driver.rs index 8be82428..d9c0307e 100644 --- a/tests/test_dev_driver.rs +++ b/tests/test_dev_driver.rs @@ -190,7 +190,7 @@ impl CheckDmesg { /// Verify if dmesg number of lines changed from the last recorded line. pub fn expect_no_changes(&mut self) -> NitroCliResult<()> { - let checks = vec![ + let checks = [ "WARNING", "BUG", "ERROR", @@ -264,8 +264,8 @@ mod test_dev_driver { let mut enclave = driver.create_enclave().unwrap(); // Add invalid memory region. - let result = enclave.add_mem_region(EnclaveMemoryRegion::new(0, 0, 2 * MiB as u64)); - assert_eq!(result.is_err(), true); + let result = enclave.add_mem_region(EnclaveMemoryRegion::new(0, 0, 2 * MiB)); + assert!(result.is_err()); // Create a memory region using hugetlbfs. let region = MemoryRegion::new(libc::MAP_HUGE_2MB).unwrap(); @@ -276,7 +276,7 @@ mod test_dev_driver { region.mem_addr() + 1, region.mem_size(), )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Add wrongly sized memory region of 1 MiB. let result = enclave.add_mem_region(EnclaveMemoryRegion::new( @@ -284,7 +284,7 @@ mod test_dev_driver { region.mem_addr(), region.mem_size() / 2, )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Add wrongly sized memory region of double the memory size. let result = enclave.add_mem_region(EnclaveMemoryRegion::new( @@ -292,7 +292,7 @@ mod test_dev_driver { region.mem_addr(), region.mem_size() * 2, )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Add wrongly sized memory region of max value multiple of 2 MiB. let result = enclave.add_mem_region(EnclaveMemoryRegion::new( @@ -300,7 +300,7 @@ mod test_dev_driver { region.mem_addr(), u64::max_value() - (2 * 1024 * 1024) + 1, )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Add wrong memory region with address out of range. let result = enclave.add_mem_region(EnclaveMemoryRegion::new( @@ -308,7 +308,7 @@ mod test_dev_driver { region.mem_addr() + region.mem_size(), region.mem_size(), )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); let mut check_dmesg = CheckDmesg::new().expect("Failed to obtain dmesg object"); check_dmesg @@ -318,13 +318,13 @@ mod test_dev_driver { // Correctly add the memory region. let region = MemoryRegion::new(libc::MAP_HUGE_2MB).unwrap(); let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from(®ion)); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); check_dmesg.expect_no_changes().unwrap(); // Add the same memory region twice. let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from(®ion)); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Add a memory region with invalid flags. let region = MemoryRegion::new(libc::MAP_HUGE_2MB).unwrap(); @@ -333,7 +333,7 @@ mod test_dev_driver { region.mem_addr(), region.mem_size(), )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); } #[test] @@ -344,7 +344,7 @@ mod test_dev_driver { // Add an invalid cpu id. let result = enclave.add_cpu(u32::max_value()); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); let mut candidates = cpu_info.get_cpu_candidates(); // Instance does not have the appropriate number of cpus. @@ -361,13 +361,13 @@ mod test_dev_driver { // Insert the first valid cpu id. let result = enclave.add_cpu(cpu_id); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); check_dmesg.expect_no_changes().unwrap(); // Try inserting the cpu twice. let result = enclave.add_cpu(cpu_id); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); check_dmesg .record_current_line() @@ -376,7 +376,7 @@ mod test_dev_driver { // Add all remaining cpus. for cpu in &candidates { let result = enclave.add_cpu(*cpu); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } check_dmesg.expect_no_changes().unwrap(); @@ -392,7 +392,7 @@ mod test_dev_driver { // Add an auto-chosen cpu from the pool. let result = enclave.add_cpu(0); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); check_dmesg.expect_no_changes().unwrap(); @@ -403,14 +403,14 @@ mod test_dev_driver { // Add all remaining auto-chosen cpus. for _i in 0..candidates.len() { let result = enclave.add_cpu(0); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } check_dmesg.expect_no_changes().unwrap(); // Add one more cpu than the maximum available in the pool. let result = enclave.add_cpu(0); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); } #[test] @@ -421,7 +421,7 @@ mod test_dev_driver { // Start enclave without resources. let result = enclave.start(EnclaveStartInfo::default()); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Allocate memory for the enclave. #[cfg(target_arch = "x86_64")] @@ -453,12 +453,12 @@ mod test_dev_driver { // Add memory to the enclave. for region in &mut mem_regions { let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from(region)); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } // Start the enclave without cpus. let result = enclave.start(EnclaveStartInfo::default()); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); let cpu_info = CpuInfo::new().expect("Failed to obtain CpuInfo."); let candidates = cpu_info.get_cpu_candidates(); @@ -474,12 +474,12 @@ mod test_dev_driver { for cpu in &candidates { let result = enclave.add_cpu(*cpu); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } // Start enclave without memory. let result = enclave.start(EnclaveStartInfo::default()); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); drop(enclave); @@ -488,12 +488,12 @@ mod test_dev_driver { // Add memory to the enclave. for region in &mut mem_regions { let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from(region)); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } // Add the first available cpu. let result = enclave.add_cpu(candidates[0]); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); // Start without cpu pair. #[cfg(target_arch = "aarch64")] @@ -505,7 +505,7 @@ mod test_dev_driver { let result = enclave.start(EnclaveStartInfo::default()); #[cfg(target_arch = "x86_64")] - assert_eq!(result.is_err(), true); + assert!(result.is_err()); #[cfg(target_arch = "aarch64")] assert_eq!(result.is_err(), false); @@ -533,31 +533,31 @@ mod test_dev_driver { // Add the first cpu pair. let result = enclave.add_cpu(candidates[1]); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); // Start with an invalid flag. let mut enclave_start_info = EnclaveStartInfo::default(); enclave_start_info.flags = 1234; let result = enclave.start(enclave_start_info); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Start with an invalid CID. let mut enclave_start_info = EnclaveStartInfo::default(); enclave_start_info.enclave_cid = VMADDR_CID_LOCAL as u64; let result = enclave.start(enclave_start_info); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); enclave_start_info.enclave_cid = VMADDR_CID_HOST as u64; let result = enclave.start(enclave_start_info); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); enclave_start_info.enclave_cid = u32::max_value() as u64; let result = enclave.start(enclave_start_info); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); enclave_start_info.enclave_cid = u32::max_value() as u64 + 1234_u64; let result = enclave.start(enclave_start_info); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); let mut check_dmesg = CheckDmesg::new().expect("Failed to obtain dmesg object"); check_dmesg @@ -566,33 +566,33 @@ mod test_dev_driver { // Start the enclave. let result = enclave.start(EnclaveStartInfo::default()); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); check_dmesg.expect_no_changes().unwrap(); // Try starting an already running enclave. let result = enclave.start(EnclaveStartInfo::default()); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Try adding an already added memory region // after the enclave start. let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from(&mem_regions[0])); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Try adding a new memory region after the enclave start. let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from( &MemoryRegion::new(libc::MAP_HUGE_2MB).unwrap(), )); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Try adding an already added vcpu after enclave start. let result = enclave.add_cpu(candidates[0]); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); // Try adding a new vcpu after enclave start. if candidates.len() >= 3 { let result = enclave.add_cpu(candidates[2]); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); } } @@ -648,18 +648,18 @@ mod test_dev_driver { // Add memory to the enclave. for region in &mut mem_regions { let result = enclave.add_mem_region(EnclaveMemoryRegion::new_from(region)); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } // Add cpus to the enclave. for cpu in &candidates { let result = enclave.add_cpu(*cpu); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } // Start and stop the enclave let result = enclave.start(EnclaveStartInfo::default()); - assert_eq!(result.is_err(), false); + assert!(result.is_ok()); } } } diff --git a/tests/test_nitro_cli_args.rs b/tests/test_nitro_cli_args.rs index 8bf5a247..e68f625b 100644 --- a/tests/test_nitro_cli_args.rs +++ b/tests/test_nitro_cli_args.rs @@ -12,7 +12,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "terminate-enclave"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -20,7 +20,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "terminate-enclave", "--enclave-id"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -33,7 +33,7 @@ mod test_nitro_cli_args { "i-1234_enc123", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -47,7 +47,7 @@ mod test_nitro_cli_args { "135", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -60,7 +60,7 @@ mod test_nitro_cli_args { "testName", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -68,7 +68,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "terminate-enclave", "--enclave-name"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -82,7 +82,7 @@ mod test_nitro_cli_args { "name2", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -90,7 +90,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "describe-enclaves"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -98,7 +98,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "describe-enclaves", "--metadata"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -106,7 +106,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "describe-eif", "--eif-path", "dir/image.eif"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -114,7 +114,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "describe-eif", "--eif-path"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -122,7 +122,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "console"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -130,7 +130,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "console", "--enclave-id"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -138,7 +138,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "console", "--enclave-id", "i-1234_enc123"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -152,7 +152,7 @@ mod test_nitro_cli_args { "135", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -160,7 +160,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "console", "--enclave-name", "testName"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -168,7 +168,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "console", "--enclave-name"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -176,7 +176,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "console", "--enclave-name", "name1", "name2"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -191,7 +191,7 @@ mod test_nitro_cli_args { "10", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -206,7 +206,7 @@ mod test_nitro_cli_args { "10", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -220,7 +220,7 @@ mod test_nitro_cli_args { "--disconnect-timeout", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -228,7 +228,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "build-enclave", "--output-file", "image.eif"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -243,7 +243,7 @@ mod test_nitro_cli_args { "image.eif", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -256,7 +256,7 @@ mod test_nitro_cli_args { "dkr.ecr.us-east-1.amazonaws.com/stronghold-develss", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -273,7 +273,7 @@ mod test_nitro_cli_args { "image.eif", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -294,7 +294,7 @@ mod test_nitro_cli_args { "key.pem", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -317,7 +317,7 @@ mod test_nitro_cli_args { "meta.json", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -339,7 +339,7 @@ mod test_nitro_cli_args { "--metadata", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -360,7 +360,7 @@ mod test_nitro_cli_args { "--debug-mode", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -378,7 +378,7 @@ mod test_nitro_cli_args { "--debug-mode", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -397,7 +397,7 @@ mod test_nitro_cli_args { "--debug-mode", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -418,7 +418,7 @@ mod test_nitro_cli_args { "--debug-mode", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -436,7 +436,7 @@ mod test_nitro_cli_args { "--debug-mode", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -452,7 +452,7 @@ mod test_nitro_cli_args { "dir/image.eif", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -470,7 +470,7 @@ mod test_nitro_cli_args { "--enclave-cid", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -491,7 +491,7 @@ mod test_nitro_cli_args { "123", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -506,7 +506,7 @@ mod test_nitro_cli_args { "512", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -523,7 +523,7 @@ mod test_nitro_cli_args { "--eif-path", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -531,7 +531,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "run-enclave", "--config"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -545,7 +545,7 @@ mod test_nitro_cli_args { "config2.json", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -564,7 +564,7 @@ mod test_nitro_cli_args { "dir/image.eif", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -587,7 +587,7 @@ mod test_nitro_cli_args { "testName", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } #[test] @@ -609,7 +609,7 @@ mod test_nitro_cli_args { "--enclave-name", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -617,7 +617,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "pcr", "--input"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -625,7 +625,7 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "pcr", "--signing-certificate"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -640,7 +640,7 @@ mod test_nitro_cli_args { "test.bin", ]; - assert_eq!(app.get_matches_from_safe(args).is_err(), true) + assert!(app.get_matches_from_safe(args).is_err()) } #[test] @@ -648,6 +648,6 @@ mod test_nitro_cli_args { let app = create_app!(); let args = vec!["nitro cli", "pcr", "--signing-certificate", "cert.pem"]; - assert_eq!(app.get_matches_from_safe(args).is_err(), false) + assert!(app.get_matches_from_safe(args).is_ok()) } } diff --git a/tests/tests.rs b/tests/tests.rs index 2c129a1d..9f26050c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -86,7 +86,7 @@ mod tests { metadata: None, }; - assert_eq!(build_enclaves(args).is_err(), true); + assert!(build_enclaves(args).is_err()); } #[test] @@ -410,7 +410,7 @@ mod tests { setup_env(); let req_enclave_cid = args.enclave_cid; let req_mem_size = args.memory_mib; - let req_nr_cpus: u64 = args.cpu_count.unwrap().try_into().unwrap(); + let req_nr_cpus: u64 = args.cpu_count.unwrap().into(); let debug_mode = args.debug_mode; let mut enclave_manager = run_enclaves(&args, None) .expect("Run enclaves failed") @@ -445,7 +445,7 @@ mod tests { let contents = String::from_utf8(buffer).unwrap(); let boot = contents.contains("nsm: loading out-of-tree module"); - assert_eq!(boot, true); + assert!(boot); let info = get_enclave_describe_info(&enclave_manager, false).unwrap(); let replies: Vec = vec![info]; @@ -571,7 +571,7 @@ mod tests { let replies: Vec = vec![info]; let _reply = &replies[0]; - assert_eq!(enclave_console(enclave_cid, None).is_err(), true); + assert!(enclave_console(enclave_cid, None).is_err()); terminate_enclaves(&mut enclave_manager, None).expect("Terminate enclaves failed"); } @@ -981,7 +981,7 @@ mod tests { let eif_info = describe_eif(args.output).unwrap(); assert_eq!(eif_info.version, 4); - assert_eq!(eif_info.is_signed, false); + assert!(!eif_info.is_signed); assert!(eif_info.cert_info.is_none()); assert!(eif_info.crc_check); assert!(eif_info.sign_check.is_none()); @@ -1023,7 +1023,7 @@ mod tests { let eif_info = describe_eif(args.output).unwrap(); assert_eq!(eif_info.version, 4); - assert_eq!(eif_info.is_signed, true); + assert!(eif_info.is_signed); assert!(eif_info.cert_info.is_some()); assert!(eif_info.crc_check); assert!(eif_info.sign_check.unwrap());