mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Implement DetailsReporter
report within ReportAfterSuite
The change is needed to verify the conformance test spec, as this is verified in `verify-conformance-yaml.sh`. Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
parent
b57bade50c
commit
dd58016484
@ -120,12 +120,6 @@ func RunE2ETests(t *testing.T) {
|
||||
// Stream the progress to stdout and optionally a URL accepting progress updates.
|
||||
r = append(r, e2ereporters.NewProgressReporter(framework.TestContext.ProgressReportURL))
|
||||
|
||||
// The DetailsRepoerter will output details about every test (name, files, lines, etc) which helps
|
||||
// when documenting our tests.
|
||||
if len(framework.TestContext.SpecSummaryOutput) > 0 {
|
||||
r = append(r, e2ereporters.NewDetailsReporterFile(framework.TestContext.SpecSummaryOutput))
|
||||
}
|
||||
|
||||
klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, config.GinkgoConfig.ParallelNode)
|
||||
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
|
||||
}
|
||||
|
@ -21,9 +21,11 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
// Never, ever remove the line with "/ginkgo". Without it,
|
||||
@ -33,6 +35,7 @@ import (
|
||||
// "github.com/onsi/ginkgo/v2"
|
||||
|
||||
"k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
conformancetestdata "k8s.io/kubernetes/test/conformance/testdata"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
"k8s.io/kubernetes/test/e2e/framework/config"
|
||||
@ -135,3 +138,43 @@ func TestMain(m *testing.M) {
|
||||
func TestE2E(t *testing.T) {
|
||||
RunE2ETests(t)
|
||||
}
|
||||
|
||||
var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkgo.Report) {
|
||||
var err error
|
||||
// The DetailsRepoerter will output details about every test (name, files, lines, etc) which helps
|
||||
// when documenting our tests.
|
||||
if len(framework.TestContext.SpecSummaryOutput) <= 0 {
|
||||
return
|
||||
}
|
||||
absPath, err := filepath.Abs(framework.TestContext.SpecSummaryOutput)
|
||||
if err != nil {
|
||||
klog.Errorf("%#v\n", err)
|
||||
panic(err)
|
||||
}
|
||||
f, err := os.Create(absPath)
|
||||
if err != nil {
|
||||
klog.Errorf("%#v\n", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
for _, specReport := range report.SpecReports {
|
||||
b, err := specReport.MarshalJSON()
|
||||
if err != nil {
|
||||
klog.Errorf("Error in detail reporter: %v", err)
|
||||
return
|
||||
}
|
||||
_, err = f.Write(b)
|
||||
if err != nil {
|
||||
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
||||
return
|
||||
}
|
||||
// Printing newline between records for easier viewing in various tools.
|
||||
_, err = fmt.Fprintln(f, "")
|
||||
if err != nil {
|
||||
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 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 reporters
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/onsi/ginkgo/v2/config"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// DetailsReporter is a ginkgo reporter which dumps information regarding the tests which is difficult to get
|
||||
// via an AST app. This allows us to leverage the existing ginkgo logic to walk the tests and such while then following
|
||||
// up with an custom app which leverages AST to generate conformance documentation.
|
||||
type DetailsReporter struct {
|
||||
Writer io.Writer
|
||||
}
|
||||
|
||||
// NewDetailsReporterWithWriter returns a reporter which will write the SpecSummary objects as tests
|
||||
// complete to the given writer.
|
||||
func NewDetailsReporterWithWriter(w io.Writer) *DetailsReporter {
|
||||
return &DetailsReporter{
|
||||
Writer: w,
|
||||
}
|
||||
}
|
||||
|
||||
// NewDetailsReporterFile returns a reporter which will create the file given and dump the specs
|
||||
// to it as they complete.
|
||||
func NewDetailsReporterFile(filename string) *DetailsReporter {
|
||||
absPath, err := filepath.Abs(filename)
|
||||
if err != nil {
|
||||
klog.Errorf("%#v\n", err)
|
||||
panic(err)
|
||||
}
|
||||
f, err := os.Create(absPath)
|
||||
if err != nil {
|
||||
klog.Errorf("%#v\n", err)
|
||||
panic(err)
|
||||
}
|
||||
return NewDetailsReporterWithWriter(f)
|
||||
}
|
||||
|
||||
// SpecSuiteWillBegin is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *DetailsReporter) SpecSuiteWillBegin(cfg config.GinkgoConfigType, summary *types.SuiteSummary) {
|
||||
}
|
||||
|
||||
// SpecSuiteDidEnd is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *DetailsReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {}
|
||||
|
||||
// SpecDidComplete is invoked by Ginkgo each time a spec is completed (including skipped specs).
|
||||
func (reporter *DetailsReporter) SpecDidComplete(specSummary *types.SpecSummary) {
|
||||
b, err := json.Marshal(specSummary)
|
||||
if err != nil {
|
||||
klog.Errorf("Error in detail reporter: %v", err)
|
||||
return
|
||||
}
|
||||
_, err = reporter.Writer.Write(b)
|
||||
if err != nil {
|
||||
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
||||
return
|
||||
}
|
||||
// Printing newline between records for easier viewing in various tools.
|
||||
_, err = fmt.Fprintln(reporter.Writer, "")
|
||||
if err != nil {
|
||||
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// SpecWillRun is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *DetailsReporter) SpecWillRun(specSummary *types.SpecSummary) {}
|
||||
|
||||
// BeforeSuiteDidRun is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *DetailsReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {}
|
||||
|
||||
// AfterSuiteDidRun is implemented as a noop to satisfy the reporter interface for ginkgo.
|
||||
func (reporter *DetailsReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
|
||||
if c, ok := reporter.Writer.(io.Closer); ok {
|
||||
c.Close()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user