1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package junit 18 19 import ( 20 "github.com/onsi/ginkgo/v2" 21 "github.com/onsi/ginkgo/v2/reporters" 22 "github.com/onsi/ginkgo/v2/types" 23 ) 24 25 // WriteJUnitReport generates a JUnit file that is shorter than the one 26 // normally written by `ginkgo --junit-report`. This is needed because the full 27 // report can become too large for tools like Spyglass 28 // (https://github.com/kubernetes/kubernetes/issues/111510). 29 func WriteJUnitReport(report ginkgo.Report, filename string) error { 30 config := reporters.JunitReportConfig{ 31 // Remove details for specs where we don't care. 32 OmitTimelinesForSpecState: types.SpecStatePassed | types.SpecStateSkipped, 33 34 // Don't write <failure message="summary">. The same text is 35 // also in the full text for the failure. If we were to write 36 // both, then tools like kettle and spyglass would concatenate 37 // the two strings and thus show duplicated information. 38 OmitFailureMessageAttr: true, 39 40 // All labels are also part of the spec texts in inline [] tags, 41 // so we don't need to write them separately. 42 OmitSpecLabels: true, 43 } 44 45 return reporters.GenerateJUnitReportWithConfig(report, filename, config) 46 } 47