mirror of
https://codeberg.org/PGPainless/wkd-java.git
synced 2024-11-22 07:12:05 +01:00
Refactor TestSuiteTestRunner
This commit is contained in:
parent
d50df99946
commit
a99f0fef71
1 changed files with 20 additions and 10 deletions
|
@ -6,12 +6,15 @@ package pgp.wkd.cli.test_suite;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.platform.commons.logging.Logger;
|
||||||
|
import org.junit.platform.commons.logging.LoggerFactory;
|
||||||
import pgp.wkd.cli.WKDCLI;
|
import pgp.wkd.cli.WKDCLI;
|
||||||
import pgp.wkd.cli.command.Fetch;
|
import pgp.wkd.cli.command.Fetch;
|
||||||
import pgp.wkd.test_suite.TestCase;
|
import pgp.wkd.test_suite.TestCase;
|
||||||
import pgp.wkd.test_suite.TestSuite;
|
import pgp.wkd.test_suite.TestSuite;
|
||||||
import pgp.wkd.test_suite.TestSuiteGenerator;
|
import pgp.wkd.test_suite.TestSuiteGenerator;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
@ -20,32 +23,39 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
public class TestSuiteTestRunner {
|
public class TestSuiteTestRunner {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(TestSuiteTestRunner.class);
|
||||||
private static TestSuite suite;
|
private static TestSuite suite;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void setup() throws Exception {
|
public static void setup() throws Exception {
|
||||||
Path tempDir = Files.createTempDirectory("wkd-test");
|
// Temporary, directory based WKD
|
||||||
tempDir.toFile().deleteOnExit();
|
Path tempPath = Files.createTempDirectory("wkd-test");
|
||||||
Fetch.fetcher = new DirectoryBasedWkdFetcher(tempDir);
|
File tempFile = tempPath.toFile();
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
|
||||||
|
// Generate test certificates inside the temp wkd
|
||||||
String domain = "example.com";
|
String domain = "example.com";
|
||||||
|
|
||||||
TestSuiteGenerator generator = new TestSuiteGenerator(domain);
|
TestSuiteGenerator generator = new TestSuiteGenerator(domain);
|
||||||
suite = generator.generateTestSuiteInDirectory(tempDir.toFile(), TestSuiteGenerator.Method.direct);
|
suite = generator.generateTestSuiteInDirectory(tempFile, TestSuiteGenerator.Method.direct);
|
||||||
|
|
||||||
|
// Fetch certificates from a local directory instead of the internetzzz.
|
||||||
|
Fetch.fetcher = new DirectoryBasedWkdFetcher(tempPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runTestsAgainstTestSuite() {
|
void runTestsAgainstTestSuite() {
|
||||||
for (TestCase testCase : suite.getTestCases()) {
|
for (TestCase testCase : suite.getTestCases()) {
|
||||||
System.out.println("Executing test " + testCase.getTestTitle());
|
LOGGER.info(() -> "Execute Test Case '" + testCase.getTestTitle() + "'");
|
||||||
|
String mail = testCase.getLookupMailAddress();
|
||||||
|
|
||||||
int exitCode = WKDCLI.execute(new String[] {
|
int exitCode = WKDCLI.execute(new String[] {
|
||||||
"fetch", "--armor", testCase.getLookupMailAddress()
|
"fetch", "--armor", mail
|
||||||
});
|
});
|
||||||
|
|
||||||
if (testCase.isExpectSuccess()) {
|
if (testCase.isExpectSuccess()) {
|
||||||
assertEquals(0, exitCode);
|
assertEquals(0, exitCode, testCase.getTestDescription());
|
||||||
} else {
|
} else {
|
||||||
assertNotEquals(0, exitCode);
|
assertNotEquals(0, exitCode, testCase.getTestDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue