Skip to content

Commit e6e6cb6

Browse files
authored
Pipeline tests simplification (#1348)
1 parent fb49bb2 commit e6e6cb6

File tree

22 files changed

+158
-109
lines changed

22 files changed

+158
-109
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: maven-build-with-dry-run-for-tests
2+
description: maven-build-with-dry-run-for-tests
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: maven-build-with-dry-run-for-tests
7+
shell: bash
8+
run: |
9+
# find all the tests that are supposed to be run, but don't actually run them.
10+
# this is achieved via: 'spring.cloud.k8s.skip.tests=true' in DisabledTestsCondition
11+
./mvnw clean install -Dskip.build.image=true -Dspring.cloud.k8s.skip.tests=true \
12+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=error \
13+
-T 1C > /tmp/tests.txt
14+
15+
- name: upload test
16+
uses: actions/upload-artifact@v3
17+
with:
18+
name: tests.txt
19+
path: /tmp/tests.txt
20+

.github/workflows/maven.yaml

Lines changed: 11 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
- name: build fabric8 istio
3535
uses: ./.github/workflows/composites/fabric8-istio
3636

37-
- name: build with skip tests and skip images
38-
run: ./mvnw -T 1C -s .settings.xml clean install -U -DskipTests -Dskip.build.image=true
37+
- name: maven build with dry-run for tests
38+
uses: ./.github/workflows/composites/maven-build-with-dry-run-for-tests
3939

4040
- name: build controllers project
4141
uses: ./.github/workflows/composites/build-controllers-project
@@ -136,86 +136,23 @@ jobs:
136136
uses: ./.github/workflows/composites/load-docker-images
137137
if: env.BASE_BRANCH != '2.1.x'
138138

139+
- name: download tests
140+
uses: actions/download-artifact@v3
141+
with:
142+
name: tests.txt
143+
path: /tmp
144+
139145
- name: run tests
140146
env:
141147
CURRENT_INDEX: ${{ matrix.current_index }}
142148
NUMBER_OF_JOBS: ${{ matrix.number_of_jobs }}
143149
run: |
144150
145-
# - find all tests
146-
# - exclude Fabric8IstionIT
147-
# - only take classes that have @Test inside them
148-
# - ignore the ones that have 'abstract class'. we do this because otherwise we would pass
149-
# to -DtestsToRun an abstract class, and it will not run anything.
150-
# - drop the "begining" xxx/src/test/java
151-
# - replace / with .
152-
# - drop last ".java"
153-
# - replace newline with space
154-
# - replace '\n' with ' '
155-
# exclude all integration tests for branch '2.1.x' via 'grep -v '.*IT.java''
156-
157-
echo "base_branch : $BASE_BRANCH"
158-
declare -a PLAIN_TEST_CLASSNAMES
159-
baseBranch=$BASE_BRANCH
160-
if [[ $baseBranch == "2.1.x" ]]; then
161-
162-
PLAIN_TEST_CLASSNAMES=($(find . -name '*.java' \
163-
| grep 'src/test/java' \
164-
| grep -v 'Fabric8IstioIT' \
165-
| grep -v '.*IT.java' \
166-
| xargs grep -l '@Test' \
167-
| xargs grep -L 'abstract class' \
168-
| sed 's/.*src.test.java.//g' \
169-
| sed 's@/@.@g' \
170-
| sed 's/.\{5\}$//' \
171-
| tr '\n' ' '))
172-
else
173-
PLAIN_TEST_CLASSNAMES=($(find . -name '*.java' \
174-
| grep 'src/test/java' \
175-
| grep -v 'Fabric8IstioIT' \
176-
| xargs grep -l '@Test' \
177-
| xargs grep -L 'abstract class' \
178-
| sed 's/.*src.test.java.//g' \
179-
| sed 's@/@.@g' \
180-
| sed 's/.\{5\}$//' \
181-
| tr '\n' ' '))
182-
fi
183-
184-
# classes that have @Test and are abstract, for example: "LabeledSecretWithPrefixTests"
185-
# - exclude Fabric8IstionIT
186-
# - only take classes that have @Test inside them
187-
# - only take classes that are abstract
188-
# - drop everything up until the last "/"
189-
# - drop ".java"
190-
191-
ABSTRACT_TEST_CLASSNAMES_COMMAND="find . -name '*.java' \
192-
| grep 'src/test/java' \
193-
| grep -v 'Fabric8IstioIT' \
194-
| xargs grep -l '@Test' \
195-
| xargs grep -l 'abstract class' \
196-
| sed 's/.*\///g' \
197-
| sed 's/.java//g'"
198-
199-
# find classes that extend abstract test classes
200-
DERIVED_FROM_ABSTRACT_CLASSES_COMMAND="find . -name '*.java' \
201-
| grep 'src/test/java' \
202-
| grep -v 'Fabric8IstioIT' \
203-
| xargs grep -l 'extends replace_me ' \
204-
| sed 's/.*src.test.java.//g' \
205-
| sed 's@/@.@g' \
206-
| sed 's/.\{5\}$//' \
207-
| tr '\n' ' '"
208-
209-
while read class_name; do
210-
replaced=$(echo ${DERIVED_FROM_ABSTRACT_CLASSES_COMMAND/replace_me/"$class_name"})
211-
result=($(eval $replaced))
212-
PLAIN_TEST_CLASSNAMES+=(${result[@]})
213-
done < <(eval $ABSTRACT_TEST_CLASSNAMES_COMMAND)
214-
151+
PLAIN_TEST_CLASSNAMES=($(cat /tmp/tests.txt | grep 'spring.cloud.k8s.test.to.run' | awk '{print $3}'))
215152
IFS=$'\n'
216-
SORTED_TEST_CLASSNAMES=( $(sort <<< "${PLAIN_TEST_CLASSNAMES[*]} | uniq -u") )
153+
SORTED_TEST_CLASSNAMES=( $(sort <<< "${PLAIN_TEST_CLASSNAMES[*]}") )
217154
unset IFS
218-
155+
219156
number_of_tests=${#SORTED_TEST_CLASSNAMES[@]}
220157
number_of_jobs=${NUMBER_OF_JOBS}
221158
current_index=${CURRENT_INDEX}
@@ -299,4 +236,3 @@ jobs:
299236
-Dmaven.wagon.http.retryHandler.count=3 \
300237
-Dskip.build.image=true
301238
fi
302-

spring-cloud-kubernetes-client-autoconfig/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<artifactId>mockito-inline</artifactId>
5555
<scope>test</scope>
5656
</dependency>
57+
<dependency>
58+
<groupId>org.springframework.cloud</groupId>
59+
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
60+
<scope>test</scope>
61+
</dependency>
5762
</dependencies>
5863

5964
</project>

spring-cloud-kubernetes-client-config/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
<artifactId>mockito-inline</artifactId>
110110
<scope>test</scope>
111111
</dependency>
112+
<dependency>
113+
<groupId>org.springframework.cloud</groupId>
114+
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
115+
<scope>test</scope>
116+
</dependency>
112117
</dependencies>
113118

114119

spring-cloud-kubernetes-client-discovery/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
<artifactId>wiremock-jre8-standalone</artifactId>
7676
<scope>test</scope>
7777
</dependency>
78+
<dependency>
79+
<groupId>org.springframework.cloud</groupId>
80+
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
81+
<scope>test</scope>
82+
</dependency>
7883

7984
</dependencies>
8085

spring-cloud-kubernetes-client-loadbalancer/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
<scope>test</scope>
5353
</dependency>
5454
<dependency>
55-
<groupId>org.junit.vintage</groupId>
56-
<artifactId>junit-vintage-engine</artifactId>
55+
<groupId>org.springframework.cloud</groupId>
56+
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
5757
<scope>test</scope>
5858
</dependency>
5959
</dependencies>

spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientLoadBalancerPodModeTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
import io.kubernetes.client.openapi.ApiClient;
2323
import io.kubernetes.client.util.ClientBuilder;
24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
24+
import org.junit.jupiter.api.Test;
2625

2726
import org.springframework.beans.factory.annotation.Autowired;
2827
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -39,7 +38,6 @@
3938
import org.springframework.http.HttpStatus;
4039
import org.springframework.http.client.ClientHttpResponse;
4140
import org.springframework.mock.http.client.MockClientHttpResponse;
42-
import org.springframework.test.context.junit4.SpringRunner;
4341
import org.springframework.web.client.RestTemplate;
4442

4543
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +50,6 @@
5250
/**
5351
* @author Ryan Baxter
5452
*/
55-
@RunWith(SpringRunner.class)
5653
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
5754
classes = KubernetesClientLoadBalancerPodModeTests.App.class)
5855
public class KubernetesClientLoadBalancerPodModeTests {

spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientLoadBalancerServiceModeTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import io.kubernetes.client.openapi.models.V1ServicePortBuilder;
2929
import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder;
3030
import io.kubernetes.client.util.ClientBuilder;
31-
import org.junit.Test;
32-
import org.junit.runner.RunWith;
31+
import org.junit.jupiter.api.Test;
3332
import org.mockito.Mockito;
3433

3534
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +45,6 @@
4645
import org.springframework.http.HttpStatus;
4746
import org.springframework.http.client.ClientHttpResponse;
4847
import org.springframework.mock.http.client.MockClientHttpResponse;
49-
import org.springframework.test.context.junit4.SpringRunner;
5048
import org.springframework.web.client.RestTemplate;
5149

5250
import static org.assertj.core.api.Assertions.assertThat;
@@ -58,7 +56,6 @@
5856
/**
5957
* @author Ryan Baxter
6058
*/
61-
@RunWith(SpringRunner.class)
6259
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
6360
classes = KubernetesClientLoadBalancerServiceModeTests.App.class,
6461
properties = { "spring.cloud.kubernetes.loadbalancer.mode=SERVICE" })

spring-cloud-kubernetes-commons/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
<artifactId>spring-test</artifactId>
103103
<scope>test</scope>
104104
</dependency>
105+
<dependency>
106+
<groupId>org.springframework.cloud</groupId>
107+
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
108+
<scope>test</scope>
109+
</dependency>
105110
</dependencies>
106111

107112

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<artifactId>mockito-inline</artifactId>
5353
<scope>test</scope>
5454
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.cloud</groupId>
57+
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
58+
<scope>test</scope>
59+
</dependency>
5560
</dependencies>
5661

5762
<build>

0 commit comments

Comments
 (0)