Skip to content

Commit 956e6d2

Browse files
authoredDec 8, 2022
Add junit config option for omitting leafnodetype (#1088)
allow omitting the LeafNodeType (`[It]`) from being included in the junit results file by adding a new config option and skipping over the setting of name to LeafNodeType. Default behavior remains as is. a follow up on de44005 Signed-off-by: Brady Pratt <bpratt@redhat.com> Signed-off-by: Brady Pratt <bpratt@redhat.com>
1 parent 8804859 commit 956e6d2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
 

Diff for: ‎reporters/junit_report.go

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type JunitReportConfig struct {
3333

3434
// Enable OmitSpecLabels to prevent labels from appearing in the spec name
3535
OmitSpecLabels bool
36+
37+
// Enable OmitLeafNodeType to prevent the spec leaf node type from appearing in the spec name
38+
OmitLeafNodeType bool
3639
}
3740

3841
type JUnitTestSuites struct {
@@ -175,13 +178,17 @@ func GenerateJUnitReportWithConfig(report types.Report, dst string, config Junit
175178
}
176179
for _, spec := range report.SpecReports {
177180
name := fmt.Sprintf("[%s]", spec.LeafNodeType)
181+
if config.OmitLeafNodeType {
182+
name = ""
183+
}
178184
if spec.FullText() != "" {
179185
name = name + " " + spec.FullText()
180186
}
181187
labels := spec.Labels()
182188
if len(labels) > 0 && !config.OmitSpecLabels {
183189
name = name + " [" + strings.Join(labels, ", ") + "]"
184190
}
191+
name = strings.TrimSpace(name)
185192

186193
test := JUnitTestCase{
187194
Name: name,

Diff for: ‎reporters/junit_report_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ var _ = Describe("JunitReport", func() {
220220
OmitFailureMessageAttr: true,
221221
OmitCapturedStdOutErr: true,
222222
OmitSpecLabels: true,
223+
OmitLeafNodeType: true,
223224
})).Should(Succeed())
224225
DeferCleanup(os.Remove, fname)
225226

@@ -252,7 +253,7 @@ var _ = Describe("JunitReport", func() {
252253
Ω(suite.TestCases).Should(HaveLen(4))
253254

254255
failingSpec := suite.TestCases[0]
255-
Ω(failingSpec.Name).Should(Equal("[It] A B C"))
256+
Ω(failingSpec.Name).Should(Equal("A B C"))
256257
Ω(failingSpec.Classname).Should(Equal("My Suite"))
257258
Ω(failingSpec.Status).Should(Equal("timedout"))
258259
Ω(failingSpec.Skipped).Should(BeNil())
@@ -303,7 +304,7 @@ var _ = Describe("JunitReport", func() {
303304
))
304305

305306
passingSpec := suite.TestCases[1]
306-
Ω(passingSpec.Name).Should(Equal("[It] A"))
307+
Ω(passingSpec.Name).Should(Equal("A"))
307308
Ω(passingSpec.Classname).Should(Equal("My Suite"))
308309
Ω(passingSpec.Status).Should(Equal("passed"))
309310
Ω(passingSpec.Skipped).Should(BeNil())
@@ -313,7 +314,7 @@ var _ = Describe("JunitReport", func() {
313314
Ω(passingSpec.SystemErr).Should(BeEmpty())
314315

315316
pendingSpec := suite.TestCases[2]
316-
Ω(pendingSpec.Name).Should(Equal("[It] A"))
317+
Ω(pendingSpec.Name).Should(Equal("A"))
317318
Ω(pendingSpec.Classname).Should(Equal("My Suite"))
318319
Ω(pendingSpec.Status).Should(Equal("pending"))
319320
Ω(pendingSpec.Skipped.Message).Should(Equal("pending"))
@@ -323,7 +324,7 @@ var _ = Describe("JunitReport", func() {
323324
Ω(pendingSpec.SystemErr).Should(BeEmpty())
324325

325326
panickedSpec := suite.TestCases[3]
326-
Ω(panickedSpec.Name).Should(Equal("[It] A"))
327+
Ω(panickedSpec.Name).Should(Equal("A"))
327328
Ω(panickedSpec.Classname).Should(Equal("My Suite"))
328329
Ω(panickedSpec.Status).Should(Equal("panicked"))
329330
Ω(panickedSpec.Skipped).Should(BeNil())

0 commit comments

Comments
 (0)
Please sign in to comment.