@@ -83,9 +83,13 @@ type ExpectedRequest struct {
83
83
84
84
// Response defines expected properties of a response from a backend.
85
85
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
89
93
}
90
94
91
95
type BackendRef struct {
@@ -314,8 +318,14 @@ func CompareRequest(t *testing.T, req *roundtripper.Request, cReq *roundtripper.
314
318
actualVal , ok := cRes .Headers [strings .ToLower (name )]
315
319
if ! ok {
316
320
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 )
319
329
}
320
330
}
321
331
}
0 commit comments