-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1053 from alvaroaleman/junit
🏃 Generate junit in CI
- Loading branch information
Showing
32 changed files
with
189 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}) | ||
} |
7 changes: 5 additions & 2 deletions
7
pkg/internal/testing/integration/internal/integration_tests/integration_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}) | ||
} |
7 changes: 5 additions & 2 deletions
7
pkg/internal/testing/integration/internal/internal_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.