From 07b9293af340b8885c4bf01a389826a877888acc Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 11 Nov 2022 12:02:28 -0800 Subject: [PATCH] Fix test to use a file from another temp directory (#5158) (#5165) The test used an absolute path which is incorrect as it made a platform dependent assumption. This change fixes that. Signed-off-by: Rabi Panda --- .../opensearch/index/analysis/AnalysisTests.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/opensearch/index/analysis/AnalysisTests.java b/server/src/test/java/org/opensearch/index/analysis/AnalysisTests.java index 01281ea323e60..0446ac78d4efc 100644 --- a/server/src/test/java/org/opensearch/index/analysis/AnalysisTests.java +++ b/server/src/test/java/org/opensearch/index/analysis/AnalysisTests.java @@ -136,14 +136,24 @@ public void testParseWordListError() throws IOException { assertEquals("Line [1]: Error while parsing rule = abcd", ex.getMessage()); } - public void testParseWordListOutsideConfigDirError() { + public void testParseWordListOutsideConfigDirError() throws IOException { Path home = createTempDir(); - Path dict = home.resolve("/etc/os-release"); + Path temp = createTempDir(); + Path dict = temp.resolve("foo.dict"); + try (BufferedWriter writer = Files.newBufferedWriter(dict, StandardCharsets.UTF_8)) { + writer.write("abcd"); + writer.write('\n'); + } Settings nodeSettings = Settings.builder().put("foo.bar_path", dict).put(Environment.PATH_HOME_SETTING.getKey(), home).build(); Environment env = TestEnvironment.newEnvironment(nodeSettings); RuntimeException ex = expectThrows( RuntimeException.class, - () -> Analysis.parseWordList(env, nodeSettings, "foo.bar", s -> { throw new RuntimeException("Error while parsing"); }) + () -> Analysis.parseWordList( + env, + nodeSettings, + "foo.bar", + s -> { throw new RuntimeException("Error while parsing rule = " + s); } + ) ); assertEquals("Line [1]: Invalid rule", ex.getMessage()); }