Skip to content

Commit

Permalink
Generate junit in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman committed Jul 17, 2020
1 parent f98ea97 commit ba7fed0
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 15 deletions.
3 changes: 2 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,12 @@ 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")
RunSpecsWithDefaultAndCustomReporters(t, "Controllerutil Suite", []Reporter{printer.NewlineReporter{}})
}

var t *envtest.Environment
Expand Down
52 changes: 47 additions & 5 deletions pkg/envtest/printer/ginkgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,30 @@ package printer

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

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

func init() {
if os.Getenv("CI") == "" {
return
}
artifactsDir := os.Getenv("ARTIFACTS")
if artifactsDir == "" {
return
}

junitReporter = reporters.NewJUnitReporter(filepath.Join(artifactsDir, fmt.Sprintf("junit_%d.xml", config.GinkgoConfig.ParallelNode)))
}

// A very dirty hack to get junit output in CI. Is nil unless the CI and ARTIFACTS env vars are set.
var junitReporter reporters.Reporter

var _ ginkgo.Reporter = NewlineReporter{}

// NewlineReporter is Reporter that Prints a newline after the default Reporter output so that the results
Expand All @@ -35,19 +53,43 @@ type NewlineReporter struct{}

// SpecSuiteWillBegin implements ginkgo.Reporter
func (NewlineReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
if junitReporter != nil {
junitReporter.SpecSuiteWillBegin(config, summary)
}
}

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

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

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

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

// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:"
func (NewlineReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) { fmt.Printf("\n") }
func (NewlineReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
fmt.Printf("\n")
if junitReporter != nil {
junitReporter.SpecSuiteDidEnd(summary)
}
}
6 changes: 4 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,16 @@
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")
RunSpecsWithDefaultAndCustomReporters(t, "Addr Suite", []Reporter{printer.NewlineReporter{}})
}
6 changes: 4 additions & 2 deletions pkg/internal/testing/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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")
RunSpecsWithDefaultAndCustomReporters(t, "Integration Framework Unit Tests", []Reporter{printer.NewlineReporter{}})
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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")
RunSpecsWithDefaultAndCustomReporters(t, "Integration Framework Integration Tests", []Reporter{printer.NewlineReporter{}})
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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")
RunSpecsWithDefaultAndCustomReporters(t, "Internal Suite", []Reporter{printer.NewlineReporter{}})
}
4 changes: 3 additions & 1 deletion pkg/scheme/scheme_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (

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

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

func TestScheme(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Scheme Suite")
RunSpecsWithDefaultAndCustomReporters(t, "Scheme Suite", []Reporter{printer.NewlineReporter{}})
}

0 comments on commit ba7fed0

Please sign in to comment.