5
5
"context"
6
6
"encoding/json"
7
7
"fmt"
8
- "io"
9
8
"io/ioutil"
10
9
"math/rand"
11
10
"os"
@@ -53,41 +52,40 @@ const (
53
52
// GinkgoRunSuiteOptions is used to run a suite of tests by invoking each test
54
53
// as a call to a child worker (the run-tests command).
55
54
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"`
61
60
62
61
// ShardCount is the total number of partitions the test suite is divided into.
63
62
// Each executor runs one of these partitions.
64
- ShardCount int
63
+ ShardCount int `json:"shardCount"`
65
64
66
65
// ShardStrategy is which strategy we'll use for dividing tests.
67
- ShardStrategy string
66
+ ShardStrategy string `json:"shardStrategy"`
68
67
69
68
// ShardID is the 1-based index of the shard this instance is responsible for running.
70
- ShardID int
69
+ ShardID int `json:"shardID"`
71
70
72
71
// SyntheticEventTests allows the caller to translate events or outside
73
72
// context into a failure.
74
- SyntheticEventTests JUnitsForEvents
73
+ SyntheticEventTests JUnitsForEvents `json:"-"`
75
74
76
- ClusterStabilityDuringTest string
75
+ ClusterStabilityDuringTest string `json:"clusterStability"`
77
76
78
- IncludeSuccessOutput bool
77
+ IncludeSuccessOutput bool `json:"-"`
79
78
80
- CommandEnv []string
79
+ CommandEnv []string `json:"-"`
81
80
82
- DryRun bool
83
- PrintCommands bool
84
- genericclioptions.IOStreams
81
+ DryRun bool `json:"dryRun"`
82
+ PrintCommands bool `json:"printCommands"`
85
83
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:"-"`
91
89
}
92
90
93
91
func NewGinkgoRunSuiteOptions (streams genericclioptions.IOStreams ) * GinkgoRunSuiteOptions {
@@ -735,13 +733,27 @@ func (o *GinkgoRunSuiteOptions) Run(suite *TestSuite, clusterConfig *clusterdisc
735
733
fmt .Fprintf (o .Out , "Blocking test failures:\n \n \t * %s\n \n " , strings .Join (names , "\n \t * " ))
736
734
}
737
735
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
+
738
750
if len (o .JUnitDir ) > 0 {
739
751
finalSuiteResults := generateJUnitTestSuiteResults (junitSuiteName , duration , tests , syntheticTestResults ... )
740
752
if err := writeJUnitReport (finalSuiteResults , "junit_e2e" , timeSuffix , o .JUnitDir , o .ErrOut ); err != nil {
741
753
fmt .Fprintf (o .Out , "error: Unable to write e2e JUnit xml results: %v" , err )
742
754
}
743
755
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 {
745
757
fmt .Fprintf (o .Out , "error: Unable to write e2e Extension Test Result JSON results: %v" , err )
746
758
}
747
759
@@ -779,11 +791,53 @@ func isBlockingFailure(test *testCase) bool {
779
791
}
780
792
}
781
793
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 {
783
837
// Ensure the directory exists
784
- err := os .MkdirAll (dir , 0755 )
838
+ err := os .MkdirAll (r . Options . JUnitDir , 0755 )
785
839
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 )
787
841
return err
788
842
}
789
843
@@ -794,27 +848,28 @@ func writeExtensionTestResults(tests []*testCase, dir, filePrefix, fileSuffix st
794
848
results = append (results , test .extensionTestResult )
795
849
}
796
850
}
851
+ r .Results = results
797
852
798
853
// Marshal results to JSON
799
- data , err := json .MarshalIndent (results , "" , " " )
854
+ data , err := json .MarshalIndent (r , "" , " " )
800
855
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 )
802
857
return err
803
858
}
804
859
805
860
// 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 ))
807
862
file , err := os .Create (filePath )
808
863
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 )
810
865
return err
811
866
}
812
867
defer file .Close ()
813
868
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 )
815
870
_ , err = file .Write (data )
816
871
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 )
818
873
return err
819
874
}
820
875
0 commit comments