Pipeline tests simplification (#1348)
This commit is contained in:
20
.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
vendored
Normal file
20
.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: maven-build-with-dry-run-for-tests
|
||||
description: maven-build-with-dry-run-for-tests
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: maven-build-with-dry-run-for-tests
|
||||
shell: bash
|
||||
run: |
|
||||
# find all the tests that are supposed to be run, but don't actually run them.
|
||||
# this is achieved via: 'spring.cloud.k8s.skip.tests=true' in DisabledTestsCondition
|
||||
./mvnw clean install -Dskip.build.image=true -Dspring.cloud.k8s.skip.tests=true \
|
||||
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=error \
|
||||
-T 1C > /tmp/tests.txt
|
||||
|
||||
- name: upload test
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: tests.txt
|
||||
path: /tmp/tests.txt
|
||||
|
||||
86
.github/workflows/maven.yaml
vendored
86
.github/workflows/maven.yaml
vendored
@@ -34,8 +34,8 @@ jobs:
|
||||
- name: build fabric8 istio
|
||||
uses: ./.github/workflows/composites/fabric8-istio
|
||||
|
||||
- name: build with skip tests and skip images
|
||||
run: ./mvnw -T 1C -s .settings.xml clean install -U -DskipTests -Dskip.build.image=true
|
||||
- name: maven build with dry-run for tests
|
||||
uses: ./.github/workflows/composites/maven-build-with-dry-run-for-tests
|
||||
|
||||
- name: build controllers project
|
||||
uses: ./.github/workflows/composites/build-controllers-project
|
||||
@@ -136,86 +136,23 @@ jobs:
|
||||
uses: ./.github/workflows/composites/load-docker-images
|
||||
if: env.BASE_BRANCH != '2.1.x'
|
||||
|
||||
- name: download tests
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: tests.txt
|
||||
path: /tmp
|
||||
|
||||
- name: run tests
|
||||
env:
|
||||
CURRENT_INDEX: ${{ matrix.current_index }}
|
||||
NUMBER_OF_JOBS: ${{ matrix.number_of_jobs }}
|
||||
run: |
|
||||
|
||||
# - find all tests
|
||||
# - exclude Fabric8IstionIT
|
||||
# - only take classes that have @Test inside them
|
||||
# - ignore the ones that have 'abstract class'. we do this because otherwise we would pass
|
||||
# to -DtestsToRun an abstract class, and it will not run anything.
|
||||
# - drop the "begining" xxx/src/test/java
|
||||
# - replace / with .
|
||||
# - drop last ".java"
|
||||
# - replace newline with space
|
||||
# - replace '\n' with ' '
|
||||
# exclude all integration tests for branch '2.1.x' via 'grep -v '.*IT.java''
|
||||
|
||||
echo "base_branch : $BASE_BRANCH"
|
||||
declare -a PLAIN_TEST_CLASSNAMES
|
||||
baseBranch=$BASE_BRANCH
|
||||
if [[ $baseBranch == "2.1.x" ]]; then
|
||||
|
||||
PLAIN_TEST_CLASSNAMES=($(find . -name '*.java' \
|
||||
| grep 'src/test/java' \
|
||||
| grep -v 'Fabric8IstioIT' \
|
||||
| grep -v '.*IT.java' \
|
||||
| xargs grep -l '@Test' \
|
||||
| xargs grep -L 'abstract class' \
|
||||
| sed 's/.*src.test.java.//g' \
|
||||
| sed 's@/@.@g' \
|
||||
| sed 's/.\{5\}$//' \
|
||||
| tr '\n' ' '))
|
||||
else
|
||||
PLAIN_TEST_CLASSNAMES=($(find . -name '*.java' \
|
||||
| grep 'src/test/java' \
|
||||
| grep -v 'Fabric8IstioIT' \
|
||||
| xargs grep -l '@Test' \
|
||||
| xargs grep -L 'abstract class' \
|
||||
| sed 's/.*src.test.java.//g' \
|
||||
| sed 's@/@.@g' \
|
||||
| sed 's/.\{5\}$//' \
|
||||
| tr '\n' ' '))
|
||||
fi
|
||||
|
||||
# classes that have @Test and are abstract, for example: "LabeledSecretWithPrefixTests"
|
||||
# - exclude Fabric8IstionIT
|
||||
# - only take classes that have @Test inside them
|
||||
# - only take classes that are abstract
|
||||
# - drop everything up until the last "/"
|
||||
# - drop ".java"
|
||||
|
||||
ABSTRACT_TEST_CLASSNAMES_COMMAND="find . -name '*.java' \
|
||||
| grep 'src/test/java' \
|
||||
| grep -v 'Fabric8IstioIT' \
|
||||
| xargs grep -l '@Test' \
|
||||
| xargs grep -l 'abstract class' \
|
||||
| sed 's/.*\///g' \
|
||||
| sed 's/.java//g'"
|
||||
|
||||
# find classes that extend abstract test classes
|
||||
DERIVED_FROM_ABSTRACT_CLASSES_COMMAND="find . -name '*.java' \
|
||||
| grep 'src/test/java' \
|
||||
| grep -v 'Fabric8IstioIT' \
|
||||
| xargs grep -l 'extends replace_me ' \
|
||||
| sed 's/.*src.test.java.//g' \
|
||||
| sed 's@/@.@g' \
|
||||
| sed 's/.\{5\}$//' \
|
||||
| tr '\n' ' '"
|
||||
|
||||
while read class_name; do
|
||||
replaced=$(echo ${DERIVED_FROM_ABSTRACT_CLASSES_COMMAND/replace_me/"$class_name"})
|
||||
result=($(eval $replaced))
|
||||
PLAIN_TEST_CLASSNAMES+=(${result[@]})
|
||||
done < <(eval $ABSTRACT_TEST_CLASSNAMES_COMMAND)
|
||||
|
||||
PLAIN_TEST_CLASSNAMES=($(cat /tmp/tests.txt | grep 'spring.cloud.k8s.test.to.run' | awk '{print $3}'))
|
||||
IFS=$'\n'
|
||||
SORTED_TEST_CLASSNAMES=( $(sort <<< "${PLAIN_TEST_CLASSNAMES[*]} | uniq -u") )
|
||||
SORTED_TEST_CLASSNAMES=( $(sort <<< "${PLAIN_TEST_CLASSNAMES[*]}") )
|
||||
unset IFS
|
||||
|
||||
|
||||
number_of_tests=${#SORTED_TEST_CLASSNAMES[@]}
|
||||
number_of_jobs=${NUMBER_OF_JOBS}
|
||||
current_index=${CURRENT_INDEX}
|
||||
@@ -299,4 +236,3 @@ jobs:
|
||||
-Dmaven.wagon.http.retryHandler.count=3 \
|
||||
-Dskip.build.image=true
|
||||
fi
|
||||
|
||||
|
||||
@@ -54,6 +54,11 @@
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -109,6 +109,11 @@
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -75,6 +75,11 @@
|
||||
<artifactId>wiremock-jre8-standalone</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -21,8 +21,7 @@ import java.util.Collections;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.util.ClientBuilder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -39,7 +38,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.mock.http.client.MockClientHttpResponse;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -52,7 +50,6 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = KubernetesClientLoadBalancerPodModeTests.App.class)
|
||||
public class KubernetesClientLoadBalancerPodModeTests {
|
||||
|
||||
@@ -28,8 +28,7 @@ import io.kubernetes.client.openapi.models.V1ServiceListBuilder;
|
||||
import io.kubernetes.client.openapi.models.V1ServicePortBuilder;
|
||||
import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder;
|
||||
import io.kubernetes.client.util.ClientBuilder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,7 +45,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.mock.http.client.MockClientHttpResponse;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -58,7 +56,6 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = KubernetesClientLoadBalancerServiceModeTests.App.class,
|
||||
properties = { "spring.cloud.kubernetes.loadbalancer.mode=SERVICE" })
|
||||
|
||||
@@ -102,6 +102,11 @@
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,11 @@
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -76,6 +76,11 @@
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -44,6 +44,11 @@
|
||||
<artifactId>wiremock-jre8-standalone</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
|
||||
<properties>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -54,6 +51,11 @@
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -125,6 +125,11 @@
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -159,6 +159,11 @@
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -115,6 +115,11 @@
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -45,10 +45,14 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -61,31 +61,16 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${maven-failsafe-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -46,5 +46,10 @@
|
||||
<artifactId>kubernetes-server-mock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2013-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.tests.commons.junit_extension;
|
||||
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
/**
|
||||
* This is mainly needed for our pipeline, to get the test classes names. Its purpose is
|
||||
* to act like a 'dry-run': show all the tests fully qualified names without actually
|
||||
* running them.
|
||||
*
|
||||
* The way to use it: "mvn clean test -Dspring.cloud.k8s.skip.tests=true". This way all
|
||||
* tests will be skipped, but also will be printed to the standard output as a fully
|
||||
* qualified name, i.e.:
|
||||
*
|
||||
* <pre>
|
||||
* spring.cloud.k8s.test.to.run -> org.springframework.cloud.kubernetes.Fabric8InsideHealthIndicatorTest
|
||||
* </pre>
|
||||
*
|
||||
* @author wind57
|
||||
*/
|
||||
public class DisabledTestsCondition implements ExecutionCondition {
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
|
||||
if ("true".equals(System.getProperty("spring.cloud.k8s.skip.tests"))) {
|
||||
System.out.println("spring.cloud.k8s.test.to.run -> " + extensionContext.getRequiredTestClass().getName());
|
||||
return ConditionEvaluationResult.disabled("");
|
||||
}
|
||||
else {
|
||||
return ConditionEvaluationResult.enabled("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.springframework.cloud.kubernetes.tests.commons.junit_extension.DisabledTestsCondition
|
||||
@@ -0,0 +1 @@
|
||||
junit.jupiter.extensions.autodetection.enabled=true
|
||||
Reference in New Issue
Block a user