Resolve inconsistent handling of certain config options. (#1065)

* Resolve inconsistent handling of [Bb]oolean config options by handling primitives the same as the boxed type.

Signed-off-by: Steven J Schroeder <steven.schroeder@consensys.net>
pull/1089/head
Steven Schroeder 5 years ago committed by GitHub
parent a7dedec986
commit 4050988bf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      besu/src/main/java/org/hyperledger/besu/cli/util/TomlConfigFileDefaultProvider.java
  2. 36
      besu/src/test/java/org/hyperledger/besu/cli/TomlConfigFileDefaultProviderTest.java

@ -64,11 +64,11 @@ public class TomlConfigFileDefaultProvider implements IDefaultValueProvider {
final String defaultValue;
// Convert config values to the right string representation for default string value
if (optionSpec.type().equals(Boolean.class)) {
if (optionSpec.type().equals(Boolean.class) || optionSpec.type().equals(boolean.class)) {
defaultValue = getBooleanEntryAsString(optionSpec);
} else if (optionSpec.isMultiValue() || isArray) {
defaultValue = getListEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Integer.class)) {
} else if (optionSpec.type().equals(Integer.class) || optionSpec.type().equals(int.class)) {
defaultValue = getIntegerEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Wei.class)) {
defaultValue = getIntegerEntryAsString(optionSpec);

@ -72,21 +72,25 @@ public class TomlConfigFileDefaultProviderTest {
new TomlConfigFileDefaultProvider(mockCommandLine, tempConfigFile);
// this option must be found in config
assertThat(providerUnderTest.defaultValue(OptionSpec.builder("a-short-option").build()))
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("a-short-option").type(Integer.class).build()))
.isEqualTo("123");
// this option must be found in config as one of its names is present in the file.
// also this is the shortest one.
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("a-short-option", "another-name-for-the-option").build()))
OptionSpec.builder("a-short-option", "another-name-for-the-option")
.type(Integer.class)
.build()))
.isEqualTo("123");
// this option must be found in config as one of its names is present in the file.
// also this is the longest one.
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("l", "longer", "a-longer-option").build()))
OptionSpec.builder("l", "longer", "a-longer-option").type(Integer.class).build()))
.isEqualTo("1234");
}
}
@ -97,8 +101,11 @@ public class TomlConfigFileDefaultProviderTest {
Map<String, OptionSpec> validOptionsMap = new HashMap<>();
validOptionsMap.put("--a-boolean-option", null);
validOptionsMap.put("--another-boolean-option", null);
validOptionsMap.put("--a-primitive-boolean-option", null);
validOptionsMap.put("--another-primitive-boolean-option", null);
validOptionsMap.put("--a-multi-value-option", null);
validOptionsMap.put("--an-int-value-option", null);
validOptionsMap.put("--a-primitive-int-value-option", null);
validOptionsMap.put("--a-wei-value-option", null);
validOptionsMap.put("--a-string-value-option", null);
validOptionsMap.put("--a-nested-multi-value-option", null);
@ -113,10 +120,16 @@ public class TomlConfigFileDefaultProviderTest {
fileWriter.newLine();
fileWriter.write("another-boolean-option=false");
fileWriter.newLine();
fileWriter.write("a-primitive-boolean-option=true");
fileWriter.newLine();
fileWriter.write("another-primitive-boolean-option=false");
fileWriter.newLine();
fileWriter.write("a-multi-value-option=[\"value1\", \"value2\"]");
fileWriter.newLine();
fileWriter.write("an-int-value-option=123");
fileWriter.newLine();
fileWriter.write("a-primitive-int-value-option=456");
fileWriter.newLine();
fileWriter.write("a-wei-value-option=1");
fileWriter.newLine();
fileWriter.write("a-string-value-option='my value'");
@ -138,6 +151,18 @@ public class TomlConfigFileDefaultProviderTest {
OptionSpec.builder("another-boolean-option").type(Boolean.class).build()))
.isEqualTo("false");
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("a-primitive-boolean-option").type(boolean.class).build()))
.isEqualTo("true");
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("another-primitive-boolean-option")
.type(boolean.class)
.build()))
.isEqualTo("false");
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("a-multi-value-option").type(Collection.class).build()))
@ -148,6 +173,11 @@ public class TomlConfigFileDefaultProviderTest {
OptionSpec.builder("an-int-value-option").type(Integer.class).build()))
.isEqualTo("123");
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("a-primitive-int-value-option").type(int.class).build()))
.isEqualTo("456");
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("a-wei-value-option").type(Wei.class).build()))

Loading…
Cancel
Save