Skip to content

Commit 66ee517

Browse files
committed
Rectified Conformance Test Name Generation
Rectified Conformance Test Name Generation Rectified Conformance Test Name Generation
1 parent 0c923e3 commit 66ee517

9 files changed

+35
-19
lines changed

conformance/tests/httproute-exact-path-matching.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var HTTPExactPathMatching = suite.ConformanceTest{
6565
// Declare tc here to avoid loop variable
6666
// reuse issues across parallel tests.
6767
tc := testCases[i]
68-
t.Run(testName(tc, i), func(t *testing.T) {
68+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
6969
t.Parallel()
7070
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
7171
})

conformance/tests/httproute-header-matching.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var HTTPRouteHeaderMatching = suite.ConformanceTest{
8383
// Declare tc here to avoid loop variable
8484
// reuse issues across parallel tests.
8585
tc := testCases[i]
86-
t.Run(testName(tc, i), func(t *testing.T) {
86+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
8787
t.Parallel()
8888
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
8989
})

conformance/tests/httproute-hostname-intersection.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ var HTTPRouteHostnameIntersection = suite.ConformanceTest{
181181
// Declare tc here to avoid loop variable
182182
// reuse issues across parallel tests.
183183
tc := testCases[i]
184-
t.Run(testName(tc, i), func(t *testing.T) {
184+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
185185
t.Parallel()
186186
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
187187
})
@@ -221,7 +221,7 @@ var HTTPRouteHostnameIntersection = suite.ConformanceTest{
221221
// Declare tc here to avoid loop variable
222222
// reuse issues across parallel tests.
223223
tc := testCases[i]
224-
t.Run(testName(tc, i), func(t *testing.T) {
224+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
225225
t.Parallel()
226226
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
227227
})

conformance/tests/httproute-listener-hostname-matching.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var HTTPRouteListenerHostnameMatching = suite.ConformanceTest{
8989
// Declare tc here to avoid loop variable
9090
// reuse issues across parallel tests.
9191
tc := testCases[i]
92-
t.Run(testName(tc, i), func(t *testing.T) {
92+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
9393
t.Parallel()
9494
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
9595
})

conformance/tests/httproute-matching-across-routes.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package tests
1818

1919
import (
20-
"fmt"
2120
"testing"
2221

2322
"k8s.io/apimachinery/pkg/types"
@@ -107,19 +106,10 @@ var HTTPRouteMatchingAcrossRoutes = suite.ConformanceTest{
107106
// Declare tc here to avoid loop variable
108107
// reuse issues across parallel tests.
109108
tc := testCases[i]
110-
t.Run(testName(tc, i), func(t *testing.T) {
109+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
111110
t.Parallel()
112111
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
113112
})
114113
}
115114
},
116115
}
117-
118-
func testName(tc http.ExpectedResponse, i int) string {
119-
headerStr := ""
120-
if tc.Request.Headers != nil {
121-
headerStr = " with headers"
122-
}
123-
124-
return fmt.Sprintf("%d request to %s%s%s should go to %s", i, tc.Request.Host, tc.Request.Path, headerStr, tc.Backend)
125-
}

conformance/tests/httproute-matching.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var HTTPRouteMatching = suite.ConformanceTest{
7070
// Declare tc here to avoid loop variable
7171
// reuse issues across parallel tests.
7272
tc := testCases[i]
73-
t.Run(testName(tc, i), func(t *testing.T) {
73+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
7474
t.Parallel()
7575
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
7676
})

conformance/tests/httproute-query-param-matching.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var HTTPRouteQueryParamMatching = suite.ConformanceTest{
8383

8484
for i := range testCases {
8585
tc := testCases[i]
86-
t.Run(testName(tc, i), func(t *testing.T) {
86+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
8787
t.Parallel()
8888
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
8989
})

conformance/tests/httproute-request-header-modifier.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ var HTTPRouteRequestHeaderModifier = suite.ConformanceTest{
185185
// Declare tc here to avoid loop variable
186186
// reuse issues across parallel tests.
187187
tc := testCases[i]
188-
t.Run(testName(tc, i), func(t *testing.T) {
188+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
189189
t.Parallel()
190190
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, tc)
191191
})

conformance/utils/http/http.go

+26
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type ExpectedResponse struct {
4040
StatusCode int
4141
Backend string
4242
Namespace string
43+
44+
// User Given TestCase name
45+
TestCaseName string
4346
}
4447

4548
// Request can be used as both the request to make and a means to verify
@@ -229,3 +232,26 @@ func CompareRequest(cReq *roundtripper.CapturedRequest, cRes *roundtripper.Captu
229232
}
230233
return nil
231234
}
235+
236+
// Get User-defined test case name or generate from expected response to a given request.
237+
func (er *ExpectedResponse) GetTestCaseName(i int) string {
238+
239+
// If TestCase name is provided then use that or else generate one.
240+
if er.TestCaseName != "" {
241+
return er.TestCaseName
242+
}
243+
244+
headerStr := ""
245+
reqStr := ""
246+
247+
if er.Request.Headers != nil {
248+
headerStr = " with headers"
249+
}
250+
251+
reqStr = fmt.Sprintf("%d request to '%s%s'%s", i, er.Request.Host, er.Request.Path, headerStr)
252+
253+
if er.Backend != "" {
254+
return fmt.Sprintf("%s should go to %s", reqStr, er.Backend)
255+
}
256+
return fmt.Sprintf("%s should receive a %d", reqStr, er.StatusCode)
257+
}

0 commit comments

Comments
 (0)