Skip to content

Commit

Permalink
Add minimal windows build (#379)
Browse files Browse the repository at this point in the history
* Add minimal windows build
  • Loading branch information
big-andy-coates authored Dec 23, 2023
1 parent 429fb38 commit c504026
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 51 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ permissions:
contents: read

jobs:
build:
build_linux:
permissions:
packages: write
runs-on: ubuntu-latest
Expand Down Expand Up @@ -67,9 +67,27 @@ jobs:
run: |
./gradlew -Dgradle.publish.key="$GRADLE_PUBLISH_KEY" -Dgradle.publish.secret="$GRADLE_PUBLISH_SECRET" publishPlugins
# Until Creek fully supports Windows, minimal check:
build_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # v1.1.0
- name: Set up JDK
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
with:
java-version: '17'
distribution: 'adopt'
- name: Setup Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
with:
gradle-home-cache-cleanup: true
- name: Build
run: ./gradlew.bat build -PexcludeContainerised

create-gh-release:
if: startsWith(github.ref, 'refs/tags/') && !endsWith(github.ref, '-alpha')
needs: build
needs: [build_linux, build_windows]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
import org.creekservice.api.system.test.test.services.TestServiceDescriptor;
import org.creekservice.api.test.util.TestPaths;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

@Tag("ContainerisedTest")
class SystemTestExecutorFunctionalTest {

// Change this to true locally to debug using attach me plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -81,6 +82,7 @@

@SuppressFBWarnings({"DMI_HARDCODED_ABSOLUTE_FILENAME", "PREDICTABLE_RANDOM"})
@ExtendWith(MockitoExtension.class)
@Tag("ContainerisedTest")
class DockerServiceContainerFunctionalTest {

private static final String SERVICE_NAME = "test-service";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
Expand All @@ -40,6 +41,9 @@
@SuppressWarnings("OptionalGetWithoutIsPresent")
class PicoCliParserTest {

private static final Path TESTS_PATH = Path.of("test", "path");
private static final Path RESULTS_PATH = Path.of("result", "path");

@Test
void shouldReturnEmptyOnHelp() {
// Given:
Expand Down Expand Up @@ -87,10 +91,10 @@ void shouldParseMinimalSetWithDefaults() {
// Then:
assertThat(
result.map(ExecutorOptions::testDirectory).map(Path::toString),
is(Optional.of("test/path")));
is(Optional.of(TESTS_PATH.toString())));
assertThat(
result.map(ExecutorOptions::resultDirectory).map(Path::toString),
is(Optional.of("result/path")));
is(Optional.of(RESULTS_PATH.toString())));
assertThat(result.flatMap(ExecutorOptions::verifierTimeout), is(Optional.empty()));
assertThat(
result.map(ExecutorOptions::suitesFilter).map(f -> f.test(Paths.get("any"))),
Expand All @@ -101,7 +105,7 @@ void shouldParseMinimalSetWithDefaults() {
@Test
void shouldThrowIfTestPathNotProvided() {
// Given:
final String[] args = {"-rd", "result/path"};
final String[] args = {"-rd", RESULTS_PATH.toString()};

// When:
final Exception e = assertThrows(RuntimeException.class, () -> parse(args));
Expand All @@ -115,7 +119,7 @@ void shouldThrowIfTestPathNotProvided() {
@Test
void shouldThrowIfResultPathNotProvided() {
// Given:
final String[] args = {"-td", "test/path"};
final String[] args = {"-td", TESTS_PATH.toString()};

// When:
final Exception e = assertThrows(RuntimeException.class, () -> parse(args));
Expand Down Expand Up @@ -151,8 +155,8 @@ void shouldParseSuitePattern() {

// Then:
final Predicate<Path> filter = result.get().suitesFilter();
assertThat(filter.test(Path.of("/some/included/path")), is(true));
assertThat(filter.test(Path.of("/some/excluded/path")), is(false));
assertThat(filter.test(Path.of("some", "included", "path")), is(true));
assertThat(filter.test(Path.of(File.separator, "some", "excluded", "path")), is(false));
}

@Test
Expand Down Expand Up @@ -337,7 +341,10 @@ void shouldParseSingleMultipleDebugEnvInMultipleParams() {
@Test
void shouldParseReadOnlyMount() {
// Given:
final String[] args = minimalArgs("--mount-read-only=/host/path=/container/path");
final Path mountSource = Path.of(File.separator, "host", "path");
final Path mountDestination = Path.of("/", "container", "path");
final String[] args =
minimalArgs("--mount-read-only=" + mountSource + "=" + mountDestination);

// When:
final Optional<ExecutorOptions> result = parse(args);
Expand All @@ -347,8 +354,8 @@ void shouldParseReadOnlyMount() {
result.map(ExecutorOptions::mountInfo).map(Collection::size), is(Optional.of(1)));

final ExecutorOptions.MountInfo mount = result.get().mountInfo().iterator().next();
assertThat(mount.hostPath(), is(Path.of("/host/path")));
assertThat(mount.containerPath(), is(Path.of("/container/path")));
assertThat(mount.hostPath(), is(mountSource));
assertThat(mount.containerPath(), is(mountDestination));
assertThat(mount.readOnly(), is(true));
}

Expand Down Expand Up @@ -520,9 +527,11 @@ void shouldImplementToStringOnMinimalOptions() {
result.map(Object::toString),
is(
Optional.of(
"--test-directory=test/path"
"--test-directory="
+ TESTS_PATH
+ lineSeparator()
+ "--result-directory=result/path"
+ "--result-directory="
+ RESULTS_PATH
+ lineSeparator()
+ "--verifier-timeout-seconds=<Not Set>"
+ lineSeparator()
Expand All @@ -546,6 +555,16 @@ void shouldImplementToStringOnMinimalOptions() {
@Test
void shouldImplementToStringOnFullOptions() {
// Given:
final Path mrS0 = Path.of("a", "b");
final Path mrD0 = Path.of("c");
final Path mrS1 = Path.of("d", "e");
final Path mrD1 = Path.of("f");

final Path mwS0 = Path.of("a");
final Path mwD0 = Path.of("b", "c");
final Path mwS1 = Path.of("d");
final Path mwD1 = Path.of("g");

final String[] args =
minimalArgs(
"--verifier-timeout-seconds=90",
Expand All @@ -555,8 +574,8 @@ void shouldImplementToStringOnFullOptions() {
"-dsi=a-0,b-1",
"-de=E=F",
"-e=A=B,C=D",
"-mr=/a/b=/c,d/e=/f",
"-mw=/a=/b/c,/d=/f");
"-mr=" + mrS0 + "=" + mrD0 + "," + mrS1 + "=" + mrD1,
"-mw=" + mwS0 + "=" + mwD0 + "," + mwS1 + "=" + mwD1);

// When:
final Optional<ExecutorOptions> result = parse(args);
Expand All @@ -566,9 +585,11 @@ void shouldImplementToStringOnFullOptions() {
result.map(Object::toString),
is(
Optional.of(
"--test-directory=test/path"
"--test-directory="
+ TESTS_PATH
+ lineSeparator()
+ "--result-directory=result/path"
+ "--result-directory="
+ RESULTS_PATH
+ lineSeparator()
+ "--verifier-timeout-seconds=90"
+ lineSeparator()
Expand All @@ -584,14 +605,29 @@ void shouldImplementToStringOnFullOptions() {
+ lineSeparator()
+ "--env=A=B,C=D"
+ lineSeparator()
+ "--mount-read-only=/a/b=/c,d/e=/f"
+ "--mount-read-only="
+ mrS0
+ "="
+ mrD0
+ ","
+ mrS1
+ "="
+ mrD1
+ lineSeparator()
+ "--mount-writable=/a=/b/c,/d=/f")));
+ "--mount-writable="
+ mwS0
+ "="
+ mwD0
+ ","
+ mwS1
+ "="
+ mwD1)));
}

private static String[] minimalArgs(final String... additional) {
final List<String> args =
new ArrayList<>(List.of("-td", "test/path", "-rd", "result/path"));
new ArrayList<>(
List.of("-td", TESTS_PATH.toString(), "-rd", RESULTS_PATH.toString()));
args.addAll(List.of(additional));
return args.toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.creekservice.internal.system.test.executor.observation;

import static java.lang.System.lineSeparator;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -107,7 +108,11 @@ void shouldLogAfterErroredTest() {
listener.afterTest(test, testResult);

// Then:
verify(logger).info("Finished test 'Bob': ERROR: msg\n" + Throwables.stackTrace(cause));
verify(logger)
.info(
"Finished test 'Bob': ERROR: msg"
+ lineSeparator()
+ Throwables.stackTrace(cause));
}

@Test
Expand All @@ -121,7 +126,11 @@ void shouldLogAfterFailedTest() {
listener.afterTest(test, testResult);

// Then:
verify(logger).info("Finished test 'Bob': FAILED: msg\n" + Throwables.stackTrace(cause));
verify(logger)
.info(
"Finished test 'Bob': FAILED: msg"
+ lineSeparator()
+ Throwables.stackTrace(cause));
}

@Test
Expand Down Expand Up @@ -163,6 +172,9 @@ void shouldLogAfterSuiteStartUpFailure() {

// Then:
verify(logger)
.info("Start up failed for suite 'Bob': msg\n" + Throwables.stackTrace(cause));
.info(
"Start up failed for suite 'Bob': msg"
+ lineSeparator()
+ Throwables.stackTrace(cause));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.nio.file.FileSystemException;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import org.creekservice.api.system.test.extension.test.model.TestExecutionResult;
import org.creekservice.api.test.util.TestPaths;
import org.creekservice.internal.system.test.executor.result.SuiteResult;
Expand All @@ -48,6 +49,9 @@
@MockitoSettings(strictness = Strictness.LENIENT)
class XmlResultsWriterTest {

private static final boolean RUNNING_ON_WINDOWS =
System.getProperty("os.name").toLowerCase().contains("win");

@Mock private ObjectWriter objectWriter;
@Mock private TestExecutionResult result;

Expand Down Expand Up @@ -155,8 +159,18 @@ void shouldSanitizeSuiteNameForUseInFileName() {
writer.write(result);

// Then:
// Windows path, for some reason, has additional '_' characters in the name:
final Path expectedFileName =
RUNNING_ON_WINDOWS
? Path.of("TEST-_some____Weird_--_______________Name.xml")
: Path.of("TEST-_some____Weird_--_____________Name.xml");

assertThat(
outputDir.resolve("TEST-_some____Weird_--_____________Name.xml"),
"Directory content:"
+ TestPaths.listDirectory(outputDir)
.map(Path::toString)
.collect(Collectors.joining(System.lineSeparator())),
outputDir.resolve(expectedFileName),
fileContains("some xml"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.creekservice.internal.system.test.executor.result.xml;

import static java.lang.System.lineSeparator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -64,7 +65,9 @@ void shouldSerializeSuccess() throws Exception {
// Then:
assertThat(
xml,
is("<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\"/>\n"));
is(
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\"/>"
+ lineSeparator()));
}

@Test
Expand All @@ -79,9 +82,12 @@ void shouldSerializeSkipped() throws Exception {
assertThat(
xml,
is(
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\">\n"
+ " <skipped/>\n"
+ "</testcase>\n"));
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\">"
+ lineSeparator()
+ " <skipped/>"
+ lineSeparator()
+ "</testcase>"
+ lineSeparator()));
}

@Test
Expand All @@ -98,12 +104,15 @@ void shouldSerializeFailed() throws Exception {
assertThat(
xml,
is(
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\">\n"
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\">"
+ lineSeparator()
+ " <failure message=\"Expectation not met\""
+ " type=\"java.lang.AssertionError\">"
+ stackTrace
+ "</failure>\n"
+ "</testcase>\n"));
+ stackTrace.replaceAll("\r", "&#xd;")
+ "</failure>"
+ lineSeparator()
+ "</testcase>"
+ lineSeparator()));
}

@Test
Expand All @@ -120,11 +129,14 @@ void shouldSerializeError() throws Exception {
assertThat(
xml,
is(
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\">\n"
"<testcase classname=\"the suite\" name=\"the test\" time=\"1234.567\">"
+ lineSeparator()
+ " <error message=\"bad state\""
+ " type=\"java.lang.IllegalStateException\">"
+ stackTrace
+ "</error>\n"
+ "</testcase>\n"));
+ stackTrace.replaceAll("\r", "&#xd;")
+ "</error>"
+ lineSeparator()
+ "</testcase>"
+ lineSeparator()));
}
}
Loading

0 comments on commit c504026

Please sign in to comment.