Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/gradle/org.testcontainers-testcon…
Browse files Browse the repository at this point in the history
…tainers-1.19.3
  • Loading branch information
big-andy-coates authored Dec 24, 2023
2 parents c691e09 + d56acc4 commit ea5dbed
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 96 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 @@ -61,16 +61,20 @@ public InitializeResourcesListener(final SystemTest api) {
this(
api,
ResourceInitializer.resourceInitializer(
new ResourceInitializer.ResourceCreator() {
@SuppressWarnings({"unchecked", "rawtypes"})
new ResourceInitializer.Callbacks() {
@Override
public <T extends ResourceDescriptor> void validate(
final Class<T> type, final Collection<T> resources) {
api.extensions().model().resourceHandler(type).validate(resources);
}

@Override
public <T extends ResourceDescriptor & OwnedResource> void ensure(
final Collection<T> creatableResources) {
final Class<T> type, final Collection<T> creatableResources) {
api.extensions()
.model()
.resourceHandler(
creatableResources.iterator().next().getClass())
.ensure((Collection) creatableResources);
.resourceHandler(type)
.ensure(creatableResources);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static java.lang.System.lineSeparator;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.creekservice.api.system.test.test.services.TestServiceDescriptor.OwnedOutput;
import static org.creekservice.api.system.test.test.services.TestServiceDescriptor.UnmanagedInternal;
import static org.creekservice.api.system.test.test.services.TestServiceDescriptor.UnownedInput1;
import static org.creekservice.api.test.util.TestPaths.ensureDirectories;
import static org.creekservice.api.test.util.coverage.CodeCoverage.codeCoverageCmdLineArg;
import static org.creekservice.api.test.util.debug.RemoteDebug.remoteDebugArguments;
Expand All @@ -45,12 +47,13 @@
import java.util.stream.Collectors;
import org.creekservice.api.base.type.Suppliers;
import org.creekservice.api.system.test.test.extension.TestCreekExtensionProvider;
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 Expand Up @@ -510,20 +513,30 @@ void shouldProcessExpectations() {
}

@Test
void shouldReportEnsureResourceFailures() {
void shouldReportExtensionInitializationFailure() {
// Given:
givenEnv(
TestCreekExtensionProvider.ENV_FAIL_ENSURE_RESOURCE_ID,
TestServiceDescriptor.UnownedInput1.id());
givenEnv(TestCreekExtensionProvider.ENV_FAIL_INITIALIZE_RESOURCE_ID, OwnedOutput.id());

// When:
final int exitCode = runExecutor(minimalArgs());

// Then:
assertThat(stdErr.get(), containsString("Extension initialization failed"));
assertThat(exitCode, is(2));
}

@Test
void shouldReportResourceValidationFailure() {
// Given:
givenEnv(TestCreekExtensionProvider.ENV_FAIL_VALIDATE_RESOURCE_ID, UnmanagedInternal.id());

// When:
final int exitCode = runExecutor(minimalArgs());

// Then:
assertThat(
stdOut.get(),
containsString(
"Ensure failed for resource: " + TestServiceDescriptor.UnownedInput1.id()));
stdErr.get(),
containsString("Validation failed for resource group: " + UnmanagedInternal.id()));
assertThat(
stdErr.get(),
containsString(
Expand All @@ -532,21 +545,16 @@ void shouldReportEnsureResourceFailures() {
}

@Test
void shouldReportPrepareResourceFailures() {
void shouldReportEnsureResourceFailures() {
// Given:
givenEnv(
TestCreekExtensionProvider.ENV_FAIL_PREPARE_RESOURCE_ID,
TestServiceDescriptor.UnownedInput1.id());
givenEnv(TestCreekExtensionProvider.ENV_FAIL_ENSURE_RESOURCE_ID, UnownedInput1.id());

// When:
final int exitCode = runExecutor(minimalArgs());

// Then:
assertThat(
stdOut.get(),
containsString(
"Prepare failed for resource: "
+ TestServiceDescriptor.UnownedInput1.id()));
stdOut.get(), containsString("Ensure failed for resource: " + UnownedInput1.id()));
assertThat(
stdErr.get(),
containsString(
Expand All @@ -555,18 +563,21 @@ void shouldReportPrepareResourceFailures() {
}

@Test
void shouldReportResourceValidationFailure() {
void shouldReportPrepareResourceFailures() {
// Given:
givenEnv(TestCreekExtensionProvider.ENV_FAIL_VALIDATE_RESOURCE_ID, OwnedOutput.id());
givenEnv(TestCreekExtensionProvider.ENV_FAIL_PREPARE_RESOURCE_ID, UnownedInput1.id());

// When:
final int exitCode = runExecutor(minimalArgs());

// Then:
assertThat(
stdOut.get(), containsString("Prepare failed for resource: " + UnownedInput1.id()));
assertThat(
stdErr.get(),
containsString("Validation failed for resource group: " + OwnedOutput.id()));
assertThat(exitCode, is(2));
containsString(
"There were failing tests. See the report at: " + resultDir.toUri()));
assertThat(exitCode, is(1));
}

@Test
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
Loading

0 comments on commit ea5dbed

Please sign in to comment.