|
24 | 24 | import org.hamcrest.Matchers; |
25 | 25 |
|
26 | 26 | import java.util.Arrays; |
| 27 | +import java.util.List; |
| 28 | +import java.util.Set; |
| 29 | +import java.util.function.Supplier; |
27 | 30 |
|
28 | 31 | import static java.util.Collections.emptySet; |
29 | 32 | import static org.hamcrest.Matchers.containsString; |
| 33 | +import static org.hamcrest.Matchers.hasToString; |
30 | 34 | import static org.hamcrest.Matchers.is; |
31 | 35 |
|
32 | 36 | public class SettingsModuleTests extends ModuleTestCase { |
@@ -185,4 +189,31 @@ public void testMutuallyExclusiveScopes() { |
185 | 189 | assertThat(e.getMessage(), containsString("Cannot register setting [foo.bar] twice")); |
186 | 190 | } |
187 | 191 | } |
| 192 | + |
| 193 | + public void testPluginSettingWithoutNamespace() { |
| 194 | + final String key = randomAlphaOfLength(8); |
| 195 | + final Setting<String> setting = Setting.simpleString(key, Property.NodeScope); |
| 196 | + runSettingWithoutNamespaceTest( |
| 197 | + key, () -> new SettingsModule(Settings.EMPTY, List.of(setting), List.of(), Set.of(), Set.of(), Set.of())); |
| 198 | + } |
| 199 | + |
| 200 | + public void testClusterSettingWithoutNamespace() { |
| 201 | + final String key = randomAlphaOfLength(8); |
| 202 | + final Setting<String> setting = Setting.simpleString(key, Property.NodeScope); |
| 203 | + runSettingWithoutNamespaceTest( |
| 204 | + key, () -> new SettingsModule(Settings.EMPTY, List.of(), List.of(), Set.of(), Set.of(setting), Set.of())); |
| 205 | + } |
| 206 | + |
| 207 | + public void testIndexSettingWithoutNamespace() { |
| 208 | + final String key = randomAlphaOfLength(8); |
| 209 | + final Setting<String> setting = Setting.simpleString(key, Property.IndexScope); |
| 210 | + runSettingWithoutNamespaceTest( |
| 211 | + key, () -> new SettingsModule(Settings.EMPTY, List.of(), List.of(), Set.of(), Set.of(), Set.of(setting))); |
| 212 | + } |
| 213 | + |
| 214 | + private void runSettingWithoutNamespaceTest(final String key, final Supplier<SettingsModule> supplier) { |
| 215 | + final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, supplier::get); |
| 216 | + assertThat(e, hasToString(containsString("setting [" + key + "] is not in any namespace, its name must contain a dot"))); |
| 217 | + } |
| 218 | + |
188 | 219 | } |
0 commit comments