Skip to content

Commit

Permalink
ci: 在ci环境下动态开启数据库单元测试 (#767)
Browse files Browse the repository at this point in the history
* ci: 在ci环境下动态开启数据库单元测试

* ci: 更新test

* ci: update config

* fix: 修复问题

* ci: 更新ci
  • Loading branch information
damingerdai authored Nov 1, 2023
1 parent 4d87262 commit ed69e71
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432/tcp
- 5432:5432
redis:
image: redis:7.2.2-alpine
options: >-
Expand All @@ -58,7 +58,8 @@ jobs:
run: cd migration && go build -o migrate migration.go && ./migrate up
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
# POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 123456
POSTGRES_DB: postgres
Expand All @@ -75,6 +76,13 @@ jobs:
- name: Unit Test with Gradle
# run: ./gradlew flywayMigrate && ./gradlew build
run: ./gradlew test
env:
CI: true
- name: Unit Test with Maven
# run: ./gradlew flywayMigrate && ./gradlew build
run: ./mvnw test && ./mvnw surefire-report:report-only
env:
CI: true
build:
runs-on: ${{ matrix.os }}
needs: [ test ]
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
maven { url 'https://repo.spring.io/snapshot' }
mavenCentral()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://plugins.gradle.org/m2/' }
}
}

Expand Down Expand Up @@ -97,3 +98,10 @@ if (project.hasProperty('standalone')) {
mainClass = 'org.daming.hoteler.HotelerApplication'
}
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
34 changes: 30 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<maven.compiler.target>21</maven.compiler.target>
<changelog.version>1.100.6</changelog.version>
<jsonwebtoken.version>0.12.3</jsonwebtoken.version>
<jacoco.version>0.8.11</jacoco.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -142,7 +143,6 @@
<artifactId>flyway-core</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -162,9 +162,34 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<skipTests>false</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<!-- jacoco: generate test coverage report -->
<!-- <plugin>-->
<!-- <groupId>org.jacoco</groupId>-->
<!-- <artifactId>jacoco-maven-plugin</artifactId>-->
<!-- <version>${jacoco.version}</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>prepare-agent</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- <id>generate-code-coverage-report</id>-->
<!-- <phase>test</phase>-->
<!-- <goals>-->
<!-- <goal>report</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down Expand Up @@ -194,6 +219,7 @@
</plugin>

<!-- git changelog maven plugin -->
<!--
<plugin>
<groupId>se.bjurr.gitchangelog</groupId>
<artifactId>git-changelog-maven-plugin</artifactId>
Expand All @@ -209,7 +235,7 @@
<useIntegrations>true</useIntegrations>
<gitHubEnabled>trye</gitHubEnabled>
<gitHubApi>https://api.github.com/repos/damingerdai/hoteler</gitHubApi>
<!-- <gitHubToken>${GITHUB_OAUTH2TOKEN}</gitHubToken>&lt;!&ndash; Optional // &ndash;&gt;-->
<gitHubToken>${GITHUB_OAUTH2TOKEN}</gitHubToken>
<gitHubIssuePattern>#([0-9]*)</gitHubIssuePattern>
<templateFile>changelog.mustache</templateFile>
<readableTagName>-([^-]+?)$</readableTagName>
Expand All @@ -219,7 +245,7 @@
</execution>
</executions>
</plugin>

-->
</plugins>
</build>
<repositories>
Expand Down
2 changes: 1 addition & 1 deletion src/main/angular
2 changes: 2 additions & 0 deletions src/test/java/org/daming/hoteler/HotelerApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class HotelerApplicationTests {

@Test
void contextLoads() {
System.out.println("Hello, this is ci env");
System.out.println(System.getenv("CI"));
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.daming.hoteler.repository.jdbc;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
// @Transactional
@Disabled
@Transactional
@EnabledIfEnvironmentVariable(named = "CI", matches = "true")
class IRoleDaoTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
// import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Transactional;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
// @Transactional
@Disabled
@Transactional
@EnabledIfEnvironmentVariable(named = "CI", matches = "true")
class IUserDaoTest {

@Autowired
Expand Down

0 comments on commit ed69e71

Please sign in to comment.