From 1897ca728f140f8b0c9bb3a8fc8c3e8dddf01cf4 Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Tue, 30 Jul 2024 09:32:38 +0200 Subject: [PATCH] chore: make clippy happy --- src/controller.rs | 24 ++++++++---------------- src/goose.rs | 12 ++++++------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index 46edbe7e..8bf4dbea 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -33,13 +33,13 @@ use tokio_tungstenite::tungstenite::Message; /// - Commands will be displayed in the help screen in the order defined here, so /// they should be logically grouped. /// 2. Add the new command to `ControllerCommand::details` and populate all -/// `ControllerCommandDetails`, using other commands as an implementation reference. -/// - The `regex` is used to identify the command, and optionally to extract a -/// value (for example see `Hatchrate` and `Users`) -/// - If additional validation is required beyond the regular expression, add -/// the necessary logic to `ControllerCommand::validate_value`. +/// `ControllerCommandDetails`, using other commands as an implementation reference. +/// - The `regex` is used to identify the command, and optionally to extract a +/// value (for example see `Hatchrate` and `Users`) +/// - If additional validation is required beyond the regular expression, add +/// the necessary logic to `ControllerCommand::validate_value`. /// 3. Add any necessary parent process logic for the command to -/// `GooseAttack::handle_controller_requests` (also in this file). +/// `GooseAttack::handle_controller_requests` (also in this file). /// 4. Add a test for the new command in tests/controller.rs. #[derive(Clone, Debug, EnumIter, PartialEq, Eq)] pub enum ControllerCommand { @@ -642,10 +642,8 @@ impl GooseAttack { AttackPhase::Idle => { let current_users = if !self.test_plan.steps.is_empty() { self.test_plan.steps[self.test_plan.current].0 - } else if let Some(users) = self.configuration.users { - users } else { - 0 + self.configuration.users.unwrap_or_default() }; info!( "changing users from {:?} to {}", @@ -1410,13 +1408,7 @@ impl Controller for ControllerState { raw_value: ControllerTelnetMessage, ) -> Result { let command_string = match str::from_utf8(&raw_value) { - Ok(m) => { - if let Some(c) = m.lines().next() { - c - } else { - "" - } - } + Ok(m) => m.lines().next().unwrap_or_default(), Err(e) => { let error = format!("ignoring unexpected input from telnet controller: {}", e); info!("{}", error); diff --git a/src/goose.rs b/src/goose.rs index 68c0450f..c9797721 100644 --- a/src/goose.rs +++ b/src/goose.rs @@ -522,7 +522,7 @@ impl Scenario { Scenario { name: name.to_string(), machine_name: Scenario::get_machine_name(name), - scenarios_index: usize::max_value(), + scenarios_index: usize::MAX, weight: 1, transaction_wait: None, transactions: Vec::new(), @@ -961,7 +961,7 @@ impl GooseUser { metrics_channel: None, shutdown_channel: None, // A value of max_value() indicates this user isn't fully initialized yet. - weighted_users_index: usize::max_value(), + weighted_users_index: usize::MAX, load_test_hash, request_cadence: GooseRequestCadence::new(), slept: 0, @@ -1144,9 +1144,9 @@ impl GooseUser { /// of precedence: /// 1. `--host` (host specified on the command line when running load test) /// 2. [`Scenario`](./struct.Scenario.html)`.host` (default host defined for the - /// current scenario) + /// current scenario) /// 3. [`GooseDefault::Host`](../config/enum.GooseDefault.html#variant.Host) (default host - /// defined for the current load test) + /// defined for the current load test) pub fn build_url(&self, path: &str) -> Result> { // If URL includes a host, simply use it. if let Ok(parsed_path) = Url::parse(path) { @@ -2177,7 +2177,7 @@ impl GooseUser { /// - A manually built client is specific to a single Goose thread -- if you are /// generating a large load test with many users, each will need to manually build their /// own client (typically you'd do this in a Transaction that is registered with - /// [`Transaction::set_on_start()`] in each Scenario requiring a custom client; + /// [`Transaction::set_on_start()`] in each Scenario requiring a custom client; /// - Manually building a client will completely replace the automatically built client /// with a brand new one, so any configuration, cookies or headers set in the previously /// built client will be gone; @@ -2811,7 +2811,7 @@ impl Transaction { pub fn new(function: TransactionFunction) -> Self { trace!("new transaction"); Transaction { - transactions_index: usize::max_value(), + transactions_index: usize::MAX, name: "".to_string(), weight: 1, sequence: 0,