This repository was archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgonocular_test.go
More file actions
80 lines (77 loc) · 2.49 KB
/
gonocular_test.go
File metadata and controls
80 lines (77 loc) · 2.49 KB
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
package gonocular
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestComposingViews(t *testing.T) {
Convey("When composing views", t, func() {
Convey("During dev mode", func() {
DevMode()
Convey("With template parse errors", func() {
template := TemplateFiles("fortests/error.html").Template()
rw := httptest.NewRecorder()
template.RenderHTML(rw, nil)
Convey("Error page should include template source", func() {
body := rw.Body.String()
containsSource := strings.Contains(body, "{{ blah() }}")
So(containsSource, ShouldBeTrue)
})
Convey("Content-Type should be text/html", func() {
contentType := rw.Header().Get("Content-Type")
So(contentType, ShouldEqual, "text/html")
})
Convey("Status is 500 InternalServerError", func() {
So(rw.Code, ShouldEqual, http.StatusInternalServerError)
})
})
Convey("Without template parse errors", func() {
template := TemplateFiles("fortests/noerror.html").Template()
rw := httptest.NewRecorder()
template.RenderHTML(rw, nil)
Convey("Page should render content", func() {
body := rw.Body.String()
containsSource := strings.Contains(body, "<h1>Hello World!</h1>")
So(containsSource, ShouldBeTrue)
})
Convey("Content-Type should be text/html", func() {
contentType := rw.Header().Get("Content-Type")
So(contentType, ShouldEqual, "text/html")
})
Convey("Status is 200 OK", func() {
So(rw.Code, ShouldEqual, http.StatusOK)
})
})
})
Convey("During production mode", func() {
ProductionMode()
Convey("With template parse errors", func() {
Convey("Getting the template should panic", func() {
templateFunc := func() {
TemplateFiles("fortests/error.html").Template()
}
So(templateFunc, ShouldPanic)
})
})
Convey("Without template parse errors", func() {
template := TemplateFiles("fortests/noerror.html").Template()
rw := httptest.NewRecorder()
template.RenderHTML(rw, nil)
Convey("Page should render content", func() {
body := rw.Body.String()
containsSource := strings.Contains(body, "<h1>Hello World!</h1>")
So(containsSource, ShouldBeTrue)
})
Convey("Content-Type should be text/html", func() {
contentType := rw.Header().Get("Content-Type")
So(contentType, ShouldEqual, "text/html")
})
Convey("Status is 200 OK", func() {
So(rw.Code, ShouldEqual, http.StatusOK)
})
})
})
})
}