Skip to content

Commit d443640

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

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
package io.ipfs.api;
22

3+
import java.io.File;
34
import java.nio.file.*;
45
import java.util.*;
56

67
import org.junit.Assert;
8+
import org.junit.BeforeClass;
9+
import org.junit.Rule;
710
import org.junit.Test;
11+
import org.junit.rules.TemporaryFolder;
812

913
import io.ipfs.multiaddr.MultiAddress;
1014

1115
public class RecursiveAddTest {
1216

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

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

1729
@Test
1830
public void testAdd() throws Exception {
1931
System.out.println("ipfs version: " + ipfs.version());
2032

2133
String EXPECTED = "QmX5fZ6aUxNTAS7ZfYc8f4wPoMx6LctuNbMjuJZ9EmUSr6";
2234

23-
Path base = Files.createTempDirectory("test");
35+
Path base = tempFolder.newFolder().toPath();
2436
Files.write(base.resolve("index.html"), "<html></html>".getBytes());
2537
Path js = base.resolve("js");
2638
js.toFile().mkdirs();
@@ -35,7 +47,7 @@ public void testAdd() throws Exception {
3547
public void binaryRecursiveAdd() throws Exception {
3648
String EXPECTED = "Qmd1dTx4Z1PHxSHDR9jYoyLJTrYsAau7zLPE3kqo14s84d";
3749

38-
Path base = TMPDATA.resolve("bindata");
50+
Path base = tempFolder.newFolder().toPath();
3951
base.toFile().mkdirs();
4052
byte[] bindata = new byte[1024*1024];
4153
new Random(28).nextBytes(bindata);
@@ -53,7 +65,7 @@ public void binaryRecursiveAdd() throws Exception {
5365
public void largeBinaryRecursiveAdd() throws Exception {
5466
String EXPECTED = "QmZdfdj7nfxE68fBPUWAGrffGL3sYGx1MDEozMg73uD2wj";
5567

56-
Path base = TMPDATA.resolve("largebindata");
68+
Path base = tempFolder.newFolder().toPath();
5769
base.toFile().mkdirs();
5870
byte[] bindata = new byte[100 * 1024*1024];
5971
new Random(28).nextBytes(bindata);
@@ -73,7 +85,7 @@ public void largeBinaryRecursiveAdd() throws Exception {
7385
public void largeBinaryInSubdirRecursiveAdd() throws Exception {
7486
String EXPECTED = "QmUYuMwCpgaxJhNxRA5Pmje8EfpEgU3eQSB9t3VngbxYJk";
7587

76-
Path base = TMPDATA.resolve("largebininsubdirdata");
88+
Path base = tempFolder.newFolder().toPath();
7789
base.toFile().mkdirs();
7890
Path bindir = base.resolve("moredata");
7991
bindir.toFile().mkdirs();

0 commit comments

Comments
 (0)