Skip to content

Commit

Permalink
test(plugins/DbCopy): solve directory creation failure due to limited…
Browse files Browse the repository at this point in the history
… permissions
  • Loading branch information
halibobo1205 committed May 20, 2024
1 parent e7c8d40 commit e6f14ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/src/test/java/org/tron/plugins/DbCopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DbCopyTest extends DbTest {
@Test
public void testRun() {
String[] args = new String[] { "db", "cp", INPUT_DIRECTORY,
tmpDir + UUID.randomUUID()};
genarateTmpDir()};
Assert.assertEquals(0, cli.execute(args));
}

Expand All @@ -32,7 +32,7 @@ public void testNotExist() {
@Test
public void testEmpty() throws IOException {
String[] args = new String[] {"db", "cp", temporaryFolder.newFolder().toString(),
tmpDir + UUID.randomUUID()};
genarateTmpDir()};
Assert.assertEquals(0, cli.execute(args));
}

Expand All @@ -46,7 +46,7 @@ public void testDestIsExist() throws IOException {
@Test
public void testSrcIsFile() throws IOException {
String[] args = new String[] {"db", "cp", temporaryFolder.newFile().toString(),
tmpDir + UUID.randomUUID()};
genarateTmpDir()};
Assert.assertEquals(403, cli.execute(args));
}

Expand Down
10 changes: 10 additions & 0 deletions plugins/src/test/java/org/tron/plugins/DbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ private static void initDB(File file) throws IOException {
}
}
}

/**
* Generate a not-exist temporary directory path.
* @return temporary path
*/
public String genarateTmpDir() {
File dir = Paths.get(tmpDir, UUID.randomUUID().toString()).toFile();
dir.deleteOnExit();
return dir.getPath();
}
}

0 comments on commit e6f14ed

Please sign in to comment.