Skip to content

Commit

Permalink
Test fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
at88mph committed May 23, 2024
1 parent f55eb30 commit 55ba2c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,17 @@ public static String get(final Path path, final String attributeKey) throws IOEx

// getfattr command returns the full attribute in key=value format.
final String commandOutput = XAttrCommandExecutor.execute(command);
final Matcher commandOutputMatcher = XAttrCommandExecutor.GET_COMMAND_OUTPUT_PATTERN.matcher(commandOutput);

if (!commandOutputMatcher.find()) {
throw new IllegalStateException("Unknown command output: " + commandOutput);
if (commandOutput == null) {
return null;
} else {
return commandOutputMatcher.group(1);
final Matcher commandOutputMatcher = XAttrCommandExecutor.GET_COMMAND_OUTPUT_PATTERN.matcher(commandOutput);

if (!commandOutputMatcher.find()) {
throw new IllegalStateException("Unknown command output: " + commandOutput);
} else {
return commandOutputMatcher.group(1);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ public void setAndGetUserAttribute() throws Exception {
final Path target = fs.getPath(XAttrCommandExecutorTest.ROOT, folderName).toAbsolutePath();
Files.createDirectory(target);

try {
XAttrCommandExecutor.get(target, "user.foo");
Assert.fail("Should not already have user.foo attribute.");
} catch (IOException ioException) {
// Good
}
Assert.assertNull("Should not already have user.foo attribute.",
XAttrCommandExecutor.get(target, "user.foo"));

XAttrCommandExecutor.set(target, "user.foo", "bar");

Expand Down Expand Up @@ -141,14 +137,15 @@ public void setAttributeNullKey() throws Exception {
XAttrCommandExecutor.set(target, null, "bogusValue");
}

@Test(expected = IOException.class)
@Test
public void getAttributeNoSuchKey() throws Exception {
final String folderName = "getAttributeFail-" + UUID.randomUUID();
final FileSystem fs = FileSystems.getDefault();
final Path target = fs.getPath(XAttrCommandExecutorTest.ROOT, folderName).toAbsolutePath();
Files.createDirectory(target);

XAttrCommandExecutor.get(target, "user.bogus.attr");
Assert.assertNull("Should be null for no such attribute.",
XAttrCommandExecutor.get(target, "user.bogus.attr"));
}

@Test(expected = IllegalArgumentException.class)
Expand Down

0 comments on commit 55ba2c7

Please sign in to comment.