|
21 | 21 | import org.elasticsearch.common.settings.Settings;
|
22 | 22 | import org.elasticsearch.test.ESTestCase;
|
23 | 23 |
|
| 24 | +import java.io.FileNotFoundException; |
24 | 25 | import java.io.IOException;
|
25 | 26 | import java.net.URL;
|
26 | 27 | import java.nio.file.Path;
|
27 | 28 |
|
28 | 29 | import static org.hamcrest.CoreMatchers.endsWith;
|
29 | 30 | import static org.hamcrest.CoreMatchers.notNullValue;
|
30 | 31 | import static org.hamcrest.CoreMatchers.nullValue;
|
| 32 | +import static org.hamcrest.CoreMatchers.startsWith; |
31 | 33 | import static org.hamcrest.Matchers.arrayWithSize;
|
32 | 34 | import static org.hamcrest.Matchers.containsString;
|
33 | 35 | import static org.hamcrest.Matchers.equalTo;
|
|
37 | 39 | * Simple unit-tests for Environment.java
|
38 | 40 | */
|
39 | 41 | public class EnvironmentTests extends ESTestCase {
|
40 |
| - public Environment newEnvironment() throws IOException { |
| 42 | + public Environment newEnvironment() { |
41 | 43 | return newEnvironment(Settings.EMPTY);
|
42 | 44 | }
|
43 | 45 |
|
44 |
| - public Environment newEnvironment(Settings settings) throws IOException { |
| 46 | + public Environment newEnvironment(Settings settings) { |
45 | 47 | Settings build = Settings.builder()
|
46 | 48 | .put(settings)
|
47 | 49 | .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath())
|
@@ -146,4 +148,23 @@ public void testNodeDoesNotRequireLocalStorageButHasPathData() {
|
146 | 148 | assertThat(e, hasToString(containsString("node does not require local storage yet path.data is set to [" + pathData + "]")));
|
147 | 149 | }
|
148 | 150 |
|
| 151 | + public void testNonExistentTempPathValidation() { |
| 152 | + Settings build = Settings.builder() |
| 153 | + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) |
| 154 | + .build(); |
| 155 | + Environment environment = new Environment(build, null, createTempDir().resolve("this_does_not_exist")); |
| 156 | + FileNotFoundException e = expectThrows(FileNotFoundException.class, environment::validateTmpFile); |
| 157 | + assertThat(e.getMessage(), startsWith("Temporary file directory [")); |
| 158 | + assertThat(e.getMessage(), endsWith("this_does_not_exist] does not exist or is not accessible")); |
| 159 | + } |
| 160 | + |
| 161 | + public void testTempPathValidationWhenRegularFile() throws IOException { |
| 162 | + Settings build = Settings.builder() |
| 163 | + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) |
| 164 | + .build(); |
| 165 | + Environment environment = new Environment(build, null, createTempFile("something", ".test")); |
| 166 | + IOException e = expectThrows(IOException.class, environment::validateTmpFile); |
| 167 | + assertThat(e.getMessage(), startsWith("Configured temporary file directory [")); |
| 168 | + assertThat(e.getMessage(), endsWith(".test] is not a directory")); |
| 169 | + } |
149 | 170 | }
|
0 commit comments