Skip to content

Better management of temporary files in RecursiveAddTest #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/test/java/io/ipfs/api/RecursiveAddTest.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
package io.ipfs.api;

import java.io.File;
import java.nio.file.*;
import java.util.*;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import io.ipfs.multiaddr.MultiAddress;

public class RecursiveAddTest {

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

static Path TMPDATA = Paths.get("target/tmpdata");
static File TMPDATA = new File("target/tmpdata");

@BeforeClass
public static void createTmpData() {
TMPDATA.mkdirs();
}

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder(TMPDATA);

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

String EXPECTED = "QmX5fZ6aUxNTAS7ZfYc8f4wPoMx6LctuNbMjuJZ9EmUSr6";

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

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

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

Path base = TMPDATA.resolve("largebininsubdirdata");
Path base = tempFolder.newFolder().toPath();
base.toFile().mkdirs();
Path bindir = base.resolve("moredata");
bindir.toFile().mkdirs();
Expand Down