Skip to content

Commit 0f040de

Browse files
authored
Merge pull request #2633 from programmer04/sort-report
Sort items in conformance reports to maintain stability
2 parents 087d3ab + 01bae94 commit 0f040de

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

conformance/utils/suite/experimental_reports.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package suite
1818

1919
import (
20+
"sort"
21+
2022
"k8s.io/apimachinery/pkg/util/sets"
2123

2224
confv1a1 "sigs.k8s.io/gateway-api/conformance/apis/v1alpha1"
@@ -72,9 +74,6 @@ func (p profileReportsMap) addTestResults(conformanceProfile ConformanceProfile,
7274
if report.Extended == nil {
7375
report.Extended = &confv1a1.ExtendedStatus{}
7476
}
75-
if report.Extended.FailedTests == nil {
76-
report.Extended.FailedTests = []string{}
77-
}
7877
report.Extended.FailedTests = append(report.Extended.FailedTests, result.test.ShortName)
7978
report.Extended.Statistics.Failed++
8079
} else {
@@ -90,15 +89,9 @@ func (p profileReportsMap) addTestResults(conformanceProfile ConformanceProfile,
9089
report.Extended = &confv1a1.ExtendedStatus{}
9190
}
9291
report.Extended.Statistics.Skipped++
93-
if report.Extended.SkippedTests == nil {
94-
report.Extended.SkippedTests = []string{}
95-
}
9692
report.Extended.SkippedTests = append(report.Extended.SkippedTests, result.test.ShortName)
9793
} else {
9894
report.Core.Statistics.Skipped++
99-
if report.Core.SkippedTests == nil {
100-
report.Core.SkippedTests = []string{}
101-
}
10295
report.Core.SkippedTests = append(report.Core.SkippedTests, result.test.ShortName)
10396
}
10497
}
@@ -140,10 +133,11 @@ func (p profileReportsMap) compileResults(supportedFeaturesMap map[ConformancePr
140133
supportedFeatures := supportedFeaturesMap[ConformanceProfileName(report.Name)]
141134
if report.Extended != nil {
142135
if supportedFeatures != nil {
143-
if report.Extended.SupportedFeatures == nil {
144-
report.Extended.SupportedFeatures = make([]string, 0)
145-
}
146-
for _, f := range supportedFeatures.UnsortedList() {
136+
supportedFeatures := supportedFeatures.UnsortedList()
137+
sort.Slice(supportedFeatures, func(i, j int) bool {
138+
return supportedFeatures[i] < supportedFeatures[j]
139+
})
140+
for _, f := range supportedFeatures {
147141
report.Extended.SupportedFeatures = append(report.Extended.SupportedFeatures, string(f))
148142
}
149143
}
@@ -152,10 +146,11 @@ func (p profileReportsMap) compileResults(supportedFeaturesMap map[ConformancePr
152146
unsupportedFeatures := unsupportedFeaturesMap[ConformanceProfileName(report.Name)]
153147
if report.Extended != nil {
154148
if unsupportedFeatures != nil {
155-
if report.Extended.UnsupportedFeatures == nil {
156-
report.Extended.UnsupportedFeatures = make([]string, 0)
157-
}
158-
for _, f := range unsupportedFeatures.UnsortedList() {
149+
unsupportedFeatures := unsupportedFeatures.UnsortedList()
150+
sort.Slice(unsupportedFeatures, func(i, j int) bool {
151+
return unsupportedFeatures[i] < unsupportedFeatures[j]
152+
})
153+
for _, f := range unsupportedFeatures {
159154
report.Extended.UnsupportedFeatures = append(report.Extended.UnsupportedFeatures, string(f))
160155
}
161156
}

conformance/utils/suite/experimental_suite.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package suite
1919
import (
2020
"errors"
2121
"fmt"
22+
"sort"
2223
"strings"
2324
"sync"
2425
"testing"
@@ -255,10 +256,19 @@ func (suite *ExperimentalConformanceTestSuite) Report() (*confv1a1.ConformanceRe
255256
}
256257
defer suite.lock.RUnlock()
257258

259+
testNames := make([]string, 0, len(suite.results))
260+
for tN := range suite.results {
261+
testNames = append(testNames, tN)
262+
}
263+
sort.Strings(testNames)
258264
profileReports := newReports()
259-
for _, testResult := range suite.results {
260-
conformanceProfiles := getConformanceProfilesForTest(testResult.test, suite.conformanceProfiles)
261-
for _, profile := range conformanceProfiles.UnsortedList() {
265+
for _, tN := range testNames {
266+
testResult := suite.results[tN]
267+
conformanceProfiles := getConformanceProfilesForTest(testResult.test, suite.conformanceProfiles).UnsortedList()
268+
sort.Slice(conformanceProfiles, func(i, j int) bool {
269+
return conformanceProfiles[i].Name < conformanceProfiles[j].Name
270+
})
271+
for _, profile := range conformanceProfiles {
262272
profileReports.addTestResults(*profile, testResult)
263273
}
264274
}

0 commit comments

Comments
 (0)