Skip to content

Commit

Permalink
Merge pull request #2 from joon6093/1.0.x
Browse files Browse the repository at this point in the history
Release v1.0.1
  • Loading branch information
joon6093 authored Nov 23, 2024
2 parents f2455c0 + b5f9d3e commit a81b37e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/pre-release-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ jobs:
outputs:
validation-cache-key: ${{ steps.validation-cache.outputs.key }}
steps:
- uses: actions/checkout@v4

- name: Change directory to test
run: cd test
- name: Checkout code
uses: actions/checkout@v3

- name: Generate validation cache key
id: validation-cache
run: echo "key=$(echo validation-${{ runner.os }}-gradle-${{ hashFiles('test/**/*.gradle*', 'test/**/gradle-wrapper.properties') }})" >> $GITHUB_OUTPUT
run: echo "key=validation-${{ runner.os }}-gradle-${{ hashFiles('test/**/*.gradle*', 'test/**/gradle-wrapper.properties') }}" >> $GITHUB_OUTPUT

- name: Output start time
shell: bash
Expand All @@ -29,10 +27,8 @@ jobs:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Change directory to test
run: cd test
- name: Checkout code
uses: actions/checkout@v3

- name: Cache Gradle packages
id: cache-gradle
Expand All @@ -45,10 +41,6 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache Check
if: steps.cache-gradle.outputs.cache-hit == 'true'
run: echo 'Gradle cache hit!'

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand All @@ -68,13 +60,13 @@ jobs:
name: validation-report
path: ${{ github.workspace }}/test/build/reports/tests/test/

- name: publish validation results
- name: Publish validation results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: ${{ github.workspace }}/test/build/test-results/test/TEST-*.xml

- name: add comments to a pull request
- name: Add comments to a pull request
uses: mikepenz/action-junit-report@v4
if: github.event_name == 'pull_request' && always()
with:
Expand Down
12 changes: 0 additions & 12 deletions handler/src/main/java/io/jeyong/handler/HandlerApplication.java

This file was deleted.

3 changes: 3 additions & 0 deletions test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'commons-io:commons-io:2.18.0'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.testcontainers:junit-jupiter:1.20.4'
testImplementation 'org.testcontainers:testcontainers:1.20.4'
}

tasks.named('test') {
Expand Down
75 changes: 75 additions & 0 deletions test/src/test/java/io/jeyong/test/SigtermListenerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.jeyong.test;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.images.builder.ImageFromDockerfile;

@SpringBootTest
public class SigtermListenerTest {

private final Logger logger = LoggerFactory.getLogger(SigtermListenerTest.class);

@Test
void testSigtermHandling() throws Exception {
// given
Path tempDir = Files.createTempDirectory("docker-context");
copyFile("../gradlew", tempDir.resolve("gradlew"));
copyDirectory("../gradle", tempDir.resolve("gradle"));
copyFile("../settings.gradle", tempDir.resolve("settings.gradle"));
copyDirectory("../handler", tempDir.resolve("handler"));
copyDirectory("../test", tempDir.resolve("test"));

ImageFromDockerfile image = new ImageFromDockerfile()
.withFileFromPath(".", tempDir)
.withDockerfileFromBuilder(builder -> {
builder.from("eclipse-temurin:17")
.workDir("/app")
.copy("gradlew", "/app/gradlew")
.copy("gradle", "/app/gradle")
.copy("settings.gradle", "/app/settings.gradle")
.copy("handler", "/app/handler")
.copy("test", "/app/test")
.run("chmod +x ./gradlew")
.run("./gradlew bootJar")
.cmd("java", "-jar", "/app/test/build/libs/test-0.0.1-SNAPSHOT.jar")
.build();
});

// when
try (GenericContainer<?> container = new GenericContainer<>(image)
.withLogConsumer(new Slf4jLogConsumer(logger))) {
container.start();
sendSigtermToContainer(container);

// then
Integer exitCode = container.getCurrentContainerInfo().getState().getExitCode();
assertThat(exitCode).isEqualTo(0);
}
}

private void sendSigtermToContainer(GenericContainer<?> container) {
String containerId = container.getContainerId();
container.getDockerClient()
.killContainerCmd(containerId)
.withSignal("SIGTERM")
.exec();
}

private void copyFile(String source, Path destination) throws Exception {
FileUtils.copyFile(new File(source), destination.toFile());
}

private void copyDirectory(String source, Path destination) throws Exception {
FileUtils.copyDirectory(new File(source), destination.toFile());
}
}
13 changes: 0 additions & 13 deletions test/src/test/java/io/jeyong/test/TestApplicationTests.java

This file was deleted.

0 comments on commit a81b37e

Please sign in to comment.