Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏃 Generate junit in CI #1053

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hack/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ setup_envs
header_text "running go test"

go test -race ${MOD_OPT} ./...

if [[ -n ${ARTIFACTS:-} ]]; then
if grep -Rin '<failure type="Failure">' ${ARTIFACTS}/*; then exit 1; fi
fi
3 changes: 2 additions & 1 deletion pkg/builder/builder_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import (

func TestBuilder(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "application Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "application Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
3 changes: 2 additions & 1 deletion pkg/cache/cache_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Cache Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Cache Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/apiutil/apiutil_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "API Utilities Test Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "API Utilities Test Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var cfg *rest.Config
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/client_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Controller Integration Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Client Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/config/config_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

func TestConfig(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Client Config Test Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Client Config Test Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func(done Done) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/fake/client_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Controller Integration Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Fake client Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func(done Done) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Controller Integration Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Controller Integration Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/controllerutil/controllerutil_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestControllerutil(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Controllerutil Suite")
suiteName := "Controllerutil Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var t *envtest.Environment
Expand Down
4 changes: 3 additions & 1 deletion pkg/envtest/envtest_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import (
admissionv1beta1 "k8s.io/api/admissionregistration/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "EnvTest Suite", []Reporter{NewlineReporter{}})
suiteName := "Envtest Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var env *Environment
Expand Down
109 changes: 109 additions & 0 deletions pkg/envtest/printer/prow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright 2020 The Kubernetes 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

http://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 printer

import (
"fmt"
"os"
"path/filepath"
"sync"

"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/ginkgo/types"

"k8s.io/apimachinery/pkg/util/sets"
)

var (
allRegisteredSuites = sets.String{}
allRegisteredSuitesLock = &sync.Mutex{}
)

type prowReporter struct {
junitReporter *reporters.JUnitReporter
}

// NewProwReporter returns a prowReporter that will write out junit if running in Prow and do
// nothing otherwise.
// WARNING: It seems this does not always properly fail the test runs when there are failures,
// see https://github.com/onsi/ginkgo/issues/706
// When using this you must make sure to grep for failures in your junit xmls and fail the run
// if there are any.
func NewProwReporter(suiteName string) ginkgo.Reporter {
allRegisteredSuitesLock.Lock()
if allRegisteredSuites.Has(suiteName) {
panic(fmt.Sprintf("Suite named %q registered more than once", suiteName))
}
allRegisteredSuites.Insert(suiteName)
allRegisteredSuitesLock.Unlock()

if os.Getenv("CI") == "" {
return &prowReporter{}
}
artifactsDir := os.Getenv("ARTIFACTS")
if artifactsDir == "" {
return &prowReporter{}
}

path := filepath.Join(artifactsDir, fmt.Sprintf("junit_%s_%d.xml", suiteName, config.GinkgoConfig.ParallelNode))
return &prowReporter{
junitReporter: reporters.NewJUnitReporter(path),
}
}

func (pr *prowReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
if pr.junitReporter != nil {
pr.junitReporter.SpecSuiteWillBegin(config, summary)
}
}

// BeforeSuiteDidRun implements ginkgo.Reporter
func (pr *prowReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
if pr.junitReporter != nil {
pr.junitReporter.BeforeSuiteDidRun(setupSummary)
}
}

// AfterSuiteDidRun implements ginkgo.Reporter
func (pr *prowReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
if pr.junitReporter != nil {
pr.junitReporter.AfterSuiteDidRun(setupSummary)
}
}

// SpecWillRun implements ginkgo.Reporter
func (pr *prowReporter) SpecWillRun(specSummary *types.SpecSummary) {
if pr.junitReporter != nil {
pr.junitReporter.SpecWillRun(specSummary)
}
}

// SpecDidComplete implements ginkgo.Reporter
func (pr *prowReporter) SpecDidComplete(specSummary *types.SpecSummary) {
if pr.junitReporter != nil {
pr.junitReporter.SpecDidComplete(specSummary)
}
}

// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:"
func (pr *prowReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
if pr.junitReporter != nil {
pr.junitReporter.SpecSuiteDidEnd(summary)
}
}
3 changes: 2 additions & 1 deletion pkg/handler/eventhandler_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (

func TestEventhandler(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Eventhandler Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Eventhandler Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
3 changes: 2 additions & 1 deletion pkg/healthz/healthz_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (

func TestHealthz(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Healthz Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Healthz Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/internal/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Controller Integration Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Controller internal Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
3 changes: 2 additions & 1 deletion pkg/internal/recorder/recorder_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (

func TestRecorder(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Recorder Integration Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Recorder Integration Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
7 changes: 5 additions & 2 deletions pkg/internal/testing/integration/addr/addr_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package addr_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestAddr(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Addr Suite")
suiteName := "Addr Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
7 changes: 5 additions & 2 deletions pkg/internal/testing/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package integration_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestIntegration(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Integration Framework Unit Tests")
suiteName := "Integration Framework Unit Tests"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package integrationtests

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestIntegration(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Integration Framework Integration Tests")
suiteName := "Integration Framework Integration Tests"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package internal_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestInternal(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Internal Suite")
suiteName := "Internal Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
3 changes: 2 additions & 1 deletion pkg/log/log_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Log Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Log Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
3 changes: 2 additions & 1 deletion pkg/log/zap/zap_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Zap Log Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Zap Log Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}
3 changes: 2 additions & 1 deletion pkg/manager/manager_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Controller Integration Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Manager Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var testenv *envtest.Environment
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/signals/signals_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Runtime Signal Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Runtime Signal Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/predicate/predicate_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (

func TestPredicate(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Predicate Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Predicate Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconcile/reconcile_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (

func TestReconcile(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "reconcile Suite", []Reporter{printer.NewlineReporter{}})
suiteName := "Reconcile Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func() {
Expand Down
Loading