Skip to content

Commit

Permalink
Add explicit count in request validation error message
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <[email protected]>
  • Loading branch information
Anshu Agarwal committed Sep 27, 2022
1 parent 703d918 commit f3cf04d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static org.opensearch.action.ValidateActions.addValidationError;
Expand Down Expand Up @@ -141,7 +142,10 @@ public ActionRequestValidationException validate() {
validationException = addValidationError(("Weight is not a number"), validationException);
}
if (countValueWithZeroWeights > 1) {
validationException = addValidationError(("More than one value has weight set as 0 "), validationException);
validationException = addValidationError(
(String.format(Locale.ROOT, "More than one [%d] value has weight set as 0", countValueWithZeroWeights)),
validationException
);
}
return validationException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testValidate_TwoZonesWithZeroWeight() {
request.setWeightedRouting(new BytesArray(reqString), XContentType.JSON);
ActionRequestValidationException actionRequestValidationException = request.validate();
assertNotNull(actionRequestValidationException);
assertTrue(actionRequestValidationException.getMessage().contains("More than one value has weight set as 0"));
assertTrue(actionRequestValidationException.getMessage().contains("More than one [2] value has weight set as " + "0"));
}

public void testValidate_MissingWeights() {
Expand Down

0 comments on commit f3cf04d

Please sign in to comment.