Skip to content

Commit

Permalink
Fix watcher search template test after elastic#65332
Browse files Browse the repository at this point in the history
In elastic#65332, the serialization of the WatcherSearchTemplateRequest class
changed to use IndicesOptions built in XContent facilities. This had
the side effect of fixing the handling of `all` for `expand_wildcards`
to include hidden indices. However, the tests in WatcherUtilsTests were
missed. This change updates those tests.
  • Loading branch information
jaymode committed Nov 23, 2020
1 parent ba062c5 commit ab456bc
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils.formatDate;
import static org.elasticsearch.xpack.core.watcher.support.WatcherUtils.flattenModel;
import static org.elasticsearch.xpack.watcher.input.search.ExecutableSearchInput.DEFAULT_SEARCH_TYPE;
import static org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.getRandomSupportedSearchType;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -91,7 +92,9 @@ public void testResponseToData() throws Exception {
public void testSerializeSearchRequest() throws Exception {
String[] expectedIndices = generateRandomStringArray(5, 5, true);
IndicesOptions expectedIndicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS);
randomBoolean(), randomBoolean(), DEFAULT_INDICES_OPTIONS.allowAliasesToMultipleIndices(),
DEFAULT_INDICES_OPTIONS.forbidClosedIndices(), DEFAULT_INDICES_OPTIONS.ignoreAliases(),
DEFAULT_INDICES_OPTIONS.ignoreThrottled());
SearchType expectedSearchType = getRandomSupportedSearchType();

BytesReference expectedSource = null;
Expand Down Expand Up @@ -157,18 +160,14 @@ public void testDeserializeSearchRequest() throws Exception {
}
}

IndicesOptions indicesOptions = WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS;
IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
if (randomBoolean()) {
indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS);
builder.startObject("indices_options")
.field("allow_no_indices", indicesOptions.allowNoIndices())
.field("expand_wildcards", indicesOptions.expandWildcardsClosed() && indicesOptions.expandWildcardsOpen() ? "all" :
indicesOptions.expandWildcardsClosed() ? "closed" :
indicesOptions.expandWildcardsOpen() ? "open" :
"none")
.field("ignore_unavailable", indicesOptions.ignoreUnavailable())
.endObject();
randomBoolean(), randomBoolean(), indicesOptions.allowAliasesToMultipleIndices(),
indicesOptions.forbidClosedIndices(), indicesOptions.ignoreAliases(), indicesOptions.ignoreThrottled());
builder.startObject("indices_options");
indicesOptions.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
}

SearchType searchType = SearchType.DEFAULT;
Expand Down Expand Up @@ -224,5 +223,4 @@ public void testDeserializeSearchRequest() throws Exception {
assertThat(result.getTemplate().getLang(), equalTo(stored ? null : "mustache"));
}
}

}

0 comments on commit ab456bc

Please sign in to comment.