Skip to content

Commit

Permalink
add junit output for ginkgo based tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schrej committed Aug 25, 2022
1 parent fb50553 commit 8060863
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@

# Tools binaries.
hack/tools/bin

junit-report.xml
/artifacts
4 changes: 4 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -64,6 +67,7 @@ func Example() {
// This application controller will be running leader election with the provided configuration in the manager options.
// If leader election configuration is not provided, controller runs leader election with default values.
// Default values taken from: https://github.com/kubernetes/component-base/blob/master/config/v1alpha1/defaults.go
//
// defaultLeaseDuration = 15 * time.Second
// defaultRenewDeadline = 10 * time.Second
// defaultRetryPeriod = 2 * time.Second
Expand Down
17 changes: 15 additions & 2 deletions hack/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<failure type="Failure">' ${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
1 change: 1 addition & 0 deletions pkg/envtest/komega/komega_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions pkg/recorder/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit 8060863

Please sign in to comment.