Skip to content

GH 731 - review#362

Merged
czarte merged 55 commits into
masterfrom
GH-731
Feb 7, 2024
Merged

GH 731 - review#362
czarte merged 55 commits into
masterfrom
GH-731

Conversation

@czarte

@czarte czarte commented Nov 10, 2023

Copy link
Copy Markdown
Collaborator

No description provided.

czarte added 24 commits August 23, 2023 20:33
…d bools for data_dir, config_file and real_user to MultiConfig, fixing the test
…e able to push into Vcl Vector, add processing in MultiConfig, add processing in server_initializer_collected_params
… to MultiConfig and selecting them to computed_value_names on behalf of their type
…inery to determine if real-user is specified in config-file
…zer_collected_params, closure for keeping in node_configurator, final removal of redundant construction of multiconfig
…orted server_initializer_collected_params and determine_user_specific_data fncs, new fns value_opt for VclArg and tests for them
…ed_params, added handling for tilde in data_directory and config_file paths
…er_collected_params, fixed formatting for get_real_user_from_vcl
…zer_collected_params_handle_config_file_from_commandline_and_real_user_from_config_file_with_data_dir_started_by_tilde
@czarte
czarte requested a review from dnwiebe November 10, 2023 12:00

@dnwiebe dnwiebe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resume at node_configurator/mod.rs

Comment thread node/tests/utils.rs Outdated
Comment thread node/src/test_utils/mod.rs Outdated
Comment thread masq_lib/src/multi_config.rs
Comment thread masq_lib/src/multi_config.rs Outdated
Comment thread masq_lib/src/multi_config.rs Outdated
Comment thread masq_lib/src/multi_config.rs Outdated

#[test]
fn command_line_vcl_return_value_from_vcl_args_by_name() {
let command_line: Vec<String> = vec![

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a utility function with a long name that you could use in place of this? Something like vec_of_slices_to_vec_of_strings() or something?

Comment thread masq_lib/src/multi_config.rs Outdated
.collect();

let subject = CommandLineVcl::new(command_line.clone());
let existing_value = match subject

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this match at the beginning could be replaced with a .map() at the end. Also, this sequence of code that you write once for existing_value and once for non_existing_value could probably be made into a local function or closure and called twice. If locating a VclArg inside a VirtualCommandLine by name turns out to be useful enough, it could turn into a local utility function that other tests could use.

Comment thread node/src/server_initializer.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs Outdated
Comment thread node/src/node_configurator/mod.rs
Comment thread node/src/node_configurator/mod.rs
Comment thread node/src/node_configurator/mod.rs

@dnwiebe dnwiebe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resume at node_configurator_standard.rs:1001

Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated

let multi_config = gathered_params.multi_config;
let args = ArgsBuilder::new().param("--data-directory", home_dir.to_str().unwrap());
let args_vec: Vec<String> = args.into();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you creating a slice, converting to a Vec, and then back to a slice? I don't know what ArgsBuilder::new() produces.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is some machinery I took from other tests, should I investigate it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try this on one place and then create card out of it (good first issue)

Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
Comment thread node/src/node_configurator/node_configurator_standard.rs
Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
{
assert_eq!(
value_m!(env_multiconfig, "data-directory", String).unwrap(),
"booga/data_dir/MASQ/polygon-mainnet".to_string()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand where the "data_dir" part of this path came from. If it came from the DirsWrapperMock object, it seems as though it should have the complicated home_dir pasted on the beginning of it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data_dir is the placeholder in tests for .local/share directory

Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
let result = server_initializer_collected_params(&dir_wrapper, args_vec.as_slice());
let env_multiconfig = result.unwrap();

assert_eq!(env_multiconfig.is_user_specified("--data-directory"), false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions look to me to be very similar--maybe identical--to the assertions in the test above. So I wonder: how are these tests different? Are both required?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is testing the scenario, when we specify the config-file with dot, assertions just proving that we correct the path correctly and we can read from config file - so real-user and dns-servers are asserted right way

@dnwiebe dnwiebe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resume at node_configurator_standard.rs:253

Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
Comment thread node/src/node_configurator/node_configurator_standard.rs Outdated
Comment thread node/src/node_configurator/node_configurator_standard.rs
Comment thread node/src/node_configurator/node_configurator_standard.rs
fill_up_config_file(config_file);

let env_vec_array = vec![
("MASQ_CONFIG_FILE", "config.toml"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.toml is a default. Can you specify something different here to prove that the default isn't leaking through somehow?

environment_vcl: Box<dyn VirtualCommandLine>,
commandline_vcl: Box<dyn VirtualCommandLine>,
user_specific_data: UserSpecifiedData,
) -> (Vec<String>, Vec<String>) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think these _vcls could be replaced with a MultiConfig. ...sorry...

user_specific_data: UserSpecifiedData,
) -> (Vec<String>, Vec<String>) {
let mut unspecified_vec: Vec<String> = vec!["".to_string()];
let mut specified_vec: Vec<String> = vec!["".to_string()];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move these down to nearer where they're used?

|key: &str, value: &str, specified: bool| match value.is_empty() {
true => (),
false => match specified {
true => match specified_vec.contains(&key.to_string()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some code duplication here. You already have some local functions; you can probably pull out the match [un]specified_vec part into another one.

Also, the do-this-if-it-already-exists-or-this-if-it-doesn't logic is already part of HashMap, if you decided to use that. Unfortunately, what you need to make a VCL is a vector. However, there might be an easy way to convert a HashMap into a Vec with pairs. I don't know, but it might be worth looking into to simplify this code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I think you can do it by calling .iter() on the HashMap and then fold() on the result, starting with an empty vector. Every time through the closure you pass to fold(), push the two items in the pair onto the vector; that should do it, maybe in two or three lines.

user_specific_data.real_user_spec,
);

let (cmd_real_user, cmd_real_user_specified) = extract_value_from_vcl(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three operations on real-user might be unnecessary here if you pass in a MultiConfig instead of three vectors.

Box::new(environment_vcl),
Box::new(commandline_vcl),
];
//TODO write test for MultiConfig "try_new" merge line 76

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably either be done or removed.

Box::new(commandline_vcl),
];
//TODO write test for MultiConfig "try_new" merge line 76
if unspecified_vec.len() > 1 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get rid of these if statements. If a Vcl is empty, it won't affect the MultiConfig.

user_specific_data.real_user_spec,
);

let mut fill_specified_or_unspecified_box =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that there are a lot of paths through this code. I'm concerned that not all of them may be exercised by tests. If this piece of functionality retains a significant amount of complexity after you switch to MultiConfig, I'd recommend that you run the tests at least once with Coverage and make sure that all the paths through the code are covered.

czarte and others added 27 commits December 4, 2023 12:51
@czarte
czarte merged commit a50e526 into master Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants