Skip to content

Commit

Permalink
sources: fix clippy lints for rust 1.81.0
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Inglis <[email protected]>
  • Loading branch information
ginglis13 committed Oct 11, 2024
1 parent 641a8be commit 7515613
Show file tree
Hide file tree
Showing 27 changed files with 84 additions and 100 deletions.
10 changes: 5 additions & 5 deletions sources/api/apiclient/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = std::result::Result<Message, WsError>> + 'static,
heartbeat_setter: Arc<Mutex<Instant>>,
Expand Down Expand Up @@ -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<Message>,
capacity_reader: Arc<AtomicCapacity>,
Expand Down
4 changes: 2 additions & 2 deletions sources/api/apiclient/src/exec/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions sources/api/apiserver/src/server/exec/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<TtyInit>) -> Result<Self> {
if let Some(tty_init) = tty {
Self::tty_fds(child, tty_init)
Expand Down Expand Up @@ -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<WsExec>, 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));
Expand Down
6 changes: 1 addition & 5 deletions sources/api/apiserver/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,7 @@ fn comma_separated<'a>(key_name: &'static str, input: &'a str) -> Result<HashSet
}

fn transaction_name(query: &web::Query<HashMap<String, String>>) -> &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
Expand Down
2 changes: 1 addition & 1 deletion sources/api/bootstrap-containers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It queries the API for their settings, then configures the system by:
container at /.bottlerocket/bootstrap-containers/<name>/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
Expand Down
2 changes: 1 addition & 1 deletion sources/api/bootstrap-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It queries the API for their settings, then configures the system by:
container at /.bottlerocket/bootstrap-containers/<name>/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
Expand Down
2 changes: 1 addition & 1 deletion sources/api/host-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions sources/api/migration/migrator/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<()>>()
.len();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sources/api/prairiedog/src/initrd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
24 changes: 12 additions & 12 deletions sources/api/schnauzer/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"#),
Expand All @@ -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": []}}),
Expand Down Expand Up @@ -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",
Expand All @@ -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| {
Expand Down Expand Up @@ -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"),
];
Expand All @@ -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"),
];
Expand All @@ -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");
Expand Down Expand Up @@ -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::"),
];
Expand All @@ -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);
Expand Down Expand Up @@ -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| {
Expand Down
24 changes: 12 additions & 12 deletions sources/api/schnauzer/src/helpers/stdlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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";
Expand All @@ -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);
}
Expand All @@ -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";
Expand All @@ -117,30 +117,30 @@ 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);
}

#[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);
}

#[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);
}
Expand All @@ -149,15 +149,15 @@ 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);
}

#[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);
}
Expand Down Expand Up @@ -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::<bool>}}), "false"),
Expand All @@ -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": ""}}),
Expand Down
4 changes: 2 additions & 2 deletions sources/api/schnauzer/src/v2/cli/clirequirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CLIExtensionRequirement>()
.unwrap()
Expand All @@ -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::<CLIExtensionRequirement>()
.is_err());
Expand Down
Loading

0 comments on commit 7515613

Please sign in to comment.