Properly ignore tests if no backends are configured

This commit is contained in:
Paul Schaub 2023-01-22 16:53:50 +01:00
parent 0b96a5314f
commit 3789b60f0b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
11 changed files with 37 additions and 21 deletions

View file

@ -16,6 +16,7 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
// Read json config file
testImplementation "com.google.code.gson:gson:2.10.1"
api project(":sop-java")
@ -23,9 +24,6 @@ dependencies {
api "org.slf4j:slf4j-api:$slf4jVersion"
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
// Compare version strings
implementation 'org.apache.maven:maven-artifact:3.6.3'
// @Nonnull, @Nullable...
implementation "com.google.code.findbugs:jsr305:$jsrVersion"
}

View file

@ -17,32 +17,28 @@ import java.util.List;
import java.util.Properties;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public abstract class AbstractExternalSOPTest {
private static final List<Arguments> backends = new ArrayList<>();
static {
TestSuite suite = readConfiguration();
assumeTrue(suite != null);
assumeFalse(suite.backends.isEmpty());
for (TestSubject subject : suite.backends) {
if (!new File(subject.sop).exists()) {
continue;
}
Properties env = new Properties();
if (subject.env != null) {
for (Var var : subject.env) {
env.put(var.key, var.value);
if (suite != null && !suite.backends.isEmpty()) {
for (TestSubject subject : suite.backends) {
if (!new File(subject.sop).exists()) {
continue;
}
}
SOP sop = new ExternalSOP(subject.sop, env);
backends.add(Arguments.of(Named.of(subject.name, sop)));
Properties env = new Properties();
if (subject.env != null) {
for (Var var : subject.env) {
env.put(var.key, var.value);
}
}
SOP sop = new ExternalSOP(subject.sop, env);
backends.add(Arguments.of(Named.of(subject.name, sop)));
}
}
}
@ -62,6 +58,10 @@ public abstract class AbstractExternalSOPTest {
return suite;
}
public static boolean hasBackends() {
return !backends.isEmpty();
}
// JSON DTOs
public static class TestSuite {

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.SOP;
@ -17,6 +18,7 @@ import static sop.external.JUtils.arrayStartsWith;
import static sop.external.JUtils.assertArrayStartsWith;
import static sop.external.JUtils.assertAsciiArmorEquals;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
private static final String BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n";

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.ByteArrayAndResult;
@ -17,6 +18,7 @@ import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
private static final String CIPHERTEXT = "-----BEGIN PGP MESSAGE-----\n" +

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.SOP;
@ -21,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static sop.external.JUtils.assertArrayStartsWith;
import static sop.external.JUtils.assertSignedBy;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest {
private static final String BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n";

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.ByteArrayAndResult;
@ -26,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest {
@ParameterizedTest

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.SOP;
@ -17,6 +18,7 @@ import static sop.external.JUtils.arrayStartsWith;
import static sop.external.JUtils.assertArrayStartsWith;
import static sop.external.JUtils.assertAsciiArmorEquals;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalExtractCertTest extends AbstractExternalSOPTest {
private static final String BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n";

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.SOP;
@ -15,6 +16,7 @@ import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static sop.external.JUtils.assertArrayStartsWith;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
private static final Charset UTF8 = StandardCharsets.UTF_8;

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.ByteArrayAndResult;
@ -20,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static sop.external.JUtils.arrayStartsWith;
import static sop.external.JUtils.assertArrayStartsWith;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExternalSOPTest {
private static final byte[] BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n".getBytes(StandardCharsets.UTF_8);

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.ByteArrayAndResult;
@ -22,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static sop.external.JUtils.assertSignedBy;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
private static final String BEGIN_PGP_MESSAGE = "-----BEGIN PGP MESSAGE-----\n";

View file

@ -4,6 +4,7 @@
package sop.external;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sop.SOP;
@ -12,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
public class ExternalVersionTest extends AbstractExternalSOPTest {
@ParameterizedTest