From 48429a5f6ea4cdd07ba355ab8aa675b60ea3a50c Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Mon, 11 Mar 2024 10:53:28 +0530 Subject: [PATCH] refactor(service): make the add node naming more explicit --- sn_node_manager/src/add_services/config.rs | 2 +- sn_node_manager/src/add_services/mod.rs | 6 ++-- sn_node_manager/src/add_services/tests.rs | 40 +++++++++++----------- sn_node_manager/src/bin/cli/main.rs | 8 ++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/sn_node_manager/src/add_services/config.rs b/sn_node_manager/src/add_services/config.rs index 9d568381e3..1f426208fb 100644 --- a/sn_node_manager/src/add_services/config.rs +++ b/sn_node_manager/src/add_services/config.rs @@ -76,7 +76,7 @@ impl InstallNodeServiceCtxBuilder { } } -pub struct AddServiceOptions { +pub struct AddNodeServiceOptions { pub bootstrap_peers: Vec, pub count: Option, pub env_variables: Option>, diff --git a/sn_node_manager/src/add_services/mod.rs b/sn_node_manager/src/add_services/mod.rs index ddaa8e1510..482b686df7 100644 --- a/sn_node_manager/src/add_services/mod.rs +++ b/sn_node_manager/src/add_services/mod.rs @@ -10,7 +10,7 @@ pub mod config; mod tests; use self::config::{ - AddDaemonServiceOptions, AddFaucetServiceOptions, AddServiceOptions, + AddDaemonServiceOptions, AddFaucetServiceOptions, AddNodeServiceOptions, InstallFaucetServiceCtxBuilder, InstallNodeServiceCtxBuilder, }; use crate::{config::create_owned_dir, VerbosityLevel, DAEMON_SERVICE_NAME}; @@ -32,8 +32,8 @@ use std::{ /// /// There are several arguments that probably seem like they could be handled within the function, /// but they enable more controlled unit testing. -pub async fn add( - options: AddServiceOptions, +pub async fn add_node( + options: AddNodeServiceOptions, node_registry: &mut NodeRegistry, service_control: &dyn ServiceControl, verbosity: VerbosityLevel, diff --git a/sn_node_manager/src/add_services/tests.rs b/sn_node_manager/src/add_services/tests.rs index 4d9919a86c..804c4ac482 100644 --- a/sn_node_manager/src/add_services/tests.rs +++ b/sn_node_manager/src/add_services/tests.rs @@ -8,9 +8,9 @@ use crate::{ add_services::{ - add, add_daemon, add_faucet, + add_daemon, add_faucet, add_node, config::{ - AddDaemonServiceOptions, AddFaucetServiceOptions, AddServiceOptions, + AddDaemonServiceOptions, AddFaucetServiceOptions, AddNodeServiceOptions, InstallNodeServiceCtxBuilder, }, }, @@ -128,8 +128,8 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res .returning(|_| Ok(())) .in_sequence(&mut seq); - add( - AddServiceOptions { + add_node( + AddNodeServiceOptions { local: true, genesis: true, count: None, @@ -223,8 +223,8 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n let custom_rpc_address = Ipv4Addr::new(127, 0, 0, 1); - let result = add( - AddServiceOptions { + let result = add_node( + AddNodeServiceOptions { local: true, genesis: true, count: None, @@ -281,8 +281,8 @@ async fn add_genesis_node_should_return_an_error_if_count_is_greater_than_1() -> let custom_rpc_address = Ipv4Addr::new(127, 0, 0, 1); - let result = add( - AddServiceOptions { + let result = add_node( + AddNodeServiceOptions { local: true, genesis: true, count: Some(3), @@ -433,8 +433,8 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( .returning(|_| Ok(())) .in_sequence(&mut seq); - add( - AddServiceOptions { + add_node( + AddNodeServiceOptions { local: false, genesis: false, count: Some(3), @@ -571,8 +571,8 @@ async fn add_node_should_update_the_bootstrap_peers_inside_node_registry() -> Re .returning(|_| Ok(())) .in_sequence(&mut seq); - add( - AddServiceOptions { + add_node( + AddNodeServiceOptions { local: false, genesis: false, count: None, @@ -683,8 +683,8 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() .returning(|_| Ok(())) .in_sequence(&mut seq); - add( - AddServiceOptions { + add_node( + AddNodeServiceOptions { local: false, genesis: false, count: None, @@ -805,8 +805,8 @@ async fn add_new_node_should_add_another_service() -> Result<()> { .returning(|_| Ok(())) .in_sequence(&mut seq); - add( - AddServiceOptions { + add_node( + AddNodeServiceOptions { local: false, genesis: false, count: None, @@ -908,8 +908,8 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { .returning(|_| Ok(())) .in_sequence(&mut seq); - add( - AddServiceOptions { + add_node( + AddNodeServiceOptions { local: false, genesis: false, count: None, @@ -980,8 +980,8 @@ async fn add_node_should_return_error_if_custom_port_is_used_and_more_than_one_s let custom_port = 12000; - let result = add( - AddServiceOptions { + let result = add_node( + AddNodeServiceOptions { local: true, genesis: false, count: Some(3), diff --git a/sn_node_manager/src/bin/cli/main.rs b/sn_node_manager/src/bin/cli/main.rs index 49cf4cda96..1292a259de 100644 --- a/sn_node_manager/src/bin/cli/main.rs +++ b/sn_node_manager/src/bin/cli/main.rs @@ -13,8 +13,8 @@ use libp2p_identity::PeerId; use semver::Version; use sn_node_manager::{ add_services::{ - add, add_daemon, add_faucet, - config::{AddDaemonServiceOptions, AddFaucetServiceOptions, AddServiceOptions}, + add_daemon, add_faucet, add_node, + config::{AddDaemonServiceOptions, AddFaucetServiceOptions, AddNodeServiceOptions}, }, config::*, helpers::{download_and_extract_release, get_bin_version}, @@ -476,7 +476,7 @@ async fn main() -> Result<()> { &*release_repo, ) .await?; - let options = AddServiceOptions { + let options = AddNodeServiceOptions { local, genesis: peers.first, count, @@ -493,7 +493,7 @@ async fn main() -> Result<()> { env_variables, }; - add(options, &mut node_registry, &service_manager, verbosity).await?; + add_node(options, &mut node_registry, &service_manager, verbosity).await?; node_registry.save()?;