-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have consistent warning between CLI, ENV and TOML config #3969
Conversation
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
8111e58
to
2b363c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -2073,6 +2110,31 @@ public void rpcHttpOptionsRequiresServiceToBeEnabled() { | |||
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); | |||
} | |||
|
|||
@Test | |||
public void rpcHttpOptionsRequiresServiceToBeEnabledToml() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have junit 5 now, creating a parameterized tests for both command line and toml woud be nice and keep this BesuCOmmandTest a little bit smaller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could start a BesuCommandTomlTest file perhaps?
try { | ||
return !option.stringValues().isEmpty() | ||
|| commandLine.getDefaultValueProvider().defaultValue(option) != null; | ||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the try catch here? Does default value fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultValue throws Exception when fails to load default value from provider, in this case it would be an IOException as it reads value from config file. It shouldn't throw because the default value has been loaded prior to this, if fails to load config file, besu exits before here.
option -> { | ||
try { | ||
return !option.stringValues().isEmpty() | ||
|| commandLine.getDefaultValueProvider().defaultValue(option) != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work for environment variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, default value provider in besu checks for environmental variables before config file.
@@ -2073,6 +2110,31 @@ public void rpcHttpOptionsRequiresServiceToBeEnabled() { | |||
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); | |||
} | |||
|
|||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see any tests for environment variables, can test be added for that as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look good, just a small refactoring suggestion.
It feels like there should be an easier way to check the defaults, e.g. option.defaultValue() but I couldn't find anything that worked with the tests.
createTempFile( | ||
"toml", | ||
"miner-coinbase=\"" | ||
+ requestedCoinbase.toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant toString()
@@ -99,10 +99,16 @@ public static void checkMultiOptionDependencies( | |||
private static String getAffectedOptions( | |||
final CommandLine commandLine, final List<String> dependentOptionsNames) { | |||
return commandLine.getCommandSpec().options().stream() | |||
.filter(option -> Arrays.stream(option.names()).anyMatch(dependentOptionsNames::contains)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling this into its own filter makes this a lot cleaner 👍
try { | ||
return !option.stringValues().isEmpty() | ||
|| commandLine.getDefaultValueProvider().defaultValue(option) != null; | ||
} catch (Exception e) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could extract the exception throwing part into its own method to hide this complexity from the filter body.
Also, may want to check for empty string as well as null, e.g. !Strings.isNullOrEmpty(...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look
…#3969) * Update CommandLineUtils.java Signed-off-by: wcgcyx <wcgcyx@gmail.com> Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
PR description
Add additional check of option in environment variables and config file for detecting ignored dependent config warning.
Fixed Issue(s)
fixes #2069