parent
da5806a6f7
commit
f9c74a83f0
33
views_test.go
Normal file
33
views_test.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package rushlink
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resolveResponseContentTypeSuccess(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("error: '%v'\n", err)
|
||||||
|
}
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("error: '%v' should be '%v'\n", got, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveResponseContentType(t *testing.T) {
|
||||||
|
resolveResponseContentTypeSuccess(t, "", []string{}, "text/html")
|
||||||
|
resolveResponseContentTypeSuccess(t, "text/html", []string{"text/html"}, "")
|
||||||
|
resolveResponseContentTypeSuccess(t, "text/html", []string{"text/txt", "text/html"}, "text/txt;q=0.5,text/html")
|
||||||
|
resolveResponseContentTypeSuccess(t, "text/html", []string{"text/txt", "text/html"}, "text/txt;q=0.5,text/html;q=0.9")
|
||||||
|
resolveResponseContentTypeSuccess(t, "", []string{"text"}, "text/html")
|
||||||
|
resolveResponseContentTypeSuccess(t, "", []string{"text/*"}, "image/*")
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user