-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrender_test.go
115 lines (94 loc) · 2.16 KB
/
render_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package abcrender
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/unrolled/render"
)
func TestNew(t *testing.T) {
t.Parallel()
o := New(render.Options{IsDevelopment: true}, map[string]string{"test": "test"})
if o == nil {
t.Error("did not expect nil")
}
if o.(*Render).assetsManifest["test"] != "test" {
t.Error("expected test key to have value test")
}
}
func TestGetManifest(t *testing.T) {
t.Parallel()
json := `{"a": "b"}`
_, err := GetManifest("zxovasgfju")
if err == nil {
t.Error("expected error, got nil")
}
dir, err := ioutil.TempDir("", "manifesttest")
if err != nil {
t.Error(err)
}
defer os.RemoveAll(dir)
err = os.Mkdir(filepath.Join(dir, "assets"), 0755)
if err != nil {
t.Error(err)
}
err = ioutil.WriteFile(filepath.Join(dir, "assets", "manifest.json"), []byte(json), 0755)
if err != nil {
t.Error(err)
}
m, err := GetManifest(dir)
if err != nil {
t.Error(err)
}
if m["a"] != "b" {
t.Errorf("expected m[a] to be b, got %#v", m)
}
if len(m) != 1 {
t.Errorf("expected len of m to be 1, got %d", len(m))
}
}
func TestAppHelpers(t *testing.T) {
t.Parallel()
fnmap := AppHelpers(map[string]string{"css/a": "css/a123"})
if len(fnmap) == 0 {
t.Error("expected funcmap to be returned, got len 0")
}
// test asset serving from manifest
r := fnmap["cssPath"].(func(string) string)("a")
if r != "/assets/css/a123" {
t.Errorf("mismatch, got %s", r)
}
// test asset serving without manifest
r = fnmap["cssPath"].(func(string) string)("b")
if r != "/assets/css/b" {
t.Errorf("mismatch, got %s", r)
}
}
func TestLiveReloadHelper(t *testing.T) {
t.Parallel()
x := liveReloadHelper("path", "123")
if x != "/assets/js/path?host=123" {
t.Error("mismatch, got:", x)
}
}
func TestCSSTag(t *testing.T) {
t.Parallel()
x := cssTag("path")
if x != "<link href=\"path\" rel=\"stylesheet\">" {
t.Error("mismatch, got:", x)
}
}
func TestJSTag(t *testing.T) {
t.Parallel()
x := jsTag("path")
if x != "<script src=\"path\"></script>" {
t.Error("mismatch, got:", x)
}
}
func TestJSBootstrap(t *testing.T) {
t.Parallel()
x := jsBootstrap()
if len(x) == 0 {
t.Error("expected contents back")
}
}