From ccc34eb446f97d314f2ab9841f9596c487cdac21 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Mon, 22 Aug 2022 16:24:54 +0200 Subject: [PATCH] add junit output for ginkgo based tests --- .gitignore | 3 +++ example_test.go | 3 +++ hack/test-all.sh | 17 +++++++++++++++-- pkg/envtest/komega/komega_test.go | 1 + pkg/recorder/example_test.go | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c2c72faf34..294685952b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ # Tools binaries. hack/tools/bin + +junit-report.xml +/artifacts \ No newline at end of file diff --git a/example_test.go b/example_test.go index beee06215a..6a72a8019b 100644 --- a/example_test.go +++ b/example_test.go @@ -26,6 +26,9 @@ import ( corev1 "k8s.io/api/core/v1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + + // since we invoke tests with -ginkgo.junit-report we need to import ginkgo. + _ "github.com/onsi/ginkgo/v2" ) // This example creates a simple application Controller that is configured for ReplicaSets and Pods. diff --git a/hack/test-all.sh b/hack/test-all.sh index 37e4ec5d3a..202dd89492 100755 --- a/hack/test-all.sh +++ b/hack/test-all.sh @@ -20,8 +20,21 @@ source $(dirname ${BASH_SOURCE})/common.sh header_text "running go test" -go test -race ${P_FLAG} ${MOD_OPT} ./... +if [[ -n ${ARTIFACTS:-} ]]; then + GINKGO_ARGS="-ginkgo.junit-report=junit-report.xml" +fi + +result=0 +go test -race ${P_FLAG} ${MOD_OPT} ./... ${GINKGO_ARGS} || result=$? if [[ -n ${ARTIFACTS:-} ]]; then - if grep -Rin '' ${ARTIFACTS}/*; then exit 1; fi + mkdir -p ${ARTIFACTS} + for file in `find . -name *junit-report.xml`; do + new_file=${file#./} + new_file=${new_file%/junit-report.xml} + new_file=${new_file//"/"/"-"} + mv "$file" "$ARTIFACTS/junit_${new_file}.xml" + done fi + +exit $result diff --git a/pkg/envtest/komega/komega_test.go b/pkg/envtest/komega/komega_test.go index 3a00be6441..275610c8bb 100644 --- a/pkg/envtest/komega/komega_test.go +++ b/pkg/envtest/komega/komega_test.go @@ -3,6 +3,7 @@ package komega import ( "testing" + _ "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/recorder/example_test.go b/pkg/recorder/example_test.go index cf1beb40c8..969420d817 100644 --- a/pkg/recorder/example_test.go +++ b/pkg/recorder/example_test.go @@ -19,6 +19,7 @@ package recorder_test import ( corev1 "k8s.io/api/core/v1" + _ "github.com/onsi/ginkgo/v2" "sigs.k8s.io/controller-runtime/pkg/recorder" )