Skip to content

Commit 9be1850

Browse files
acuminoschrej
authored andcommitted
Adpat custom reporter chnages
1 parent 5adb662 commit 9be1850

40 files changed

+43
-252
lines changed

pkg/builder/builder_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2625
"k8s.io/apimachinery/pkg/api/meta"
@@ -78,8 +77,7 @@ var _ = AfterSuite(func() {
7877
})
7978

8079
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
81-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
82-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
80+
printer.AddReport(report, suiteName)
8381
})
8482

8583
func addCRDToEnvironment(env *envtest.Environment, gvks ...schema.GroupVersionKind) {

pkg/builder/controller_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
552552
go func() {
553553
defer GinkgoRecover()
554554
Expect(mgr.Start(ctx)).NotTo(HaveOccurred())
555-
By("Stopping the application")
556555
}()
557556

558557
By("Creating a Deployment")

pkg/cache/cache_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
"k8s.io/client-go/kubernetes"
2625
"k8s.io/client-go/rest"
@@ -59,6 +58,5 @@ var _ = AfterSuite(func() {
5958
})
6059

6160
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
62-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
63-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
61+
printer.AddReport(report, suiteName)
6462
})

pkg/cache/internal/internal_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
2625
)
@@ -33,6 +32,5 @@ func TestSource(t *testing.T) {
3332
}
3433

3534
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
36-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
37-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
35+
printer.AddReport(report, suiteName)
3836
})

pkg/certwatcher/certwatcher_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
. "github.com/onsi/ginkgo/v2"
24-
"github.com/onsi/ginkgo/v2/reporters"
2524
. "github.com/onsi/gomega"
2625
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
2726
logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -50,6 +49,5 @@ var _ = AfterSuite(func() {
5049
})
5150

5251
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
53-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
54-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
52+
printer.AddReport(report, suiteName)
5553
})

pkg/client/apiutil/apiutil_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
"k8s.io/client-go/rest"
2625
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
@@ -46,6 +45,5 @@ var _ = BeforeSuite(func() {
4645
})
4746

4847
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
49-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
50-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
48+
printer.AddReport(report, suiteName)
5149
})

pkg/client/client_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
"k8s.io/client-go/kubernetes"
2625
"k8s.io/client-go/kubernetes/scheme"
@@ -64,6 +63,5 @@ var _ = AfterSuite(func() {
6463
})
6564

6665
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
67-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
68-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
66+
printer.AddReport(report, suiteName)
6967
})

pkg/client/config/config_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524

2625
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
@@ -40,6 +39,5 @@ var _ = BeforeSuite(func() {
4039
})
4140

4241
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
43-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
44-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
42+
printer.AddReport(report, suiteName)
4543
})

pkg/client/fake/client_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
2625

@@ -40,6 +39,5 @@ var _ = BeforeSuite(func() {
4039
})
4140

4241
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
43-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
44-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
42+
printer.AddReport(report, suiteName)
4543
})

pkg/cluster/cluster_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
. "github.com/onsi/ginkgo/v2"
24-
"github.com/onsi/ginkgo/v2/reporters"
2524
. "github.com/onsi/gomega"
2625
"k8s.io/client-go/kubernetes"
2726
"k8s.io/client-go/rest"
@@ -72,6 +71,5 @@ var _ = AfterSuite(func() {
7271
})
7372

7473
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
75-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
76-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
74+
printer.AddReport(report, suiteName)
7775
})

pkg/config/config_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524

2625
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
@@ -34,6 +33,5 @@ func TestScheme(t *testing.T) {
3433
}
3534

3635
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
37-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
38-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
36+
printer.AddReport(report, suiteName)
3937
})

pkg/controller/controller_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
. "github.com/onsi/ginkgo/v2"
24-
"github.com/onsi/ginkgo/v2/reporters"
2524
. "github.com/onsi/gomega"
2625
"k8s.io/apimachinery/pkg/runtime/schema"
2726
"k8s.io/client-go/kubernetes"
@@ -94,6 +93,5 @@ var _ = AfterSuite(func() {
9493
})
9594

9695
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
97-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
98-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
96+
printer.AddReport(report, suiteName)
9997
})

pkg/controller/controllerutil/controllerutil_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524

2625
"k8s.io/client-go/rest"
@@ -57,6 +56,5 @@ var _ = AfterSuite(func() {
5756
})
5857

5958
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
60-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
61-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
59+
printer.AddReport(report, suiteName)
6260
})

pkg/envtest/envtest_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/ginkgo/v2"
23-
"github.com/onsi/ginkgo/v2/reporters"
2423
. "github.com/onsi/gomega"
2524
admissionv1 "k8s.io/api/admissionregistration/v1"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -138,6 +137,5 @@ var _ = AfterSuite(func() {
138137
})
139138

