Skip to content

Commit

Permalink
✅ Add unit test for write permission check
Browse files Browse the repository at this point in the history
  • Loading branch information
evrignaud committed Nov 13, 2015
1 parent a710b70 commit 716fb69
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/java/org/fim/FimTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
*/
package org.fim;

import static org.apache.commons.lang3.SystemUtils.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.fim.command.exception.BadFimUsageException;
import org.fim.command.exception.RepositoryCreationException;
import org.fim.model.Context;
import org.fim.model.HashMode;
import org.fim.tooling.RepositoryTool;
Expand Down Expand Up @@ -63,6 +67,26 @@ public void fimRepositoryAlreadyExist() throws Exception
cut.run(new String[]{"init", "-y"}, context);
}

@Test(expected = RepositoryCreationException.class)
public void fimRepositoryNotWritable() throws Exception
{
if (IS_OS_WINDOWS)
{
// Ignore this test for Windows
throw new RepositoryCreationException();
}

tool.setReadOnly(rootDir);
try
{
cut.run(new String[]{"init", "-y"}, context);
}
finally
{
tool.setReadWrite(rootDir);
}
}

@Test(expected = BadFimUsageException.class)
public void fimDoesNotExist() throws Exception
{
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/fim/tooling/RepositoryTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public void setFileContent(Path file, String content) throws IOException
Files.write(file, sb.toString().getBytes(), CREATE);
}

public void setReadOnly(Path rootDir) throws IOException
{
setPermissions(rootDir.toAbsolutePath().toString(), "r-xr-xr-x", "R");
}

public void setReadWrite(Path rootDir) throws IOException
{
setPermissions(rootDir.toAbsolutePath().toString(), "rwxrwxrwx", "");
}

public void setPermissions(String fileName, String posixPermissions, String dosPermissions) throws IOException
{
Path file = rootDir.resolve(fileName);
Expand Down

0 comments on commit 716fb69

Please sign in to comment.