Skip to content

Commit 5c35b11

Browse files
author
Ish Shah
committed
Xunit comments and seperate package
Signed-off-by: Ish Shah <[email protected]>
1 parent 5d2d302 commit 5c35b11

File tree

2 files changed

+83
-61
lines changed

2 files changed

+83
-61
lines changed

internal/cmd/operator-sdk/scorecard/cmd.go

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/labels"
3333

3434
scorecardannotations "github.com/operator-framework/operator-sdk/internal/annotations/scorecard"
35+
xunit "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/scorecard/xunit"
3536
"github.com/operator-framework/operator-sdk/internal/flags"
3637
registryutil "github.com/operator-framework/operator-sdk/internal/registry"
3738
"github.com/operator-framework/operator-sdk/internal/scorecard"
@@ -117,63 +118,8 @@ func (c *scorecardCmd) printOutput(output v1alpha3.TestList) error {
117118
return nil
118119
}
119120

120-
type TestCase struct {
121-
// Name is the name of the test
122-
Name string `json:"name,omitempty"`
123-
Time string `json:"time,omitempty"`
124-
Classname string `json:"classname,omitempty"`
125-
Group string `json:"group,omitempty"`
126-
Failures []xUnitComplexFailure `json:"failure,omitempty"`
127-
Errors []xUnitComplexError `json:"error,omitempty"`
128-
Skipped []xUnitComplexSkipped `json:"skipped,omitempty"`
129-
}
130-
131-
type TestSuite struct {
132-
// Name is the name of the test
133-
Name string `json:"name,omitempty"`
134-
Tests string `json:"tests,omitempty"`
135-
Failures string `json:"failures,omitempty"`
136-
Errors string `json:"errors,omitempty"`
137-
Group string `json:"group,omitempty"`
138-
Skipped string `json:"skipped,omitempty"`
139-
Timestamp string `json:"timestamp,omitempty"`
140-
Hostname string `json:"hostnames,omitempty"`
141-
ID string `json:"id,omitempty"`
142-
Package string `json:"package,omitempty"`
143-
File string `json:"file,omitempty"`
144-
Log string `json:"log,omitempty"`
145-
URL string `json:"url,omitempty"`
146-
Version string `json:"version,omitempty"`
147-
TestSuites []TestSuite `json:"testsuite,omitempty"`
148-
TestCases []TestCase `json:"testcase,omitempty"`
149-
}
150-
151-
type TestSuites struct {
152-
// Name is the name of the test
153-
Name string `json:"name,omitempty"`
154-
Tests string `json:"tests,omitempty"`
155-
Failures string `json:"failures,omitempty"`
156-
Errors string `json:"errors,omitempty"`
157-
TestSuite []TestSuite `json:"testsuite,omitempty"`
158-
}
159-
160-
type xUnitComplexError struct {
161-
Type string `json:"type,omitempty"`
162-
Message string `json:"message,omitempty"`
163-
}
164-
165-
type xUnitComplexFailure struct {
166-
Type string `json:"type,omitempty"`
167-
Message string `json:"message,omitempty"`
168-
}
169-
170-
type xUnitComplexSkipped struct {
171-
Type string `json:"type,omitempty"`
172-
Message string `json:"message,omitempty"`
173-
}
174-
175-
func (c *scorecardCmd) convertXunit(output v1alpha3.TestList) TestSuites {
176-
var resultSuite TestSuites
121+
func (c *scorecardCmd) convertXunit(output v1alpha3.TestList) xunit.TestSuites {
122+
var resultSuite xunit.TestSuites
177123
resultSuite.Name = "scorecard"
178124
resultSuite.Tests = ""
179125
resultSuite.Failures = ""
@@ -183,15 +129,15 @@ func (c *scorecardCmd) convertXunit(output v1alpha3.TestList) TestSuites {
183129
for _, item := range jsonTestItems {
184130
tempResults := item.Status.Results
185131
for _, res := range tempResults {
186-
var tCase TestCase
187-
var tSuite TestSuite
132+
var tCase xunit.TestCase
133+
var tSuite xunit.TestSuite
188134
tSuite.Name = res.Name
189135
tCase.Name = res.Name
190136
if res.State == v1alpha3.ErrorState {
191-
tCase.Errors = append(tCase.Errors, xUnitComplexError{"Error", strings.Join(res.Errors, ",")})
137+
tCase.Errors = append(tCase.Errors, xunit.XUnitComplexError{Type: "Error", Message: strings.Join(res.Errors, ",")})
192138
tSuite.Errors = strings.Join(res.Errors, ",")
193139
} else if res.State == v1alpha3.FailState {
194-
tCase.Failures = append(tCase.Failures, xUnitComplexFailure{"Failure", res.Log})
140+
tCase.Failures = append(tCase.Failures, xunit.XUnitComplexFailure{Type: "Failure", Message: res.Log})
195141
tSuite.Failures = res.Log
196142
}
197143
tSuite.TestCases = append(tSuite.TestCases, tCase)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2020 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package xunitapi
16+
17+
// TestCase contain the core information from a test run, including its name and status
18+
type TestCase struct {
19+
// Name is the name of the test
20+
Name string `json:"name,omitempty"`
21+
Time string `json:"time,omitempty"`
22+
Classname string `json:"classname,omitempty"`
23+
Group string `json:"group,omitempty"`
24+
Failures []XUnitComplexFailure `json:"failure,omitempty"`
25+
Errors []XUnitComplexError `json:"error,omitempty"`
26+
Skipped []XUnitComplexSkipped `json:"skipped,omitempty"`
27+
}
28+
29+
// TestSuite contains for details about a test beyond the final status
30+
type TestSuite struct {
31+
// Name is the name of the test
32+
Name string `json:"name,omitempty"`
33+
Tests string `json:"tests,omitempty"`
34+
Failures string `json:"failures,omitempty"`
35+
Errors string `json:"errors,omitempty"`
36+
Group string `json:"group,omitempty"`
37+
Skipped string `json:"skipped,omitempty"`
38+
Timestamp string `json:"timestamp,omitempty"`
39+
Hostname string `json:"hostnames,omitempty"`
40+
ID string `json:"id,omitempty"`
41+
Package string `json:"package,omitempty"`
42+
File string `json:"file,omitempty"`
43+
Log string `json:"log,omitempty"`
44+
URL string `json:"url,omitempty"`
45+
Version string `json:"version,omitempty"`
46+
TestSuites []TestSuite `json:"testsuite,omitempty"`
47+
TestCases []TestCase `json:"testcase,omitempty"`
48+
}
49+
50+
// TestSuites is the top level object for amassing Xunit test results
51+
type TestSuites struct {
52+
// Name is the name of the test
53+
Name string `json:"name,omitempty"`
54+
Tests string `json:"tests,omitempty"`
55+
Failures string `json:"failures,omitempty"`
56+
Errors string `json:"errors,omitempty"`
57+
TestSuite []TestSuite `json:"testsuite,omitempty"`
58+
}
59+
60+
// XUnitComplexError contains a type header along with the error messages
61+
type XUnitComplexError struct {
62+
Type string `json:"type,omitempty"`
63+
Message string `json:"message,omitempty"`
64+
}
65+
66+
// XUnitComplexFailure contains a type header along with the failure logs
67+
type XUnitComplexFailure struct {
68+
Type string `json:"type,omitempty"`
69+
Message string `json:"message,omitempty"`
70+
}
71+
72+
// XUnitComplexSkipped contianers a type header along with associated run logs
73+
type XUnitComplexSkipped struct {
74+
Type string `json:"type,omitempty"`
75+
Message string `json:"message,omitempty"`
76+
}

0 commit comments

Comments
 (0)