Add test to ensure templates don't accept invalid index values

This commit is contained in:
Simon Willnauer 2016-01-18 13:00:10 +01:00
parent e52a873d1a
commit b7c0ac6ad6
1 changed files with 8 additions and 4 deletions

View File

@ -321,21 +321,25 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get(); GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty()); assertThat(response.getIndexTemplates(), empty());
client().admin().indices().preparePutTemplate("template_1") try {
client().admin().indices().preparePutTemplate("template_1")
.setTemplate("te*") .setTemplate("te*")
.setSettings(Settings.builder().put("does_not_exist", "test")) .setSettings(Settings.builder().put("does_not_exist", "test"))
.get(); .get();
fail();
} catch (IllegalArgumentException ex) {
assertEquals("unknown setting [does_not_exist]", ex.getMessage());
}
response = client().admin().indices().prepareGetTemplates().get(); response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), hasSize(1)); assertThat(response.getIndexTemplates(), hasSize(1));
assertThat(response.getIndexTemplates().get(0).getSettings().getAsMap().size(), equalTo(1)); assertThat(response.getIndexTemplates().get(0).getSettings().getAsMap().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.does_not_exist"), equalTo("test")); assertNull(response.getIndexTemplates().get(0).getSettings().get("index.does_not_exist"));
createIndex("test"); createIndex("test");
//the wrong setting has no effect but does get stored among the index settings
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get(); GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getIndexToSettings().get("test").getAsMap().get("index.does_not_exist"), equalTo("test")); assertNull(getSettingsResponse.getIndexToSettings().get("test").getAsMap().get("index.does_not_exist"));
} }
public void testIndexTemplateWithAliases() throws Exception { public void testIndexTemplateWithAliases() throws Exception {