Skip to content

Commit

Permalink
Use @TempDir and don't create files inside build directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Apr 4, 2024
1 parent 840f390 commit 828ed4f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 80 deletions.
16 changes: 6 additions & 10 deletions rpm/src/test/java/org/eclipse/packager/rpm/EmptyWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@
import org.eclipse.packager.rpm.build.RpmBuilder;
import org.eclipse.packager.rpm.build.RpmBuilder.PackageInformation;
import org.eclipse.packager.rpm.parse.RpmInputStream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class EmptyWriterTest {
private static final Path OUT_BASE = Paths.get("target", "data", "out.empty");

@BeforeAll
public static void setup() throws IOException {
Files.createDirectories(OUT_BASE);
}
class EmptyWriterTest {
@TempDir
private Path outBase;

@Test
public void test3() throws IOException, PGPException {
void test3() throws IOException, PGPException {
Path outFile;

try (RpmBuilder builder = new RpmBuilder("testEmpty", "1.0.0", "1", "noarch", OUT_BASE)) {
try (RpmBuilder builder = new RpmBuilder("testEmpty", "1.0.0", "1", "noarch", outBase)) {
final PackageInformation pinfo = builder.getInformation();

pinfo.setLicense("EPL");
Expand Down
19 changes: 7 additions & 12 deletions rpm/src/test/java/org/eclipse/packager/rpm/Issue130Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

Expand All @@ -28,24 +27,20 @@
import org.eclipse.packager.rpm.build.RpmBuilder.PackageInformation;
import org.eclipse.packager.rpm.parse.InputHeader;
import org.eclipse.packager.rpm.parse.RpmInputStream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class Issue130Test {
private static final Path OUT_BASE = Paths.get("target", "data", "out");

class Issue130Test {
private static final List<String> PREFIXES = Arrays.asList("/opt", "/var/log");

@BeforeAll
public static void setup() throws IOException {
Files.createDirectories(OUT_BASE);
}
@TempDir
private Path outBase;

@Test
public void test() throws IOException {
Path outFile;
void test() throws IOException {
final Path outFile;

try (RpmBuilder builder = new RpmBuilder("prefixes-test", "1.0.0", "1", "noarch", OUT_BASE)) {
try (final RpmBuilder builder = new RpmBuilder("prefixes-test", "1.0.0", "1", "noarch", outBase)) {
final PackageInformation pinfo = builder.getInformation();

pinfo.setPrefixes(PREFIXES);
Expand Down
18 changes: 6 additions & 12 deletions rpm/src/test/java/org/eclipse/packager/rpm/Issue136Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.eclipse.packager.rpm.app.Dumper;
import org.eclipse.packager.rpm.build.RpmBuilder;
import org.eclipse.packager.rpm.info.RpmInformations;
import org.eclipse.packager.rpm.parse.InputHeader;
import org.eclipse.packager.rpm.parse.RpmInputStream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class Issue136Test {
private static final Path OUT_BASE = Paths.get("target", "data", "out");

@BeforeAll
public static void setup() throws IOException {
Files.createDirectories(OUT_BASE);
}
class Issue136Test {
@TempDir
private Path outBase;

@ParameterizedTest
@ValueSource(strings = {
Expand All @@ -49,10 +44,10 @@ public static void setup() throws IOException {
"012345678901234567890123456789012345678901234567890123456789012345",
"0123456789012345678901234567890123456789012345678901234567890123456",
})
public void test(final String originalName) throws IOException {
void test(final String originalName) throws IOException {
Path outFile;

try (RpmBuilder builder = new RpmBuilder(originalName, "1.0.0", "1", "noarch", OUT_BASE)) {
try (RpmBuilder builder = new RpmBuilder(originalName, "1.0.0", "1", "noarch", outBase)) {
outFile = builder.getTargetFile();

builder.build();
Expand All @@ -72,5 +67,4 @@ public void test(final String originalName) throws IOException {
assertTrue(leadNameBytes.length < 66, () -> "Expected lead name bytes to be less than 66, was " + leadNameBytes.length);
}
}

}
28 changes: 11 additions & 17 deletions rpm/src/test/java/org/eclipse/packager/rpm/Issue24Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,28 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

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

import org.eclipse.packager.rpm.build.BuilderOptions;
import org.eclipse.packager.rpm.build.RpmBuilder;
import org.eclipse.packager.rpm.build.RpmFileNameProvider;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class Issue24Test {
private static final Path OUT_BASE = Paths.get("target", "data", "out");

@BeforeAll
public static void setup() throws IOException {
Files.createDirectories(OUT_BASE);
}
class Issue24Test {
@TempDir
private Path outBase;

@Test
public void test() throws IOException {
void test() throws IOException {
final String name = "issue-24-test";
final String version = "1.0.0";
final String release = "1";
final String architecture = "noarch";
BuilderOptions options = new BuilderOptions();
final BuilderOptions options = new BuilderOptions();
options.setFileNameProvider(RpmFileNameProvider.DEFAULT_FILENAME_PROVIDER);

try (final RpmBuilder builder = new RpmBuilder(name, new RpmVersion(version, release), architecture, OUT_BASE, options)) {
try (final RpmBuilder builder = new RpmBuilder(name, new RpmVersion(version, release), architecture, outBase, options)) {
final Path outFile = builder.getTargetFile();

builder.build();
Expand All @@ -54,16 +48,16 @@ public void test() throws IOException {
assertEquals(expectedRpmFileName, outFile.getFileName().toString());
}

options = new BuilderOptions();
options.setFileNameProvider(RpmFileNameProvider.LEGACY_FILENAME_PROVIDER);
final BuilderOptions options2 = new BuilderOptions();
options2.setFileNameProvider(RpmFileNameProvider.LEGACY_FILENAME_PROVIDER);

try (final RpmBuilder builder = new RpmBuilder(name, new RpmVersion(version, release), architecture, OUT_BASE, options)) {
try (final RpmBuilder builder = new RpmBuilder(name, new RpmVersion(version, release), architecture, outBase, options2)) {
final Path outFile = builder.getTargetFile();

builder.build();

final String expectedRpmFileName = name + "-" + version + "-" + release + "-" + architecture + ".rpm";
final String rpmFileName = options.getFileNameProvider().getRpmFileName(builder.getName(), builder.getVersion(), builder.getArchitecture());
final String rpmFileName = options2.getFileNameProvider().getRpmFileName(builder.getName(), builder.getVersion(), builder.getArchitecture());
assertEquals(expectedRpmFileName, rpmFileName);
assertEquals(expectedRpmFileName, outFile.getFileName().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.eclipse.packager.rpm.build.RpmBuilder;
import org.eclipse.packager.rpm.parse.InputHeader;
import org.eclipse.packager.rpm.parse.RpmInputStream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,19 +41,15 @@
class SetVerifyFlagsTest {
private final static Logger LOGGER = LoggerFactory.getLogger(SetVerifyFlagsTest.class);

private static final Path OUT_BASE = Paths.get("target", "data", "out");

@BeforeAll
static void setup() throws IOException {
Files.createDirectories(OUT_BASE);
}

private static final String DIRNAME = "/opt/testing/";

private static final String NAME_myconf = "my.conf";

private static final String NAME_myreadme = "readme.txt";

@TempDir
private Path outBase;

/**
* Firstly, writes a RPM file with two file entries having different type flags
* and different verification flags;
Expand All @@ -62,7 +58,7 @@ static void setup() throws IOException {
@Test
void writeRpmWithVerifyFlags() throws IOException {
final Path outFile;
try (RpmBuilder builder = new RpmBuilder("vflag0-test", "1.0.0", "1", "noarch", OUT_BASE)) {
try (RpmBuilder builder = new RpmBuilder("vflag0-test", "1.0.0", "1", "noarch", outBase)) {
final String content_myconf = "Hallo, myconf!";
builder.newContext().addFile(DIRNAME + NAME_myconf, content_myconf.getBytes(), (targetName, object, type) -> {
if ((DIRNAME + NAME_myconf).equals(targetName)) {
Expand Down
35 changes: 15 additions & 20 deletions rpm/src/test/java/org/eclipse/packager/rpm/WriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,18 @@
import org.eclipse.packager.rpm.parse.RpmInputStream;
import org.eclipse.packager.rpm.signature.RsaHeaderSignatureProcessor;
import org.eclipse.packager.security.pgp.PgpHelper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class WriterTest {
private static final Path OUT_BASE = Paths.get("target", "data", "out");

class WriterTest {
private static final Path IN_BASE = Paths.get("src", "test", "resources", "data", "in");

@BeforeAll
public static void setup() throws IOException {
Files.createDirectories(OUT_BASE);
}
@TempDir
private Path outBase;

@Test
public void test1() throws IOException {
final Path rpm1 = OUT_BASE.resolve("test1-1.0.0.rpm");
void test1() throws IOException {
final Path rpm1 = outBase.resolve("test1-1.0.0.rpm");

final Header<RpmTag> header = new Header<>();

Expand Down Expand Up @@ -89,8 +85,8 @@ public void test1() throws IOException {
requirements.add(new Dependency("rpmlib(CompressedFileNames)", "3.0.4-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB));
Dependencies.putRequirements(header, requirements);

try (PayloadRecorder.Finished finished = new PayloadRecorder().finish()) {
try (RpmWriter writer = new RpmWriter(rpm1, new LeadBuilder("test1", new RpmVersion("1.0.0")), header)) {
try (final PayloadRecorder.Finished finished = new PayloadRecorder().finish()) {
try (final RpmWriter writer = new RpmWriter(rpm1, new LeadBuilder("test1", new RpmVersion("1.0.0")), header)) {
writer.setPayload(finished);
}
}
Expand All @@ -101,10 +97,10 @@ public void test1() throws IOException {
}

@Test
public void test2() throws IOException {
final Path outFile = OUT_BASE.resolve("test2-1.0.0.1.rpm");
void test2() throws IOException {
final Path outFile = outBase.resolve("test2-1.0.0.1.rpm");

try (PayloadRecorder payload = new PayloadRecorder()) {
try (final PayloadRecorder payload = new PayloadRecorder()) {
final Header<RpmTag> header = new Header<>();

header.putString(RpmTag.PAYLOAD_FORMAT, "cpio");
Expand Down Expand Up @@ -152,10 +148,10 @@ public void test2() throws IOException {
}

@Test
public void test3() throws IOException, PGPException {
void test3() throws IOException, PGPException {
Path outFile;

try (RpmBuilder builder = new RpmBuilder("test3", "1.0.0", "1", "noarch", OUT_BASE)) {
try (final RpmBuilder builder = new RpmBuilder("test3", "1.0.0", "1", "noarch", outBase)) {
final PackageInformation pinfo = builder.getInformation();

pinfo.setLicense("EPL");
Expand Down Expand Up @@ -211,10 +207,10 @@ public void test3() throws IOException, PGPException {
}

@Test
public void test4() throws IOException, InterruptedException {
void test4() throws IOException, InterruptedException {
final Path outFile;

try (RpmBuilder builder = new RpmBuilder("test4", "1.0.0", "1", "noarch", OUT_BASE)) {
try (final RpmBuilder builder = new RpmBuilder("test4", "1.0.0", "1", "noarch", outBase)) {
final PackageInformation pinfo = builder.getInformation();

pinfo.setLicense("EPL");
Expand Down Expand Up @@ -252,5 +248,4 @@ public void test4() throws IOException, InterruptedException {
pb.inheritIO();
pb.start().waitFor();
}

}

0 comments on commit 828ed4f

Please sign in to comment.