Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Ad hoc testing

Beyond the unit tests, ad hoc "integration testing" can be done by running via Gradle passing the intended command-line via `--args`, such as:

```shell
./gradlew run --args="assert fileExists build.gradle"
```

## Creating a new release

The Github Actions workflow `publish-release` will take of performing the release build, but the tag needs to be created with the release tasks shown below.
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ dependencies {
implementation 'com.jayway.jsonpath:json-path:2.6.0'
implementation 'org.apache.maven:maven-artifact:3.8.4'

testImplementation 'org.assertj:assertj-core:3.21.0'
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
testImplementation 'org.mockito:mockito-junit-jupiter:4.1.0'
testImplementation 'org.mockito:mockito-junit-jupiter:4.2.0'
testImplementation 'org.mock-server:mockserver-junit-jupiter:5.11.2'
testImplementation 'com.github.stefanbirkner:system-lambda:1.2.0'
// https://github.com/stefanbirkner/system-lambda
testImplementation 'com.github.stefanbirkner:system-lambda:1.2.1'

annotationProcessor "info.picocli:picocli-codegen:${picocliVersion}"
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/itzg/helpers/McImageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import me.itzg.helpers.asciify.Asciify;
import me.itzg.helpers.assertcmd.AssertCommand;
import me.itzg.helpers.get.GetCommand;
import me.itzg.helpers.hash.HashCommand;
import me.itzg.helpers.patch.PatchCommand;
Expand All @@ -19,6 +20,7 @@
@Command(name = "mc-image-helper",
subcommands = {
Asciify.class,
AssertCommand.class,
CompareVersionsCommand.class,
GetCommand.class,
HashCommand.class,
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/me/itzg/helpers/assertcmd/AssertCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.itzg.helpers.assertcmd;

import picocli.CommandLine.Command;

@Command(name = "assert", description = "Provides assertion operators for verifying container setup",
subcommands = {
FileExists.class
}
)
public class AssertCommand {
}
32 changes: 32 additions & 0 deletions src/main/java/me/itzg/helpers/assertcmd/FileExists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.itzg.helpers.assertcmd;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.Callable;
import picocli.CommandLine.Command;
import picocli.CommandLine.ExitCode;
import picocli.CommandLine.Parameters;

@Command(name = "fileExists")
class FileExists implements Callable<Integer> {

@Parameters
List<Path> paths;

@Override
public Integer call() throws Exception {
boolean missing = false;

if (paths != null) {
for (Path path : paths) {
if (!Files.exists(path)) {
System.err.printf("%s does not exist%n", path);
missing = true;
}
}
}

return missing ? ExitCode.SOFTWARE : ExitCode.OK;
}
}
56 changes: 56 additions & 0 deletions src/test/java/me/itzg/helpers/assertcmd/FileExistsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package me.itzg.helpers.assertcmd;

import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErr;
import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import picocli.CommandLine;

class FileExistsTest {

@Test
void passesWhenAllExist(@TempDir Path tempDir) throws Exception {
final Path file1 = Files.createFile(tempDir.resolve("file1"));
final Path file2 = Files.createFile(tempDir.resolve("file2"));

final String errOut = tapSystemErr(() -> {
int exitCode = new CommandLine(new FileExists())
.execute(
file1.toString(),
file2.toString()
);

assertThat(exitCode).isEqualTo(0);
});

assertThat(errOut).isBlank();
}

@Test
void failsWhenSomeMissing(@TempDir Path tempDir) throws Exception {
final Path file1 = Files.createFile(tempDir.resolve("file1"));
final Path file2 = Files.createFile(tempDir.resolve("file2"));
final Path pathA = tempDir.resolve("fileA");
final Path fileB = tempDir.resolve("fileB");

final String errOut = tapSystemErr(() -> {
int exitCode = new CommandLine(new FileExists())
.execute(
file1.toString(),
pathA.toString(),
file2.toString(),
fileB.toString()
);

assertThat(exitCode).isEqualTo(1);
});

assertThat(errOut).contains(
"fileA does not exist",
"fileB does not exist"
);
}
}