Add a 'core dump' to failed tests.

This commit is contained in:
Brendan Burns
2015-05-26 20:50:25 -07:00
parent 496be63c00
commit 199ed54599
2 changed files with 119 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ import (
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/ginkgo/types"
"github.com/onsi/gomega"
)
@@ -66,6 +67,22 @@ var (
reportDir = flag.String("report-dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.")
)
type failReporter struct {
failed bool
}
func (f *failReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
}
func (f *failReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {}
func (f *failReporter) SpecWillRun(specSummary *types.SpecSummary) {}
func (f *failReporter) SpecDidComplete(specSummary *types.SpecSummary) {
if specSummary.Failed() {
f.failed = true
}
}
func (f *failReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {}
func (f *failReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {}
func init() {
// Turn on verbose by default to get spec names
config.DefaultReporterConfig.Verbose = true
@@ -119,7 +136,6 @@ func TestE2E(t *testing.T) {
if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" {
config.GinkgoConfig.SkipString = "Skipped"
}
gomega.RegisterFailHandler(ginkgo.Fail)
// Ensure all pods are running and ready before starting tests (otherwise,
@@ -134,6 +150,13 @@ func TestE2E(t *testing.T) {
var r []ginkgo.Reporter
if *reportDir != "" {
r = append(r, reporters.NewJUnitReporter(path.Join(*reportDir, fmt.Sprintf("junit_%02d.xml", config.GinkgoConfig.ParallelNode))))
failReport := &failReporter{}
r = append(r, failReport)
defer func() {
if failReport.failed {
coreDump(*reportDir)
}
}()
}
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
}