diff --git a/sources/api/apiclient/src/exec.rs b/sources/api/apiclient/src/exec.rs index 410d25364..50843e1c7 100644 --- a/sources/api/apiclient/src/exec.rs +++ b/sources/api/apiclient/src/exec.rs @@ -225,10 +225,10 @@ impl ReadFromServer { /// * read: The stream of messages from the server. /// /// * heartbeat_setter: An atomic handle to a timestamp; this will be updated whenever we - /// receive a ping or pong from the server so we can make sure the connection isn't stale. + /// receive a ping or pong from the server so we can make sure the connection isn't stale. /// /// * capacity: When the server sends a capacity update, we update this AtomicCapacity, so we - /// can make sure we're not sending (or even reading) data the server can't handle. + /// can make sure we're not sending (or even reading) data the server can't handle. fn new( read: impl Stream> + 'static, heartbeat_setter: Arc>, @@ -341,11 +341,11 @@ impl ReadFromUser { /// * stdin_tx: The channel to which we should send messages containing user input. /// /// * capacity_reader: We'll only read input when the server has capacity, according to this - /// parameter, so that we don't unnecessarily fill buffers or overwhelm the server. + /// parameter, so that we don't unnecessarily fill buffers or overwhelm the server. /// /// * is_tty: whether input is coming from a TTY; think of it as whether the command is - /// interactive. If so, we read a byte at a time and send it immediately to the server so that - /// things like tab completion work. + /// interactive. If so, we read a byte at a time and send it immediately to the server so that + /// things like tab completion work. fn new( stdin_tx: mpsc::UnboundedSender, capacity_reader: Arc, diff --git a/sources/api/apiclient/src/exec/terminal.rs b/sources/api/apiclient/src/exec/terminal.rs index d1d695175..7449045c4 100644 --- a/sources/api/apiclient/src/exec/terminal.rs +++ b/sources/api/apiclient/src/exec/terminal.rs @@ -26,8 +26,8 @@ pub(crate) struct Terminal { impl Terminal { /// Parameters: /// * tty: Represents the user's desire for a TTY, where `Some(true)` means to use a TTY, - /// `Some(false)` means not to use a TTY, and `None` means to detect whether we think we should - /// use a TTY. + /// `Some(false)` means not to use a TTY, and `None` means to detect whether we think we should + /// use a TTY. /// /// For the purposes of terminal settings, "use a TTY" means to set the terminal to /// raw mode so that input is read directly, not interpreted; for example, things like ctrl-c diff --git a/sources/api/apiserver/src/server/exec/child.rs b/sources/api/apiserver/src/server/exec/child.rs index 58373e25e..8f0498507 100644 --- a/sources/api/apiserver/src/server/exec/child.rs +++ b/sources/api/apiserver/src/server/exec/child.rs @@ -69,10 +69,10 @@ pub(crate) struct ChildHandles { impl ChildHandles { /// Parameters: /// * init: The initialization parameters for the process, meaning the target container, the - /// command, and any TTY settings. + /// command, and any TTY settings. /// /// * exec_socket_path: The containerd socket we'll use to start the process in the desired - /// container's namespace. + /// container's namespace. /// /// * ws_addr: The address of the WebSocket actor, for sending messages back. pub(crate) fn new( @@ -194,10 +194,7 @@ impl ChildHandles { })() // If anything went wrong when configuring the child process, kill it and return the // original error. - .map_err(|e| { - Self::stop_impl(pid); - e - }) + .inspect(|_| Self::stop_impl(pid)) } /// Terminates the child process. @@ -262,7 +259,7 @@ impl ChildFds { /// * child: The Command for which we want read and write file descriptors. /// /// * tty: Represents the user's desire for a TTY. If None, don't create a PTY. If Some, - /// create a PTY, and start it with the specs given in TtyInit. + /// create a PTY, and start it with the specs given in TtyInit. fn new(child: &mut Command, tty: &Option) -> Result { if let Some(tty_init) = tty { Self::tty_fds(child, tty_init) @@ -451,8 +448,8 @@ impl WaitForChild { /// * ws_addr: The address of the WebSocket actor, to which we'll send the return code. /// /// * read_complete_rx: We should receive a signal on this channel when the reader thread is - /// finished. PTY I/O is buffered in the kernel, so when a process exits, it doesn't mean - /// we're done reading from the PTY; this lets us be sure. + /// finished. PTY I/O is buffered in the kernel, so when a process exits, it doesn't mean + /// we're done reading from the PTY; this lets us be sure. fn new(pid: Pid, ws_addr: Addr, read_complete_rx: Receiver<()>) -> Self { debug!("Spawning thread to wait for child exit"); thread::spawn(move || Self::wait_for_child(pid, ws_addr, read_complete_rx)); diff --git a/sources/api/apiserver/src/server/mod.rs b/sources/api/apiserver/src/server/mod.rs index 36187633c..eaee36170 100644 --- a/sources/api/apiserver/src/server/mod.rs +++ b/sources/api/apiserver/src/server/mod.rs @@ -746,11 +746,7 @@ fn comma_separated<'a>(key_name: &'static str, input: &'a str) -> Result>) -> &str { - if let Some(name_str) = query.get("tx") { - name_str - } else { - "default" - } + query.get("tx").map(String::as_str).unwrap_or("default") } // Helpers methods for the 'set' API diff --git a/sources/api/bootstrap-containers/README.md b/sources/api/bootstrap-containers/README.md index 4361e2876..5f6930cbd 100644 --- a/sources/api/bootstrap-containers/README.md +++ b/sources/api/bootstrap-containers/README.md @@ -13,7 +13,7 @@ It queries the API for their settings, then configures the system by: container at /.bottlerocket/bootstrap-containers//user-data) * creating an environment file used by a bootstrap-container-specific instance of a systemd service * creating a systemd drop-in configuration file used by a bootstrap-container-specific -instance of a systemd service + instance of a systemd service * ensuring that the bootstrap container's systemd service is enabled/disabled for the next boot ## Examples diff --git a/sources/api/bootstrap-containers/src/main.rs b/sources/api/bootstrap-containers/src/main.rs index 87fc80fe8..b1d7c7e48 100644 --- a/sources/api/bootstrap-containers/src/main.rs +++ b/sources/api/bootstrap-containers/src/main.rs @@ -10,7 +10,7 @@ It queries the API for their settings, then configures the system by: container at /.bottlerocket/bootstrap-containers//user-data) * creating an environment file used by a bootstrap-container-specific instance of a systemd service * creating a systemd drop-in configuration file used by a bootstrap-container-specific -instance of a systemd service + instance of a systemd service * ensuring that the bootstrap container's systemd service is enabled/disabled for the next boot # Examples diff --git a/sources/api/host-containers/src/main.rs b/sources/api/host-containers/src/main.rs index d3dd25a91..4643ed2a1 100644 --- a/sources/api/host-containers/src/main.rs +++ b/sources/api/host-containers/src/main.rs @@ -506,7 +506,7 @@ mod test { let temp_dir = tempfile::TempDir::new().unwrap(); let temp_config = Path::join(temp_dir.path(), "host-containers.toml"); - let _ = std::fs::write(&temp_config, config_toml).unwrap(); + std::fs::write(&temp_config, config_toml).unwrap(); let host_containers = get_host_containers(&temp_config).unwrap(); diff --git a/sources/api/migration/migrator/src/test.rs b/sources/api/migration/migrator/src/test.rs index 1fceae28b..0f9c57a70 100644 --- a/sources/api/migration/migrator/src/test.rs +++ b/sources/api/migration/migrator/src/test.rs @@ -242,7 +242,7 @@ async fn assert_directory_structure_with_failed_migration( .to_str() .unwrap() .starts_with(&to_ver_unique_prefix) - .then(|| ()) + .then_some(()) }) .collect::>() .len(); @@ -355,7 +355,7 @@ async fn migrate_forward() { let contents = std::fs::read_to_string(&output_file).unwrap(); let lines: Vec<&str> = contents.split('\n').collect(); assert_eq!(lines.len(), 4); - let first_line = *lines.get(0).unwrap(); + let first_line = *lines.first().unwrap(); let want = format!("{}: --forward", FIRST_MIGRATION); let got: String = first_line.chars().take(want.len()).collect(); assert_eq!(got, want); @@ -402,7 +402,7 @@ async fn migrate_backward() { let contents = std::fs::read_to_string(&output_file).unwrap(); let lines: Vec<&str> = contents.split('\n').collect(); assert_eq!(lines.len(), 4); - let first_line = *lines.get(0).unwrap(); + let first_line = *lines.first().unwrap(); let want = format!("{}: --backward", THIRD_MIGRATION); let got: String = first_line.chars().take(want.len()).collect(); assert_eq!(got, want); @@ -450,7 +450,7 @@ async fn migrate_forward_with_failed_migration() { let contents = std::fs::read_to_string(&output_file).unwrap(); let lines: Vec<&str> = contents.split('\n').collect(); assert_eq!(lines.len(), 4); - let first_line = *lines.get(0).unwrap(); + let first_line = *lines.first().unwrap(); let want = format!("{}: --forward", FIRST_MIGRATION); let got: String = first_line.chars().take(want.len()).collect(); assert_eq!(got, want); @@ -502,7 +502,7 @@ async fn migrate_backward_with_failed_migration() { let contents = std::fs::read_to_string(&output_file).unwrap(); let lines: Vec<&str> = contents.split('\n').collect(); assert_eq!(lines.len(), 4); - let first_line = *lines.get(0).unwrap(); + let first_line = *lines.first().unwrap(); let want = format!("{}: --backward", THIRD_MIGRATION); let got: String = first_line.chars().take(want.len()).collect(); assert_eq!(got, want); diff --git a/sources/api/prairiedog/src/initrd.rs b/sources/api/prairiedog/src/initrd.rs index 64474009f..498174942 100644 --- a/sources/api/prairiedog/src/initrd.rs +++ b/sources/api/prairiedog/src/initrd.rs @@ -56,7 +56,7 @@ mod tests { let bootconfig = GOOD_BOOTCONFIG; assert_eq!( INITRD_FROM_GOOD_BOOTCONFIG, - generate_initrd(&bootconfig.as_bytes()).unwrap() + generate_initrd(bootconfig.as_bytes()).unwrap() ); } } diff --git a/sources/api/schnauzer/src/helpers/mod.rs b/sources/api/schnauzer/src/helpers/mod.rs index d7ff96b2f..87ebe51ee 100644 --- a/sources/api/schnauzer/src/helpers/mod.rs +++ b/sources/api/schnauzer/src/helpers/mod.rs @@ -2228,7 +2228,7 @@ mod test_ecs_metadata_service_limits { #[test] fn test_valid_ecs_metadata_service_limits() { - let test_cases = vec![ + let test_cases = [ (json!({"settings": {"rps": 1, "burst": 1}}), r#"1,1"#), (json!({"settings": {"rps": 1}}), r#"1,60"#), (json!({"settings": {"burst": 1}}), r#"40,1"#), @@ -2244,7 +2244,7 @@ mod test_ecs_metadata_service_limits { #[test] fn test_invalid_ecs_metadata_service_limits() { - let test_cases = vec![ + let test_cases = [ json!({"settings": {"rps": [], "burst": 1}}), json!({"settings": {"rps": 1, "burst": []}}), json!({"settings": {"rps": [], "burst": []}}), @@ -2279,7 +2279,7 @@ mod test_replace_ipv4_octet { #[test] fn test_valid_replace_ipv4_octet() { - let test_cases = vec![ + let test_cases = [ ( json!({"ip": "192.168.1.1", "index": 3, "value": "10"}), "192.168.1.10", @@ -2299,10 +2299,10 @@ mod test_replace_ipv4_octet { #[test] fn test_invalid_replace_ipv4_octet() { - let test_cases = vec![ + let test_cases = [ json!({"ip": "192.168.1.1", "index": 4, "value": "10"}), // Invalid index json!({"ip": "invalid-ip", "index": 3, "value": "10"}), // Invalid IP - json!({"ip": "192.168.1.1", "index": 3, "value": "257"}), // Invalid octet value + json!({"ip": "192.168.1.1", "index": 3, "value": "257"}), ]; test_cases.iter().for_each(|test_case| { @@ -2342,7 +2342,7 @@ mod test_is_ipv4_is_ipv6 { #[test] fn test_valid_is_ipv4() { - let test_cases = vec![ + let test_cases = [ (json!({"ipcidr": "192.168.1.0/24"}), "true"), (json!({"ipcidr": "2001:db8::/32"}), "false"), ]; @@ -2356,7 +2356,7 @@ mod test_is_ipv4_is_ipv6 { #[test] fn test_valid_is_ipv6() { - let test_cases = vec![ + let test_cases = [ (json!({"ipcidr": "2001:db8::/32"}), "true"), (json!({"ipcidr": "192.168.1.0/24"}), "false"), ]; @@ -2370,7 +2370,7 @@ mod test_is_ipv4_is_ipv6 { #[test] fn test_invalid() { - let test_cases = vec![json!({"ipcidr": "invalid-cidr"})]; + let test_cases = [json!({"ipcidr": "invalid-cidr"})]; test_cases.iter().for_each(|test_case| { let rendered = setup_and_render_template(TEMPLATE_IPV4, test_case, "is_ipv4"); @@ -2405,7 +2405,7 @@ mod test_cidr_to_ipaddr { #[test] fn test_valid_cidr_to_ipaddr() { - let test_cases = vec![ + let test_cases = [ (json!({"ipcidr": "192.168.1.0/24"}), "192.168.1.0"), (json!({"ipcidr": "2001:db8::/32"}), "2001:db8::"), ]; @@ -2419,7 +2419,7 @@ mod test_cidr_to_ipaddr { #[test] fn test_invalid_cidr_to_ipaddr() { - let test_cases = vec![json!({"ipcidr": "invalid-cidr"})]; + let test_cases = [json!({"ipcidr": "invalid-cidr"})]; test_cases.iter().for_each(|test_case| { let rendered = setup_and_render_template(TEMPLATE, test_case); @@ -2457,9 +2457,9 @@ mod test_combined_template_for_ip_cidr { #[test] fn test_combined_template_valid_cases() { - let test_cases = vec![ + let test_cases = [ (json!({"ipcidr": "192.168.1.0/24"}), "192.168.1.10"), // IPv4 case with replacement - (json!({"ipcidr": "2001:db8::/32"}), "2001:db8::a"), // IPv6 case with 'a' suffix + (json!({"ipcidr": "2001:db8::/32"}), "2001:db8::a"), ]; test_cases.iter().for_each(|test_case| { diff --git a/sources/api/schnauzer/src/helpers/stdlib/mod.rs b/sources/api/schnauzer/src/helpers/stdlib/mod.rs index c2f1d5030..08551692f 100644 --- a/sources/api/schnauzer/src/helpers/stdlib/mod.rs +++ b/sources/api/schnauzer/src/helpers/stdlib/mod.rs @@ -81,7 +81,7 @@ mod test_any_enabled { #[test] fn test_any_enabled_with_enabled_elements() { let result = - setup_and_render_template(TEMPLATE, &json!([{"foo": [], "enabled": true}])).unwrap(); + setup_and_render_template(TEMPLATE, json!([{"foo": [], "enabled": true}])).unwrap(); let expected = "enabled"; assert_eq!(result, expected); } @@ -90,7 +90,7 @@ mod test_any_enabled { fn test_any_enabled_with_enabled_elements_from_map() { let result = setup_and_render_template( TEMPLATE, - &json!({"foo": {"enabled": false}, "bar": {"enabled": true}}), + json!({"foo": {"enabled": false}, "bar": {"enabled": true}}), ) .unwrap(); let expected = "enabled"; @@ -99,7 +99,7 @@ mod test_any_enabled { #[test] fn test_any_enabled_without_enabled_elements() { - let result = setup_and_render_template(TEMPLATE, &json!([{"enabled": false}])).unwrap(); + let result = setup_and_render_template(TEMPLATE, json!([{"enabled": false}])).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } @@ -108,7 +108,7 @@ mod test_any_enabled { fn test_any_enabled_without_enabled_elements_from_map() { let result = setup_and_render_template( TEMPLATE, - &json!({"foo": {"enabled": false}, "bar": {"enabled": false}}), + json!({"foo": {"enabled": false}, "bar": {"enabled": false}}), ) .unwrap(); let expected = "disabled"; @@ -117,14 +117,14 @@ mod test_any_enabled { #[test] fn test_any_enabled_with_empty_elements() { - let result = setup_and_render_template(TEMPLATE, &json!([])).unwrap(); + let result = setup_and_render_template(TEMPLATE, json!([])).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } #[test] fn test_any_enabled_with_empty_map() { - let result = setup_and_render_template(TEMPLATE, &json!({})).unwrap(); + let result = setup_and_render_template(TEMPLATE, json!({})).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } @@ -132,7 +132,7 @@ mod test_any_enabled { #[test] fn test_any_enabled_with_bool_flag_as_string() { // Helper is only expected to work with boolean values - let result = setup_and_render_template(TEMPLATE, &json!([{"enabled": "true"}])).unwrap(); + let result = setup_and_render_template(TEMPLATE, json!([{"enabled": "true"}])).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } @@ -140,7 +140,7 @@ mod test_any_enabled { #[test] fn test_any_enabled_with_different_type_array() { // Validates no errors if a different kind of struct is passed in - let result = setup_and_render_template(TEMPLATE, &json!([{"name": "fred"}])).unwrap(); + let result = setup_and_render_template(TEMPLATE, json!([{"name": "fred"}])).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } @@ -149,7 +149,7 @@ mod test_any_enabled { fn test_any_enabled_with_different_type_map() { // Validates no errors if a different kind of struct is passed in let result = - setup_and_render_template(TEMPLATE, &json!({"test": {"name": "fred"}})).unwrap(); + setup_and_render_template(TEMPLATE, json!({"test": {"name": "fred"}})).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } @@ -157,7 +157,7 @@ mod test_any_enabled { #[test] fn test_any_enabled_with_different_type() { // Validates no errors when a completely different JSON struct is passed - let result = setup_and_render_template(TEMPLATE, &json!({"state": "enabled"})).unwrap(); + let result = setup_and_render_template(TEMPLATE, json!({"state": "enabled"})).unwrap(); let expected = "disabled"; assert_eq!(result, expected); } @@ -1101,7 +1101,7 @@ mod test_negate_or_else { fn test_negated_values() { let template: &str = r#"{{negate_or_else false settings.value}}"#; - let test_cases = vec![ + let test_cases = [ (json!({"settings": {"value": true}}), "false"), (json!({"settings": {"value": false}}), "true"), (json!({"settings": {"value": None::}}), "false"), @@ -1116,7 +1116,7 @@ mod test_negate_or_else { #[test] fn test_fails_when_not_booleans() { - let test_cases = vec![ + let test_cases = [ json!({"settings": {"value": []}}), json!({"settings": {"value": {}}}), json!({"settings": {"value": ""}}), diff --git a/sources/api/schnauzer/src/v2/cli/clirequirements.rs b/sources/api/schnauzer/src/v2/cli/clirequirements.rs index 0dc383f29..4cc7c8edf 100644 --- a/sources/api/schnauzer/src/v2/cli/clirequirements.rs +++ b/sources/api/schnauzer/src/v2/cli/clirequirements.rs @@ -161,7 +161,7 @@ mod test { ), ]; - for (requirement_string, expected) in test_cases.into_iter() { + for (requirement_string, expected) in test_cases.iter() { let parsed: ExtensionRequirement = requirement_string .parse::() .unwrap() @@ -181,7 +181,7 @@ mod test { "needs-named-params@v1(helper1, helper2, helper3)", ]; - for requirement_string in test_cases.into_iter() { + for requirement_string in test_cases.iter() { assert!(requirement_string .parse::() .is_err()); diff --git a/sources/api/schnauzer/src/v2/import/helpers.rs b/sources/api/schnauzer/src/v2/import/helpers.rs index b885d10a2..0ce7e0b97 100644 --- a/sources/api/schnauzer/src/v2/import/helpers.rs +++ b/sources/api/schnauzer/src/v2/import/helpers.rs @@ -293,7 +293,7 @@ mod test { ("kubernetes", "v1", vec!["join_node_taints"]), ]; - for (setting_name, version, helpers) in fail_cases.into_iter() { + for (setting_name, version, helpers) in fail_cases.iter() { println!( "Checking {}@{}.{}", setting_name, @@ -309,7 +309,7 @@ mod test { assert!(StaticHelperResolver::ensure_helpers_exist(&extension_requirement).is_err()); } - for (setting_name, version, helpers) in success_cases.into_iter() { + for (setting_name, version, helpers) in success_cases.iter() { println!( "Checking {}@{}.{}", setting_name, @@ -346,7 +346,7 @@ mod test { ), ]; - for (extension_name, version, expected_helpers) in test_cases.into_iter() { + for (extension_name, version, expected_helpers) in test_cases.iter() { assert_eq!( StaticHelperResolver::fetch_helper_names_for_extension(extension_name, version) .unwrap() diff --git a/sources/api/schnauzer/src/v2/import/settings.rs b/sources/api/schnauzer/src/v2/import/settings.rs index e209c7f5d..5645e8adf 100644 --- a/sources/api/schnauzer/src/v2/import/settings.rs +++ b/sources/api/schnauzer/src/v2/import/settings.rs @@ -263,7 +263,7 @@ mod test { for (all_settings, extension_requirements, expected_settings) in test_cases.into_iter() { let minimized_settings = BottlerocketSettingsResolver::minimize_settings( - &all_settings.as_object().unwrap(), + all_settings.as_object().unwrap(), extension_requirements.into_iter(), ); assert_eq!( diff --git a/sources/bootstrap-commands/src/main.rs b/sources/bootstrap-commands/src/main.rs index 7976897bd..293e6b6e6 100644 --- a/sources/bootstrap-commands/src/main.rs +++ b/sources/bootstrap-commands/src/main.rs @@ -261,6 +261,8 @@ mod error { } } +type Result = std::result::Result; + #[cfg(test)] mod test { use super::*; @@ -280,7 +282,7 @@ mod test { let temp_dir = tempfile::TempDir::new().unwrap(); let temp_config = Path::join(temp_dir.path(), "bootstrap-commands.toml"); - let _ = std::fs::write(&temp_config, config_toml).unwrap(); + std::fs::write(&temp_config, config_toml).unwrap(); let bootstrap_command_config = get_bootstrap_commands(&temp_config).unwrap(); let bootstrap_commands = bootstrap_command_config.bootstrap_commands; @@ -332,7 +334,7 @@ mod test { let temp_dir = tempfile::TempDir::new().unwrap(); let temp_config = Path::join(temp_dir.path(), "bootstrap-commands.toml"); - let _ = std::fs::write(&temp_config, config_toml).unwrap(); + std::fs::write(&temp_config, config_toml).unwrap(); let bootstrap_command_config = get_bootstrap_commands(&temp_config).unwrap(); let bootstrap_commands = bootstrap_command_config.bootstrap_commands; @@ -360,11 +362,9 @@ mod test { let temp_dir = tempfile::TempDir::new().unwrap(); let temp_config = Path::join(temp_dir.path(), "bootstrap-commands.toml"); - let _ = std::fs::write(&temp_config, config_toml).unwrap(); + std::fs::write(&temp_config, config_toml).unwrap(); // It should fail because one of the commands is not valid. assert!(get_bootstrap_commands(&temp_config).is_err()); } } - -type Result = std::result::Result; diff --git a/sources/driverdog/src/main.rs b/sources/driverdog/src/main.rs index cd8ecbe07..d77fcaf26 100644 --- a/sources/driverdog/src/main.rs +++ b/sources/driverdog/src/main.rs @@ -608,7 +608,7 @@ mod test { { let invalid_path = &invalid.path(); let modules_sets: Result> = toml::from_str( - &fs::read_to_string(&invalid_path) + &fs::read_to_string(invalid_path) .context(error::ReadPathSnafu { path: &invalid_path, }) diff --git a/sources/imdsclient/src/lib.rs b/sources/imdsclient/src/lib.rs index b39c52d63..0a1606c7f 100644 --- a/sources/imdsclient/src/lib.rs +++ b/sources/imdsclient/src/lib.rs @@ -925,7 +925,7 @@ mod test { assert_eq!(3, parsed_list.len()); assert_eq!( "meta-data/public-keys/0/openssh-key", - parsed_list.get(0).unwrap() + parsed_list.first().unwrap() ); assert_eq!( "meta-data/public-keys/1/openssh-key", diff --git a/sources/logdog/README.md b/sources/logdog/README.md index 6dea6ddeb..0f5b3f2c6 100644 --- a/sources/logdog/README.md +++ b/sources/logdog/README.md @@ -21,7 +21,7 @@ For the log requests used to gather logs, please see the following: * [log_request](src/log_request.rs) * [logdog.common.conf](conf/logdog.common.conf) * And the variant-specific files in [conf](conf/), one of which is selected by [build.rs](build.rs) -based on the value of the `VARIANT` environment variable at build time. + based on the value of the `VARIANT` environment variable at build time. ## Colophon diff --git a/sources/logdog/src/create_tarball.rs b/sources/logdog/src/create_tarball.rs index c4c370059..4c54656be 100644 --- a/sources/logdog/src/create_tarball.rs +++ b/sources/logdog/src/create_tarball.rs @@ -63,7 +63,7 @@ mod tests { let outfilepath = outdir.path().join("somefile.tar.gz"); // run the function under test. - create_tarball(&indir.path().to_path_buf(), &outfilepath).unwrap(); + create_tarball(indir.path(), &outfilepath).unwrap(); // assert that the output tarball exists. assert!(Path::new(&outfilepath).is_file()); diff --git a/sources/logdog/src/main.rs b/sources/logdog/src/main.rs index e719533e9..c8b9ba6e4 100644 --- a/sources/logdog/src/main.rs +++ b/sources/logdog/src/main.rs @@ -18,7 +18,7 @@ For the log requests used to gather logs, please see the following: * [log_request](src/log_request.rs) * [logdog.common.conf](conf/logdog.common.conf) * And the variant-specific files in [conf](conf/), one of which is selected by [build.rs](build.rs) -based on the value of the `VARIANT` environment variable at build time. + based on the value of the `VARIANT` environment variable at build time. */ diff --git a/sources/metricdog/src/config.rs b/sources/metricdog/src/config.rs index 230cf14e7..861b9755e 100644 --- a/sources/metricdog/src/config.rs +++ b/sources/metricdog/src/config.rs @@ -66,7 +66,7 @@ mod test { assert_eq!("https://example.com", config.metrics_url.as_str()); assert!(config.send_metrics); assert_eq!(3, config.service_checks.len()); - assert_eq!("a", config.service_checks.get(0).unwrap()); + assert_eq!("a", config.service_checks.first().unwrap()); assert_eq!("b", config.service_checks.get(1).unwrap()); assert_eq!("c", config.service_checks.get(2).unwrap()); assert_eq!("us-west-2", config.region); @@ -84,7 +84,7 @@ mod test { assert_eq!("", config.metrics_url.as_str()); assert!(!config.send_metrics); assert_eq!(3, config.service_checks.len()); - assert_eq!("a", config.service_checks.get(0).unwrap()); + assert_eq!("a", config.service_checks.first().unwrap()); assert_eq!("b", config.service_checks.get(1).unwrap()); assert_eq!("c", config.service_checks.get(2).unwrap()); assert_eq!("us-west-2", config.region); diff --git a/sources/metricdog/src/systemd.rs b/sources/metricdog/src/systemd.rs index b2076e4f9..81b59a3d8 100644 --- a/sources/metricdog/src/systemd.rs +++ b/sources/metricdog/src/systemd.rs @@ -168,8 +168,7 @@ mod parse_property_tests { format!("{}=0", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten() + .and_then(|exit_code| exit_code.parse::().ok()) .unwrap(); let want = 0; @@ -182,8 +181,7 @@ mod parse_property_tests { format!("{}=255", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten() + .and_then(|exit_code| exit_code.parse::().ok()) .unwrap(); let want = 255; @@ -196,8 +194,7 @@ mod parse_property_tests { format!("{}=0\n", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten() + .and_then(|exit_code| exit_code.parse::().ok()) .unwrap(); let want = 0; @@ -210,8 +207,7 @@ mod parse_property_tests { format!("{}=255\n", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten() + .and_then(|exit_code| exit_code.parse::().ok()) .unwrap(); let want = 255; @@ -224,8 +220,7 @@ mod parse_property_tests { format!("{}=255foo", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten(); + .and_then(|exit_code| exit_code.parse::().ok()); assert!(got.is_none()); } @@ -236,8 +231,7 @@ mod parse_property_tests { format!("{} = 123", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten(); + .and_then(|exit_code| exit_code.parse::().ok()); assert!(got.is_none()); } @@ -245,8 +239,7 @@ mod parse_property_tests { #[test] fn parse_stdout_empty_string() { let got = parse_property("", EXIT_STATUS_PROPERTY) - .map(|exit_code| exit_code.parse::().ok()) - .flatten(); + .and_then(|exit_code| exit_code.parse::().ok()); assert!(got.is_none()); } @@ -254,8 +247,7 @@ mod parse_property_tests { #[test] fn parse_stdout_property_only() { let got = parse_property(EXIT_STATUS_PROPERTY, EXIT_STATUS_PROPERTY) - .map(|exit_code| exit_code.parse::().ok()) - .flatten(); + .and_then(|exit_code| exit_code.parse::().ok()); assert!(got.is_none()); } @@ -266,8 +258,7 @@ mod parse_property_tests { format!("{}=", EXIT_STATUS_PROPERTY).as_str(), EXIT_STATUS_PROPERTY, ) - .map(|exit_code| exit_code.parse::().ok()) - .flatten(); + .and_then(|exit_code| exit_code.parse::().ok()); assert!(got.is_none()); } diff --git a/sources/netdog/src/cli/write_resolv_conf.rs b/sources/netdog/src/cli/write_resolv_conf.rs index e7098875c..f8c2e6a65 100644 --- a/sources/netdog/src/cli/write_resolv_conf.rs +++ b/sources/netdog/src/cli/write_resolv_conf.rs @@ -138,7 +138,7 @@ fn handle_dns_settings(primary_interface: String) -> Result<()> { let mut dropin_file_path = dropin_dir_path.join("10-dns"); dropin_file_path.set_extension("conf"); - fs::write(&dropin_file_path, &interface_drop_in.to_string()).context( + fs::write(&dropin_file_path, interface_drop_in.to_string()).context( error::DropInFileWriteSnafu { path: dropin_file_path, }, diff --git a/sources/netdog/src/interface_id.rs b/sources/netdog/src/interface_id.rs index c3f58462f..6c13445d2 100644 --- a/sources/netdog/src/interface_id.rs +++ b/sources/netdog/src/interface_id.rs @@ -50,7 +50,7 @@ impl TryFrom for MacAddress { fn try_from(input: String) -> Result { let mut octets = 0; - for octet in input.split(|b| b == '-' || b == ':') { + for octet in input.split(['-', ':']) { // If we've gotten to 6 and are still iterating, the MAC is too long ensure!( octets != 6 && octet.len() == 2, diff --git a/sources/pciclient/src/private.rs b/sources/pciclient/src/private.rs index 1bf34606f..bf72c55b6 100644 --- a/sources/pciclient/src/private.rs +++ b/sources/pciclient/src/private.rs @@ -319,7 +319,7 @@ mod test { }; let check_efa_attachment_result = check_efa_attachment(mock_pci_client); assert!(check_efa_attachment_result.is_ok()); - assert_eq!(check_efa_attachment_result.unwrap(), true); + assert!(check_efa_attachment_result.unwrap()); } #[test] @@ -330,6 +330,6 @@ mod test { }; let check_efa_attachment_result = check_efa_attachment(mock_pci_client); assert!(check_efa_attachment_result.is_ok()); - assert_eq!(check_efa_attachment_result.unwrap(), false); + assert!(!check_efa_attachment_result.unwrap()); } } diff --git a/sources/retry-read/src/lib.rs b/sources/retry-read/src/lib.rs index 9b1f4add7..7d5c7d068 100644 --- a/sources/retry-read/src/lib.rs +++ b/sources/retry-read/src/lib.rs @@ -49,7 +49,7 @@ mod test { let mut output = vec![0; data.len()]; let count = (&data[..]).retry_read(&mut output).unwrap(); assert_eq!(count, data.len()); - assert_eq!(&data[..], &output); + assert_eq!(data, &output); } #[test] diff --git a/sources/updater/signpost/src/gptprio.rs b/sources/updater/signpost/src/gptprio.rs index 7d5a836c5..94e2221c4 100644 --- a/sources/updater/signpost/src/gptprio.rs +++ b/sources/updater/signpost/src/gptprio.rs @@ -77,19 +77,19 @@ mod tests { let mut prio = GptPrio(0x5555555555555555); assert_eq!(prio.priority(), 5); assert_eq!(prio.tries_left(), 5); - assert_eq!(prio.successful(), true); - assert_eq!(prio.will_boot(), true); + assert!(prio.successful()); + assert!(prio.will_boot()); prio.set_priority(0); assert_eq!(prio.0, 0x5550555555555555); prio.set_tries_left(0); assert_eq!(prio.0, 0x5500555555555555); prio.set_successful(false); assert_eq!(prio.0, 0x5400555555555555); - assert_eq!(prio.will_boot(), false); + assert!(!prio.will_boot()); prio = GptPrio(0x0000000000000000); - assert_eq!(prio.has_boot_succeeded(), false); + assert!(!prio.has_boot_succeeded()); prio.boot_has_succeeded(); - assert_eq!(prio.has_boot_succeeded(), true); + assert!(prio.has_boot_succeeded()); } }