@@ -83,9 +83,13 @@ type ExpectedRequest struct {
8383
8484// Response defines expected properties of a response from a backend.
8585type 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
9195type 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