Skip to content

Commit 98e3616

Browse files
committed
runsuite: include more information in ote artifact
Store the ginkgo run suite options.
1 parent d56a389 commit 98e3616

File tree

1 file changed

+86
-31
lines changed

1 file changed

+86
-31
lines changed

pkg/test/ginkgo/cmd_runsuite.go

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"io"
98
"io/ioutil"
109
"math/rand"
1110
"os"
@@ -53,41 +52,40 @@ const (
5352
// GinkgoRunSuiteOptions is used to run a suite of tests by invoking each test
5453
// as a call to a child worker (the run-tests command).
5554
type GinkgoRunSuiteOptions struct {
56-
Parallelism int
57-
Count int
58-
FailFast bool
59-
Timeout time.Duration
60-
JUnitDir string
55+
Parallelism int `json:"parallelism"`
56+
Count int `json:"count"`
57+
FailFast bool `json:"failFast"`
58+
Timeout time.Duration `json:"timeout"`
59+
JUnitDir string `json:"junitDir"`
6160

6261
// ShardCount is the total number of partitions the test suite is divided into.
6362
// Each executor runs one of these partitions.
64-
ShardCount int
63+
ShardCount int `json:"shardCount"`
6564

6665
// ShardStrategy is which strategy we'll use for dividing tests.
67-
ShardStrategy string
66+
ShardStrategy string `json:"shardStrategy"`
6867

6968
// ShardID is the 1-based index of the shard this instance is responsible for running.
70-
ShardID int
69+
ShardID int `json:"shardID"`
7170

7271
// SyntheticEventTests allows the caller to translate events or outside
7372
// context into a failure.
74-
SyntheticEventTests JUnitsForEvents
73+
SyntheticEventTests JUnitsForEvents `json:"-"`
7574

76-
ClusterStabilityDuringTest string
75+
ClusterStabilityDuringTest string `json:"clusterStability"`
7776

78-
IncludeSuccessOutput bool
77+
IncludeSuccessOutput bool `json:"-"`
7978

80-
CommandEnv []string
79+
CommandEnv []string `json:"-"`
8180

82-
DryRun bool
83-
PrintCommands bool
84-
genericclioptions.IOStreams
81+
DryRun bool `json:"dryRun"`
82+
PrintCommands bool `json:"printCommands"`
8583

86-
StartTime time.Time
87-
88-
ExactMonitorTests []string
89-
DisableMonitorTests []string
90-
Extension *extension.Extension
84+
genericclioptions.IOStreams `json:"-"`
85+
StartTime time.Time `json:"-"`
86+
ExactMonitorTests []string `json:"-"`
87+
DisableMonitorTests []string `json:"-"`
88+
Extension *extension.Extension `json:"-"`
9189
}
9290

9391
func NewGinkgoRunSuiteOptions(streams genericclioptions.IOStreams) *GinkgoRunSuiteOptions {
@@ -735,13 +733,27 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, clusterConfig *clusterdisc
735733
fmt.Fprintf(o.Out, "Blocking test failures:\n\n\t* %s\n\n", strings.Join(names, "\n\t* "))
736734
}
737735

736+
results := &extensionResults{
737+
Pass: pass,
738+
Skip: skip,
739+
BlockingFailures: len(blockingFailures),
740+
InformingFailures: len(informingFailures),
741+
StartTime: o.StartTime,
742+
EndTime: end,
743+
Duration: duration,
744+
CIEnvironment: fetchCIEnvironment(),
745+
ClusterConfiguration: clusterConfig,
746+
Suite: suite,
747+
Options: o,
748+
}
749+
738750
if len(o.JUnitDir) > 0 {
739751
finalSuiteResults := generateJUnitTestSuiteResults(junitSuiteName, duration, tests, syntheticTestResults...)
740752
if err := writeJUnitReport(finalSuiteResults, "junit_e2e", timeSuffix, o.JUnitDir, o.ErrOut); err != nil {
741753
fmt.Fprintf(o.Out, "error: Unable to write e2e JUnit xml results: %v", err)
742754
}
743755

744-
if err := writeExtensionTestResults(tests, o.JUnitDir, "extension_test_result_e2e", timeSuffix, o.ErrOut); err != nil {
756+
if err := results.write(tests, "extension_test_results", timeSuffix); err != nil {
745757
fmt.Fprintf(o.Out, "error: Unable to write e2e Extension Test Result JSON results: %v", err)
746758
}
747759

@@ -779,11 +791,53 @@ func isBlockingFailure(test *testCase) bool {
779791
}
780792
}
781793

782-
func writeExtensionTestResults(tests []*testCase, dir, filePrefix, fileSuffix string, out io.Writer) error {
794+
type ciEnvironment struct {
795+
BuildID string `json:"buildID"`
796+
JobName string `json:"jobName"`
797+
JobType string `json:"jobType"`
798+
ProwJobID string `json:"prowJobID"`
799+
800+
ReleaseImageLatest string `json:"releaseImageLatest"`
801+
OriginalReleaseImageLatest string `json:"originalReleaseImageLatest"`
802+
803+
ReleaseImageInitial string `json:"releaseImageInitial"`
804+
OriginalReleaseImageInitial string `json:"originalReleaseImageInitial"`
805+
}
806+
807+
type extensionResults struct {
808+
Total int `json:"total"`
809+
BlockingFailures int `json:"blockingFailures"`
810+
InformingFailures int `json:"informingFailures"`
811+
Pass int `json:"pass"`
812+
Skip int `json:"skip"`
813+
814+
CIEnvironment ciEnvironment `json:"ciEnvironment"`
815+
ClusterConfiguration *clusterdiscovery.ClusterConfiguration `json:"clusterConfiguration"`
816+
Suite *TestSuite `json:"suite"`
817+
Options *GinkgoRunSuiteOptions `json:"options"`
818+
StartTime time.Time `json:"startTime"`
819+
EndTime time.Time `json:"endTime"`
820+
Duration time.Duration `json:"duration"`
821+
Results extensions.ExtensionTestResults `json:"results"`
822+
}
823+
824+
func fetchCIEnvironment() ciEnvironment {
825+
return ciEnvironment{
826+
BuildID: os.Getenv("BUILD_ID"),
827+
JobName: os.Getenv("JOB_NAME"),
828+
JobType: os.Getenv("JOB_TYPE"),
829+
ProwJobID: os.Getenv("PROW_JOB_ID"),
830+
ReleaseImageLatest: os.Getenv("RELEASE_IMAGE_LATEST"),
831+
OriginalReleaseImageLatest: os.Getenv("ORIGINAL_RELEASE_IMAGE_LATEST"),
832+
ReleaseImageInitial: os.Getenv("RELEASE_IMAGE_INITIAL"),
833+
OriginalReleaseImageInitial: os.Getenv("ORIGINAL_RELEASE_IMAGE_INITIAL"),
834+
}
835+
}
836+
func (r *extensionResults) write(tests []*testCase, filePrefix, fileSuffix string) error {
783837
// Ensure the directory exists
784-
err := os.MkdirAll(dir, 0755)
838+
err := os.MkdirAll(r.Options.JUnitDir, 0755)
785839
if err != nil {
786-
fmt.Fprintf(out, "Failed to create directory %s: %v\n", dir, err)
840+
fmt.Fprintf(r.Options.ErrOut, "Failed to create directory %s: %v\n", r.Options.JUnitDir, err)
787841
return err
788842
}
789843

@@ -794,27 +848,28 @@ func writeExtensionTestResults(tests []*testCase, dir, filePrefix, fileSuffix st
794848
results = append(results, test.extensionTestResult)
795849
}
796850
}
851+
r.Results = results
797852

798853
// Marshal results to JSON
799-
data, err := json.MarshalIndent(results, "", " ")
854+
data, err := json.MarshalIndent(r, "", " ")
800855
if err != nil {
801-
fmt.Fprintf(out, "Failed to marshal test results to JSON: %v\n", err)
856+
fmt.Fprintf(r.Options.ErrOut, "Failed to marshal test results to JSON: %v\n", err)
802857
return err
803858
}
804859

805860
// Write JSON data to file
806-
filePath := filepath.Join(dir, fmt.Sprintf("%s_%s.json", filePrefix, fileSuffix))
861+
filePath := filepath.Join(r.Options.JUnitDir, fmt.Sprintf("%s_%s.json", filePrefix, fileSuffix))
807862
file, err := os.Create(filePath)
808863
if err != nil {
809-
fmt.Fprintf(out, "Failed to create file %s: %v\n", filePath, err)
864+
fmt.Fprintf(r.Options.ErrOut, "Failed to create file %s: %v\n", filePath, err)
810865
return err
811866
}
812867
defer file.Close()
813868

814-
fmt.Fprintf(out, "Writing extension test results JSON to %s\n", filePath)
869+
fmt.Fprintf(r.Options.ErrOut, "Writing extension test results JSON to %s\n", filePath)
815870
_, err = file.Write(data)
816871
if err != nil {
817-
fmt.Fprintf(out, "Failed to write to file %s: %v\n", filePath, err)
872+
fmt.Fprintf(r.Options.ErrOut, "Failed to write to file %s: %v\n", filePath, err)
818873
return err
819874
}
820875

0 commit comments

Comments
 (0)