Skip to content

Commit d0e2f9a

Browse files
committed
Add option to ignore whitespace in the resposnse header values
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
1 parent 33ed80c commit d0e2f9a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

conformance/tests/httproute-cors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var HTTPRouteCORS = suite.ConformanceTest{
8484
"access-control-max-age": "3600",
8585
"access-control-allow-credentials": "true",
8686
},
87+
IgnoreWhitespace: true,
8788
},
8889
},
8990
{
@@ -120,6 +121,7 @@ var HTTPRouteCORS = suite.ConformanceTest{
120121
"access-control-max-age": "3600",
121122
"access-control-allow-credentials": "true",
122123
},
124+
IgnoreWhitespace: true,
123125
},
124126
},
125127
{

conformance/utils/http/http.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ type ExpectedRequest struct {
8383

8484
// Response defines expected properties of a response from a backend.
8585
type Response struct {
86-
StatusCode int
87-
Headers map[string]string
88-
AbsentHeaders []string
86+
StatusCode int
87+
Headers map[string]string
88+
AbsentHeaders []string
89+
90+
// IgnoreWhitespace will cause whitespace to be ignored when comparing the respond
91+
// header values.
92+
IgnoreWhitespace bool
8993
}
9094

9195
type BackendRef struct {
@@ -314,8 +318,14 @@ func CompareRequest(t *testing.T, req *roundtripper.Request, cReq *roundtripper.
314318
actualVal, ok := cRes.Headers[strings.ToLower(name)]
315319
if !ok {
316320
return fmt.Errorf("expected %s header to be set, actual headers: %v", name, cRes.Headers)
317-
} else if strings.Join(actualVal, ",") != expectedVal {
318-
return fmt.Errorf("expected %s header to be set to %s, got %s", name, expectedVal, strings.Join(actualVal, ","))
321+
}
322+
actualValStr := strings.Join(actualVal, ",")
323+
if expected.Response.IgnoreWhitespace {
324+
actualValStr = strings.ReplaceAll(actualValStr, " ", "")
325+
expectedVal = strings.ReplaceAll(expectedVal, " ", "")
326+
}
327+
if actualValStr != expectedVal {
328+
return fmt.Errorf("expected %s header to be set to %s, got %s", name, expectedVal, actualValStr)
319329
}
320330
}
321331
}

0 commit comments

Comments
 (0)