Skip to content

Commit

Permalink
agave-validator: add args tests for set-log-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau committed Feb 14, 2025
1 parent ddec7bd commit bba1eb9
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions validator/src/commands/set_log_filter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
use {
crate::{admin_rpc_service, cli::DefaultArgs},
crate::{admin_rpc_service, cli::DefaultArgs, commands::FromClapArgMatches},
clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand},
std::{path::Path, process::exit},
};

const COMMAND: &str = "set-log-filter";

#[derive(Debug, PartialEq)]
pub struct SetLogFilterArg {
pub filter: String,
}

impl FromClapArgMatches for SetLogFilterArg {
fn from_clap_arg_match(matches: &ArgMatches) -> Self {
SetLogFilterArg {
filter: value_t_or_exit!(matches, "filter", String),
}
}
}

pub fn command(_default_args: &DefaultArgs) -> App<'_, '_> {
SubCommand::with_name("set-log-filter")
SubCommand::with_name(COMMAND)
.about("Adjust the validator log filter")
.arg(
Arg::with_name("filter")
Expand All @@ -17,12 +32,34 @@ pub fn command(_default_args: &DefaultArgs) -> App<'_, '_> {
}

pub fn execute(matches: &ArgMatches, ledger_path: &Path) {
let filter = value_t_or_exit!(matches, "filter", String);
let set_log_filter_arg = SetLogFilterArg::from_clap_arg_match(matches);

let admin_client = admin_rpc_service::connect(ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.set_log_filter(filter).await })
.block_on(async move {
admin_client
.await?
.set_log_filter(set_log_filter_arg.filter)
.await
})
.unwrap_or_else(|err| {
println!("set log filter failed: {err}");
exit(1);
});
}

#[cfg(test)]
mod tests {
use {super::*, crate::commands::tests::verify_args_struct_by_command};

#[test]
fn verify_args_struct_by_command_set_log_filter_with_filter() {
verify_args_struct_by_command(
command(&DefaultArgs::default()),
vec![COMMAND, "expected_filter_value"],
SetLogFilterArg {
filter: "expected_filter_value".to_string(),
},
);
}
}

0 comments on commit bba1eb9

Please sign in to comment.