-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponse_test.go
83 lines (70 loc) · 1.83 KB
/
response_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package crater
import "testing"
func TestRender(t *testing.T) {
res := &Response{}
res.Render("viewName", new(interface{}))
if res.viewName != "viewName" {
t.Error("viewName was not set correctly")
}
if res.model == nil {
t.Error("model was not set correctly")
}
if res.responseType != response_view {
t.Error("response type should be 'html'")
}
}
func TestRenderTemplate(t *testing.T) {
res := &Response{}
res.RenderTemplate("templateName", new(interface{}))
if res.templateName != "templateName" {
t.Error("templateName was not set correctly")
}
if res.model == nil {
t.Error("model was not set correctly")
}
if res.responseType != response_template {
t.Error("response type should be 'template'")
}
}
func TestJson(t *testing.T) {
res := &Response{}
res.Json(new(interface{}))
if res.model == nil {
t.Error("model was not set correctly")
}
if res.responseType != response_json {
t.Error("response type should be 'json'")
}
}
func TestRedirect(t *testing.T) {
res := &Response{}
res.Redirect("redirectUrl")
if res.redirectUrl != "redirectUrl" {
t.Error("redirectUrl was not set correctly")
}
if res.responseType != response_redirect {
t.Error("response type should be 'redirect'")
}
}
func TestSend(t *testing.T) {
res := &Response{}
htmlString := "<h1>text</h1>"
res.Send(htmlString)
if res.responseString != htmlString {
t.Error("html was not set correctly")
}
if res.responseType != response_string {
t.Error("response type should be 'string'")
}
}
func TestResponse_CallTwoTimes_ShouldHaveLatestCallValues(t *testing.T) {
res := &Response{}
res.Render("viewName", new(interface{}))
res.Redirect("redirectUrl")
if res.redirectUrl != "redirectUrl" {
t.Error("redirectUrl was not set correctly")
}
if res.responseType != response_redirect {
t.Error("response type should be 'redirect'")
}
}