From 71f519952b622149703200a23f465740add220e1 Mon Sep 17 00:00:00 2001 From: srikanth padakanti Date: Thu, 4 Apr 2024 15:29:02 -0500 Subject: [PATCH] Added a specific test to expect exception wehn accessing the closed indices stats Signed-off-by: srikanth padakanti --- .../action/support/IndicesOptionsTests.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java index 37a3c556804e0..aee9f0859005a 100644 --- a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java +++ b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java @@ -142,6 +142,35 @@ public void testFromOptions() { } } + public void testIllegalArgumentExceptionForClosedIndices() { + final boolean ignoreUnavailable = randomBoolean(); + final boolean allowNoIndices = randomBoolean(); + final boolean expandToOpenIndices = randomBoolean(); + final boolean expandToClosedIndices = true; + final boolean expandToHiddenIndices = randomBoolean(); + final boolean allowAliasesToMultipleIndices = randomBoolean(); + final boolean forbidClosedIndices = true; + final boolean ignoreAliases = randomBoolean(); + final boolean ignoreThrottled = randomBoolean(); + + IllegalArgumentException iae = expectThrows( + IllegalArgumentException.class, + () -> IndicesOptions.fromOptions( + ignoreUnavailable, + allowNoIndices, + expandToOpenIndices, + expandToClosedIndices, + expandToHiddenIndices, + allowAliasesToMultipleIndices, + forbidClosedIndices, + ignoreAliases, + ignoreThrottled + ) + ); + String expectedMessage = "To expand [" + WildcardStates.CLOSED + "] wildcard, please set forbid_closed_indices to `false` "; + assertEquals(expectedMessage, iae.getMessage()); + } + public void testFromOptionsWithDefaultOptions() { boolean ignoreUnavailable = randomBoolean(); boolean allowNoIndices = randomBoolean();