-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added postgres as a test container (#77)
* Added postgres test container * Added support for snapshot build * Removed redundant bits * Added 21, removed dependency * Fix Java 21 doc issue * Tidy up actions
- Loading branch information
Showing
8 changed files
with
161 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: "Build - Snapshot" | ||
on: | ||
push: | ||
branches-ignore: | ||
- main | ||
tags-ignore: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
snapshot_build: | ||
name: Snapshot build and publish | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install gpg secret key | ||
run: cat <(echo -e "${{ secrets.GPG_SECRET_KEY }}") | gpg --batch --import | ||
|
||
- name: Set up Maven Central Repository | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
cache: 'maven' | ||
|
||
- name: Cache local Maven repository | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.m2/repository | ||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-m2 | ||
|
||
- name: Set up maven settings | ||
uses: s4u/[email protected] | ||
with: | ||
servers: | | ||
[{ | ||
"id": "ossrh", | ||
"username": "${{ secrets.OSSRH_USER_V2 }}", | ||
"password": "${{ secrets.OSSRH_TOKEN_V2 }}" | ||
}, | ||
{ | ||
"id": "gpg.passphrase", | ||
"passphrase": "${{ secrets.GPG_SECRET_KEY_PASSWORD }}", | ||
"configuration": {} | ||
}] | ||
- name: Upload snapshot | ||
run: | | ||
mvn \ | ||
--no-transfer-progress \ | ||
--batch-mode \ | ||
clean deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/hsbc/engineering/PostgresConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.hsbc.engineering; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
public class PostgresConnectionTest { | ||
final String user = "hello"; | ||
final String password = "moo"; | ||
final String database = "foo"; | ||
|
||
private Map<String, String> getConnectionMap() { | ||
Map<String, String> args = Map.of( | ||
Arguments.CLASS_NAME, "org.postgresql.Driver", | ||
Arguments.USER, user, | ||
Arguments.PWD, password, | ||
Arguments.URL, pSqlContainer.getJdbcUrl(), | ||
Arguments.SQL, "SELECT 2"); | ||
|
||
return args; | ||
} | ||
|
||
@Container | ||
private PostgreSQLContainer pSqlContainer = new PostgreSQLContainer<>("postgres:16") | ||
.withDatabaseName(database) | ||
.withUsername(user) | ||
.withPassword(password); | ||
|
||
@Test | ||
void checkOK() { | ||
assertTrue(pSqlContainer.isRunning()); | ||
} | ||
|
||
@Test | ||
void mainFunctionTest() { | ||
Assertions.assertDoesNotThrow(() -> JDBCInquirer.runSimpleConnectionTest(getConnectionMap())); | ||
} | ||
|
||
@Test | ||
void perfFunctionTest() { | ||
Assertions.assertDoesNotThrow(() -> JDBCInquirer.timeExtractionTest(getConnectionMap())); | ||
} | ||
} |