forked from qor/responder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responder_test.go
42 lines (36 loc) · 954 Bytes
/
responder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package responder_test
import (
"net/http"
"testing"
"github.com/qorx/responder"
)
func checkRespond(request *http.Request, format string, t *testing.T) {
responder.With("html", func() {
if format != "html" {
t.Errorf("Should call %v, but called html", format)
}
}).With("json", func() {
if format != "json" {
t.Errorf("Should call %v, but called json", format)
}
}).With("xml", func() {
if format != "xml" {
t.Errorf("Should call %v, but called xml", format)
}
}).Respond(request)
}
func newRequestWithAcceptType(acceptType string) *http.Request {
request, _ := http.NewRequest("GET", "", nil)
request.Header.Add("Accept", acceptType)
return request
}
func TestRespond(t *testing.T) {
mimeMap := map[string]string{
"text/html": "html",
"application/json": "json",
"application/xml": "xml",
}
for mimeType, format := range mimeMap {
checkRespond(newRequestWithAcceptType(mimeType), format, t)
}
}