Skip to content

Commit b74f516

Browse files
Fix/sonrqube h2 database (#19)
* fix(use_h2_sonarqube): add h2 librairy to easily test repository on unit test and sonar * fix(use_h2_sonarqube): add h2 as a dependency * fix(use_h2_sonarqube): addsql init mode never to the test --------- Co-authored-by: Romain Vanhee <romain.vanhee@yrycom.com>
1 parent b061ba3 commit b74f516

5 files changed

Lines changed: 33 additions & 1 deletion

File tree

.github/workflows/sonar.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ jobs:
3939
run: |
4040
mkdir -p src/test/resources
4141
echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties
42+
echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties
4243
mvn clean verify sonar:sonar -Dsonar.qualitygate.wait=true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ build/
3131

3232
### VS Code ###
3333
.vscode/
34+
35+
# Test configuration generated in CI
36+
src/test/resources/application-test.properties

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ A GitHub Actions workflow is configured in:
151151
mvn clean verify sonar:sonar
152152
```
153153

154+
The CI command waits for the Quality Gate result:
155+
156+
```bash
157+
./mvnw clean verify sonar:sonar -Dsonar.qualitygate.wait=true
158+
```
159+
160+
Before running tests, the workflow recreates:
161+
162+
```bash
163+
src/test/resources/application-test.properties
164+
```
165+
166+
from a Base64-encoded GitHub secret.
167+
168+
### Required GitHub Secrets
169+
170+
- `SONAR_TOKEN`
171+
- `SONAR_HOST_URL`
172+
- `APPLICATION_TEST_PROPERTIES` (Base64-encoded `application-test.properties` content)
173+
174+
> `GITHUB_TOKEN` is provided automatically by GitHub Actions.
175+
154176
### Generate the JaCoCo coverage report locally
155177

156178
Run:

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
3333
</properties>
3434
<dependencies>
35+
<dependency>
36+
<groupId>com.h2database</groupId>
37+
<artifactId>h2</artifactId>
38+
<scope>test</scope>
39+
</dependency>
3540
<dependency>
3641
<groupId>org.springframework.boot</groupId>
3742
<artifactId>spring-boot-starter-actuator</artifactId>

src/test/java/com/xpeho/spring_boot_java_random_user/SpringBootJavaRandomUserApplicationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
5-
import org.springframework.context.annotation.Import;
5+
import org.springframework.test.context.ActiveProfiles;
66

77
@SpringBootTest
8+
@ActiveProfiles("test")
89
class SpringBootJavaRandomUserApplicationTests {
910

1011
@Test

0 commit comments

Comments
 (0)