Skip to content

Commit

Permalink
Fix test to use a file from another temp directory (#5158)
Browse files Browse the repository at this point in the history
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 <adnapibar@gmail.com>

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
  • Loading branch information
adnapibar authored Nov 8, 2022
1 parent fc47572 commit 9970617
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 9970617

Please sign in to comment.