Skip to content

Commit

Permalink
Fix method signature and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Sep 29, 2024
1 parent 083de17 commit 94f34ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions solr/core/src/java/org/apache/solr/cli/ConfigTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public List<Option> getOptions() {
.longOpt("value")
.argName("VALUE")
.hasArg()
.required(false) // should be true when -v is removed.
.required(false)
.desc("Set the property to this value; accepts JSON objects and strings.")
.build(),
SolrCLI.OPTION_SOLRURL,
Expand All @@ -128,7 +128,9 @@ public void runImpl(CommandLine cli) throws Exception {
if (property == null) {
throw new MissingArgumentException("'property' is a required option.");
}
if (value == null) {

// value is required unless the property is one of the unset- type.
if (!action.contains("unset-") && value == null) {
throw new MissingArgumentException("'value' is a required option.");
}
Map<String, Object> jsonObj = new HashMap<>();
Expand All @@ -147,7 +149,7 @@ public void runImpl(CommandLine cli) throws Exception {
String updatePath = "/" + collection + "/config";

echo("\nPOSTing request to Config API: " + solrUrl + updatePath);
echoIfVerbose(jsonBody, cli);
echoIfVerbose(jsonBody);

try (SolrClient solrClient =
SolrCLI.getSolrClient(
Expand Down
6 changes: 6 additions & 0 deletions solr/packaging/test/test_config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ teardown() {
@test "setting property" {
solr create -c COLL_NAME

run solr config -c COLL_NAME --action set-property --property updateHandler.autoCommit.maxDocs --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "'value' is a required option."

run solr config -c COLL_NAME --action set-property --property updateHandler.autoCommit.maxDocs --value 100 --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully set-property updateHandler.autoCommit.maxDocs to 100"

run solr config -c COLL_NAME --action unset-property --property updateHandler.autoCommit.maxDocs --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully unset-property updateHandler.autoCommit.maxDocs"
}

@test "short form of setting property" {
Expand Down

0 comments on commit 94f34ae

Please sign in to comment.