Skip to content

Commit 3ea0f1a

Browse files
committed
Better management of temporary files in RecursiveAddTest
1 parent acf0115 commit 3ea0f1a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/test/java/io/ipfs/api/RecursiveAddTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@
44
import java.util.*;
55

66
import org.junit.Assert;
7+
import org.junit.BeforeClass;
8+
import org.junit.Rule;
79
import org.junit.Test;
10+
import org.junit.rules.TemporaryFolder;
811

912
import io.ipfs.multiaddr.MultiAddress;
1013

1114
public class RecursiveAddTest {
1215

1316
private final IPFS ipfs = new IPFS(new MultiAddress("/ip4/127.0.0.1/tcp/5001"));
1417

15-
static Path TMPDATA = Paths.get("target/tmpdata");
18+
static File TMPDATA = new File("target/tmpdata");
19+
20+
@BeforeClass
21+
public static void createTmpData() {
22+
TMPDATA.mkdirs();
23+
}
24+
25+
@Rule
26+
public TemporaryFolder tempFolder = new TemporaryFolder(TMPDATA);
1627

1728
@Test
1829
public void testAdd() throws Exception {
1930
System.out.println("ipfs version: " + ipfs.version());
2031

2132
String EXPECTED = "QmX5fZ6aUxNTAS7ZfYc8f4wPoMx6LctuNbMjuJZ9EmUSr6";
2233

23-
Path base = Files.createTempDirectory("test");
34+
Path base = tempFolder.newFolder().toPath();
2435
Files.write(base.resolve("index.html"), "<html></html>".getBytes());
2536
Path js = base.resolve("js");
2637
js.toFile().mkdirs();
@@ -35,7 +46,7 @@ public void testAdd() throws Exception {
3546
public void binaryRecursiveAdd() throws Exception {
3647
String EXPECTED = "Qmd1dTx4Z1PHxSHDR9jYoyLJTrYsAau7zLPE3kqo14s84d";
3748

38-
Path base = TMPDATA.resolve("bindata");
49+
Path base = tempFolder.newFolder().toPath();
3950
base.toFile().mkdirs();
4051
byte[] bindata = new byte[1024*1024];
4152
new Random(28).nextBytes(bindata);
@@ -53,7 +64,7 @@ public void binaryRecursiveAdd() throws Exception {
5364
public void largeBinaryRecursiveAdd() throws Exception {
5465
String EXPECTED = "QmZdfdj7nfxE68fBPUWAGrffGL3sYGx1MDEozMg73uD2wj";
5566

56-
Path base = TMPDATA.resolve("largebindata");
67+
Path base = tempFolder.newFolder().toPath();
5768
base.toFile().mkdirs();
5869
byte[] bindata = new byte[100 * 1024*1024];
5970
new Random(28).nextBytes(bindata);
@@ -73,7 +84,7 @@ public void largeBinaryRecursiveAdd() throws Exception {
7384
public void largeBinaryInSubdirRecursiveAdd() throws Exception {
7485
String EXPECTED = "QmUYuMwCpgaxJhNxRA5Pmje8EfpEgU3eQSB9t3VngbxYJk";
7586

76-
Path base = TMPDATA.resolve("largebininsubdirdata");
87+
Path base = tempFolder.newFolder().toPath();
7788
base.toFile().mkdirs();
7889
Path bindir = base.resolve("moredata");
7990
bindir.toFile().mkdirs();

0 commit comments

Comments
 (0)