Skip to content

Commit 8e9525b

Browse files
authored
Merge pull request #2799 from mlavacca/report-summary
feat: conformance report summary field
2 parents 8a58569 + b91df55 commit 8e9525b

File tree

4 files changed

+152
-6
lines changed

4 files changed

+152
-6
lines changed

conformance/apis/v1alpha1/profilereport.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ type ProfileReport struct {
2323
// "TLS", "Mesh", e.t.c.).
2424
Name string `json:"name"`
2525

26+
// Summary is a human-readable message intended for end-users to understand
27+
// the overall status at a glance.
28+
Summary string `json:"summary"`
29+
2630
// Core indicates the core support level which includes the set of tests
2731
// which are the minimum the implementation must pass to be considered at
2832
// all conformant.
@@ -51,10 +55,6 @@ type ExtendedStatus struct {
5155
type Status struct {
5256
Result `json:"result"`
5357

54-
// Summary is a human-readable message intended for end-users to understand
55-
// the overall status at a glance.
56-
Summary string `json:"summary"`
57-
5858
// Statistics includes numerical statistics on the result of the test run.
5959
Statistics `json:"statistics"`
6060

conformance/experimental_conformance_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"sigs.k8s.io/controller-runtime/pkg/client/config"
2828
"sigs.k8s.io/yaml"
2929

30-
v1 "sigs.k8s.io/gateway-api/apis/v1"
30+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3131
"sigs.k8s.io/gateway-api/apis/v1alpha2"
3232
"sigs.k8s.io/gateway-api/apis/v1beta1"
3333
confv1a1 "sigs.k8s.io/gateway-api/conformance/apis/v1alpha1"
@@ -66,7 +66,7 @@ func TestExperimentalConformance(t *testing.T) {
6666

6767
v1alpha2.AddToScheme(mgrClient.Scheme())
6868
v1beta1.AddToScheme(mgrClient.Scheme())
69-
v1.AddToScheme(mgrClient.Scheme())
69+
gatewayv1.AddToScheme(mgrClient.Scheme())
7070

7171
// standard conformance flags
7272
supportedFeatures = suite.ParseSupportedFeatures(*flags.SupportedFeatures)

conformance/utils/suite/experimental_reports.go

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

1919
import (
20+
"fmt"
2021
"sort"
2122

2223
"k8s.io/apimachinery/pkg/util/sets"
@@ -128,6 +129,7 @@ func (p profileReportsMap) compileResults(supportedFeaturesMap map[ConformancePr
128129
report.Extended.Result = confv1a1.Success
129130
}
130131
}
132+
report.Summary = buildSummary(report)
131133
p[key] = report
132134

133135
supportedFeatures := supportedFeaturesMap[ConformanceProfileName(report.Name)]
@@ -183,3 +185,25 @@ func isTestExtended(profile ConformanceProfile, test ConformanceTest) bool {
183185
}
184186
return false
185187
}
188+
189+
// buildSummary creates a human-readable message about each profile's test outcomes.
190+
func buildSummary(report confv1a1.ProfileReport) (reportSummary string) {
191+
reportSummary = fmt.Sprintf("Core tests %s", buildReportSummary(report.Core))
192+
if report.Extended != nil {
193+
reportSummary = fmt.Sprintf("%s. Extended tests %s", reportSummary, buildReportSummary(report.Extended.Status))
194+
}
195+
return fmt.Sprintf("%s.", reportSummary)
196+
}
197+
198+
func buildReportSummary(status confv1a1.Status) string {
199+
var message string
200+
switch status.Result {
201+
case confv1a1.Success:
202+
message = "succeeded"
203+
case confv1a1.Partial:
204+
message = fmt.Sprintf("partially succeeded with %d test skips", status.Statistics.Skipped)
205+
case confv1a1.Failure:
206+
message = fmt.Sprintf("failed with %d test failures", status.Statistics.Failed)
207+
}
208+
return message
209+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
Copyright 2024 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 suite
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
24+
confv1a1 "sigs.k8s.io/gateway-api/conformance/apis/v1alpha1"
25+
)
26+
27+
func TestBuildSummary(t *testing.T) {
28+
testCases := []struct {
29+
name string
30+
report confv1a1.ProfileReport
31+
expectedSummary string
32+
}{
33+
{
34+
name: "core tests failed, no extended tests",
35+
report: confv1a1.ProfileReport{
36+
Name: string(HTTPConformanceProfileName),
37+
Core: confv1a1.Status{
38+
Result: confv1a1.Failure,
39+
Statistics: confv1a1.Statistics{
40+
Passed: 5,
41+
Failed: 3,
42+
},
43+
},
44+
},
45+
expectedSummary: "Core tests failed with 3 test failures.",
46+
},
47+
{
48+
name: "core tests succeeded, extended tests failed",
49+
report: confv1a1.ProfileReport{
50+
Name: string(HTTPConformanceProfileName),
51+
Core: confv1a1.Status{
52+
Result: confv1a1.Success,
53+
Statistics: confv1a1.Statistics{
54+
Passed: 8,
55+
},
56+
},
57+
Extended: &confv1a1.ExtendedStatus{
58+
Status: confv1a1.Status{
59+
Result: confv1a1.Failure,
60+
Statistics: confv1a1.Statistics{
61+
Passed: 2,
62+
Failed: 1,
63+
},
64+
},
65+
},
66+
},
67+
expectedSummary: "Core tests succeeded. Extended tests failed with 1 test failures.",
68+
},
69+
{
70+
name: "core tests partially succeeded, extended tests succeeded",
71+
report: confv1a1.ProfileReport{
72+
Name: string(HTTPConformanceProfileName),
73+
Core: confv1a1.Status{
74+
Result: confv1a1.Partial,
75+
Statistics: confv1a1.Statistics{
76+
Passed: 6,
77+
Skipped: 2,
78+
},
79+
},
80+
Extended: &confv1a1.ExtendedStatus{
81+
Status: confv1a1.Status{
82+
Result: confv1a1.Success,
83+
Statistics: confv1a1.Statistics{
84+
Passed: 2,
85+
},
86+
},
87+
},
88+
},
89+
expectedSummary: "Core tests partially succeeded with 2 test skips. Extended tests succeeded.",
90+
},
91+
{
92+
name: "core tests succeeded, extended tests partially succeeded",
93+
report: confv1a1.ProfileReport{
94+
Name: string(HTTPConformanceProfileName),
95+
Core: confv1a1.Status{
96+
Result: confv1a1.Success,
97+
Statistics: confv1a1.Statistics{
98+
Passed: 8,
99+
},
100+
},
101+
Extended: &confv1a1.ExtendedStatus{
102+
Status: confv1a1.Status{
103+
Result: confv1a1.Partial,
104+
Statistics: confv1a1.Statistics{
105+
Passed: 2,
106+
Skipped: 1,
107+
},
108+
},
109+
},
110+
},
111+
expectedSummary: "Core tests succeeded. Extended tests partially succeeded with 1 test skips.",
112+
},
113+
}
114+
115+
for _, tc := range testCases {
116+
t.Run(tc.name, func(t *testing.T) {
117+
tc := tc
118+
summary := buildSummary(tc.report)
119+
require.Equal(t, tc.expectedSummary, summary)
120+
})
121+
}
122+
}

0 commit comments

Comments
 (0)