Fixes HTTP header compare by including standard headers.

This commit is contained in:
James Phillips 2017-06-08 10:24:50 -07:00
parent 17051c6870
commit a7c910be7c
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
1 changed files with 13 additions and 2 deletions

View File

@ -208,7 +208,7 @@ func TestCheckHTTP(t *testing.T) {
// custom method
{desc: "custom method GET", code: 200, method: "GET", status: api.HealthPassing},
{desc: "custom method POST", code: 200, method: "POST", status: api.HealthPassing},
{desc: "custom method POST", code: 200, header: http.Header{"Content-Length": []string{"0"}}, method: "POST", status: api.HealthPassing},
{desc: "custom method abc", code: 200, method: "abc", status: api.HealthPassing},
// custom header
@ -226,10 +226,21 @@ func TestCheckHTTP(t *testing.T) {
w.WriteHeader(999)
return
}
if len(tt.header) > 0 && !reflect.DeepEqual(tt.header, r.Header) {
expectedHeader := http.Header{
"Accept": []string{"text/plain, text/*, */*"},
"Accept-Encoding": []string{"gzip"},
"Connection": []string{"close"},
"User-Agent": []string{"Consul Health Check"},
}
for k, v := range tt.header {
expectedHeader[k] = v
}
if !reflect.DeepEqual(expectedHeader, r.Header) {
w.WriteHeader(999)
return
}
// Body larger than 4k limit
body := bytes.Repeat([]byte{'a'}, 2*CheckBufSize)
w.WriteHeader(tt.code)