Browse Source

Remove locale-dependent string checking

We were checking if an exception was caused by a specific reason "Not a
directory". Alas, this reason is locale-dependent and can fail on
systems that are not set to en_US.UTF-8. This commit addresses this by
deriving what the locale-dependent error message would be and using that
for comparison with the actual exception thrown.

Closes #41689
Jason Tedor 6 years ago
parent
commit
3f15d57901

+ 9 - 1
server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java

@@ -171,7 +171,15 @@ public class PluginsServiceTests extends ESTestCase {
             if (Constants.WINDOWS) {
                 assertThat(e.getCause(), instanceOf(NoSuchFileException.class));
             } else {
-                assertThat(e.getCause(), hasToString(containsString("Not a directory")));
+                // force a "Not a directory" exception to be thrown so that we can extract the locale-dependent message
+                final String expected;
+                try (InputStream ignored = Files.newInputStream(desktopServicesStore.resolve("not-a-directory"))) {
+                    throw new AssertionError();
+                } catch (final FileSystemException inner) {
+                    // locale-dependent translation of "Not a directory"
+                    expected = inner.getReason();
+                }
+                assertThat(e.getCause(), hasToString(containsString(expected)));
             }
         }
     }