140139
var _ = ReportAfterSuite("Report to Prow", func(report Report) {
141-
reporters.ReportViaDeprecatedReporter(printer.NewlineReporter{}, report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
142-
reporters.ReportViaDeprecatedReporter(printer.NewProwReporter(suiteName), report) //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
140+
printer.AddReport(report, suiteName)
143141
})

pkg/envtest/ginkgo_test.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

pkg/envtest/printer/ginkgo.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

pkg/envtest/printer/prow.go

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import (
2222
"path/filepath"
2323
"sync"
2424

25-
"github.com/onsi/ginkgo/v2/config"
25+
"github.com/onsi/ginkgo/v2"
2626
"github.com/onsi/ginkgo/v2/reporters"
27-
"github.com/onsi/ginkgo/v2/types"
28-
2927
"k8s.io/apimachinery/pkg/util/sets"
3028
)
3129

@@ -34,75 +32,20 @@ var (
3432
allRegisteredSuitesLock = &sync.Mutex{}
3533
)
3634

37-
type prowReporter struct {
38-
junitReporter *reporters.JUnitReporter
39-
}
40-
41-
// NewProwReporter returns a prowReporter that will write out junit if running in Prow and do
42-
// nothing otherwise.
43-
// WARNING: It seems this does not always properly fail the test runs when there are failures,
44-
// see https://github.com/onsi/ginkgo/issues/706
45-
// When using this you must make sure to grep for failures in your junit xmls and fail the run
46-
// if there are any.
47-
func NewProwReporter(suiteName string) reporters.DeprecatedReporter { //nolint // For migration of custom reporter check https://onsi.github.io/ginkgo/MIGRATING_TO_V2#migration-strategy-2
35+
// AddReport adds.
36+
func AddReport(report ginkgo.Report, suiteName string) {
4837
allRegisteredSuitesLock.Lock()
4938
if allRegisteredSuites.Has(suiteName) {
5039
panic(fmt.Sprintf("Suite named %q registered more than once", suiteName))
5140
}
5241
allRegisteredSuites.Insert(suiteName)
5342
allRegisteredSuitesLock.Unlock()
5443

55-
if os.Getenv("CI") == "" {
56-
return &prowReporter{}
57-
}
5844
artifactsDir := os.Getenv("ARTIFACTS")
59-
if artifactsDir == "" {
60-
return &prowReporter{}
61-
}
62-
63-
path := filepath.Join(artifactsDir, fmt.Sprintf("junit_%s.xml", suiteName))
64-
return &prowReporter{
65-
junitReporter: reporters.NewJUnitReporter(path),
66-
}
67-
}
68-
69-
func (pr *prowReporter) SuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
70-
if pr.junitReporter != nil {
71-
pr.junitReporter.SuiteWillBegin(config, summary)
72-
}
73-
}
74-
75-
// BeforeSuiteDidRun implements ginkgo.Reporter.
76-
func (pr *prowReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
77-
if pr.junitReporter != nil {
78-
pr.junitReporter.BeforeSuiteDidRun(setupSummary)
79-
}
80-
}
81-
82-
// AfterSuiteDidRun implements ginkgo.Reporter.
83-
func (pr *prowReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
84-
if pr.junitReporter != nil {
85-
pr.junitReporter.AfterSuiteDidRun(setupSummary)
86-
}
87-
}
88-
89-
// SpecWillRun implements ginkgo.Reporter.
90-
func (pr *prowReporter) SpecWillRun(specSummary *types.SpecSummary) {
91-
if pr.junitReporter != nil {
92-
pr.junitReporter.SpecWillRun(specSummary)
93-
}
94-
}
95-
96-
// SpecDidComplete implements ginkgo.Reporter.
97-
func (pr *prowReporter) SpecDidComplete(specSummary *types.SpecSummary) {
98-
if pr.junitReporter != nil {
99-
pr.junitReporter.SpecDidComplete(specSummary)
100-
}
101-
}
10245

103-
// SuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:".
104-
func (pr *prowReporter) SuiteDidEnd(summary *types.SuiteSummary) {
105-
if pr.junitReporter != nil {
106-
pr.junitReporter.SuiteDidEnd(summary)
46+
if os.Getenv("CI") != "" && artifactsDir != "" {
47+
path := filepath.Join(artifactsDir, fmt.Sprintf("junit_%s_%d.xml", suiteName, report.SuiteConfig.ParallelProcess))
48+
err := reporters.GenerateJUnitReport(report, path)
49+
fmt.Printf("Failed to generate report\n\t%s", err.Error())
10750
}
10851
}

0 commit comments

Comments
 (0)