Skip to content

Commit d8212e6

Browse files
committed
Issue #1579 TLSRoute Passthrough - PR review update
1 parent 1d54add commit d8212e6

File tree

6 files changed

+39
-50
lines changed

6 files changed

+39
-50
lines changed

conformance/conformance_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,24 @@ func TestConformance(t *testing.T) {
4949
for feature := range exemptFeatures {
5050
supportedFeatures[feature] = false
5151
}
52-
t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n supported features: [%v]\n exempt features: [%v]",
53-
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.SupportedFeatures, *flags.ExemptFeatures)
52+
53+
// Check if this should be a single test run
54+
if *flags.RunOneTest != "" {
55+
saved := []suite.ConformanceTest{}
56+
for _, ctest := range tests.ConformanceTests {
57+
if ctest.ShortName == *flags.RunOneTest {
58+
saved = append(saved, ctest)
59+
break
60+
}
61+
}
62+
tests.ConformanceTests = saved
63+
if len(saved) == 0 {
64+
t.Fatalf("error, no such test: %s", *flags.RunOneTest)
65+
}
66+
}
67+
68+
t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n supported features: [%v]\n exempt features: [%v]\n run one test: %s",
69+
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.SupportedFeatures, *flags.ExemptFeatures, *flags.RunOneTest)
5470

5571
cSuite := suite.New(suite.Options{
5672
Client: client,

conformance/tests/tlsroute-simple-same-namespace.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ var TLSRouteSimpleSameNamespace = suite.ConformanceTest{
4848
gwNN := types.NamespacedName{Name: "gateway-tlsroute", Namespace: string(ns)}
4949
certNN := types.NamespacedName{Name: "tls-passthrough-checks-certificate", Namespace: string(ns)}
5050

51-
gwAddr, server := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
52-
if len(server) != 1 {
53-
fmt.Errorf("one and only one server required for TLS")
51+
gwAddr, hostnames := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
52+
if len(hostnames) != 1 {
53+
t.Fatalf("unexpected error in test configuration, found %d hostnames", len(hostnames))
5454
}
55-
serverStr := string(server[0])
55+
serverStr := string(hostnames[0])
5656

5757
cPem, kPem, err := GetTLSSecret(suite.Client, certNN)
5858
if err != nil {
59-
fmt.Errorf("unexpected error finding TLS secret: %w", err)
59+
t.Fatalf("unexpected error finding TLS secret: %v", err)
6060
}
61-
62-
t.Run("Simple HTTP request for TLSRoute should reach infra-backend", func(t *testing.T) {
61+
t.Run("Simple TLS request matching TLSRoute should reach infra-backend", func(t *testing.T) {
6362
tls.MakeTLSRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, cPem, kPem, serverStr,
6463
http.ExpectedResponse{
6564
Request: http.Request{Host: serverStr, Path: "/"},

conformance/tests/tlsroute-simple-same-namespace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ spec:
3232
kinds:
3333
- kind: TLSRoute
3434
tls:
35-
mode: Passthrough
35+
mode: Passthrough

conformance/utils/flags/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ var (
2929
CleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run")
3030
SupportedFeatures = flag.String("supported-features", "", "Supported features included in conformance tests suites")
3131
ExemptFeatures = flag.String("exempt-features", "", "Exempt Features excluded from conformance tests suites")
32+
RunOneTest = flag.String("test", "", "A single test name when you want to run only one")
3233
)

conformance/utils/http/http.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ const requiredConsecutiveSuccesses = 3
9393
func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripper.RoundTripper, timeoutConfig config.TimeoutConfig, gwAddr string, expected ExpectedResponse) {
9494
t.Helper()
9595

96+
req := MakeRequest(t, &expected, gwAddr, "HTTP", "http")
97+
98+
WaitForConsistentResponse(t, r, req, expected, requiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency)
99+
}
100+
101+
func MakeRequest(t *testing.T, expected *ExpectedResponse, gwAddr, protocol, scheme string) roundtripper.Request {
102+
t.Helper()
103+
96104
if expected.Request.Method == "" {
97105
expected.Request.Method = "GET"
98106
}
@@ -101,15 +109,15 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp
101109
expected.Response.StatusCode = 200
102110
}
103111

104-
t.Logf("Making %s request to http://%s%s", expected.Request.Method, gwAddr, expected.Request.Path)
112+
t.Logf("Making %s request to %s://%s%s", expected.Request.Method, scheme, gwAddr, expected.Request.Path)
105113

106114
path, query, _ := strings.Cut(expected.Request.Path, "?")
107115

108116
req := roundtripper.Request{
109117
Method: expected.Request.Method,
110118
Host: expected.Request.Host,
111-
URL: url.URL{Scheme: "http", Host: gwAddr, Path: path, RawQuery: query},
112-
Protocol: "HTTP",
119+
URL: url.URL{Scheme: scheme, Host: gwAddr, Path: path, RawQuery: query},
120+
Protocol: protocol,
113121
Headers: map[string][]string{},
114122
}
115123

@@ -125,7 +133,7 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp
125133
}
126134
req.Headers["X-Echo-Set-Header"] = []string{strings.Join(backendSetHeaders, ",")}
127135

128-
WaitForConsistentResponse(t, r, req, expected, requiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency)
136+
return req
129137
}
130138

131139
// AwaitConvergence runs the given function until it returns 'true' `threshold` times in a row.

conformance/utils/tls/tls.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package tls
1818

1919
import (
20-
"net/url"
21-
"strings"
2220
"testing"
2321
"time"
2422

@@ -41,40 +39,7 @@ const requiredConsecutiveSuccesses = 3
4139
func MakeTLSRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripper.RoundTripper, timeoutConfig config.TimeoutConfig, gwAddr string, cPem, kPem []byte, server string, expected http.ExpectedResponse) {
4240
t.Helper()
4341

44-
protocol := "HTTPS"
45-
scheme := "https"
46-
47-
if expected.Request.Method == "" {
48-
expected.Request.Method = "GET"
49-
}
50-
51-
if expected.Response.StatusCode == 0 {
52-
expected.Response.StatusCode = 200
53-
}
54-
55-
t.Logf("Making %s request to %s://%s%s", expected.Request.Method, scheme, gwAddr, expected.Request.Path)
56-
57-
path, query, _ := strings.Cut(expected.Request.Path, "?")
58-
59-
req := roundtripper.Request{
60-
Method: expected.Request.Method,
61-
Host: expected.Request.Host,
62-
URL: url.URL{Scheme: scheme, Host: gwAddr, Path: path, RawQuery: query},
63-
Protocol: protocol,
64-
Headers: map[string][]string{},
65-
}
66-
67-
if expected.Request.Headers != nil {
68-
for name, value := range expected.Request.Headers {
69-
req.Headers[name] = []string{value}
70-
}
71-
}
72-
73-
backendSetHeaders := []string{}
74-
for name, val := range expected.BackendSetResponseHeaders {
75-
backendSetHeaders = append(backendSetHeaders, name+":"+val)
76-
}
77-
req.Headers["X-Echo-Set-Header"] = []string{strings.Join(backendSetHeaders, ",")}
42+
req := http.MakeRequest(t, &expected, gwAddr, "HTTPS", "https")
7843

7944
WaitForConsistentTLSResponse(t, r, req, expected, requiredConsecutiveSuccesses, timeoutConfig.MaxTimeToConsistency, cPem, kPem, server)
8045
}

0 commit comments

Comments
 (0)