|
|
|
@ -20,6 +20,24 @@ func resolveResponseContentTypeSuccess(t *testing.T, expected string, types []st
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func resolveResponseContentTypeError(t *testing.T, expected string, types []string, acceptVal string) {
|
|
|
|
|
r, err := http.NewRequest("HEAD", "", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
r.Header.Set("Accept", acceptVal)
|
|
|
|
|
got, err := resolveResponseContentType(r, types)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Errorf("expected an error, but got a success: '%v'", got)
|
|
|
|
|
}
|
|
|
|
|
if got != "" {
|
|
|
|
|
t.Errorf("error: return value should be empty, not '%v'", got)
|
|
|
|
|
}
|
|
|
|
|
if err.Error() != expected {
|
|
|
|
|
t.Errorf("wrong error value error: got '%v', want '%v'\n", got, expected)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestResolveResponseContentType(t *testing.T) {
|
|
|
|
|
resolveResponseContentTypeSuccess(t, "", []string{}, "text/html")
|
|
|
|
|
resolveResponseContentTypeSuccess(t, "text/html", []string{"text/html"}, "")
|
|
|
|
@ -30,4 +48,7 @@ func TestResolveResponseContentType(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Issue #17
|
|
|
|
|
resolveResponseContentTypeSuccess(t, "*/*", []string{"*/*"}, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
|
|
|
|
|
|
|
|
|
// Issue #66
|
|
|
|
|
resolveResponseContentTypeError(t, "bad media-range ('*')", []string{"text/plain"}, " *")
|
|
|
|
|
}
|
|
|
|
|