-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresources_test.go
101 lines (76 loc) · 1.99 KB
/
resources_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
package main
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/gobuffalo/packr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReadContractFile(t *testing.T) {
// We embed the file now
box := packr.NewBox("./files")
cntrs, err := readContractFile(box)
assert.NoError(t, err)
assert.NotEmpty(t, cntrs)
}
func TestLoadTemplates(t *testing.T) {
// We embed the file now
box := packr.NewBox("./files")
str, err := loadTemplates(box)
assert.NoError(t, err)
assert.NotEmpty(t, str)
assert.Equal(t, 2, len(str))
}
func TestLoadTemplates_None(t *testing.T) {
box := packr.NewBox("/nonexistent")
require.NotNil(t, box)
tmpls, err := loadTemplates(box)
require.Error(t, err)
assert.Empty(t, tmpls)
}
func TestLoadTemplates_Empty(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "loadResources")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)
box := packr.NewBox(tmpdir)
require.NotNil(t, box)
tmpls, err := loadTemplates(box)
require.NoError(t, err)
assert.NotNil(t, tmpls)
assert.Empty(t, tmpls)
}
func TestLoadTemplates_Good(t *testing.T) {
box := packr.NewBox("./files")
tmpls, err := loadTemplates(box)
require.NoError(t, err)
assert.NotNil(t, tmpls)
assert.NotEmpty(t, tmpls)
fl, err := filepath.Glob("files/*.html")
require.NoError(t, err)
assert.Equal(t, len(fl), len(tmpls))
assert.NotEmpty(t, tmpls["templ.html"])
assert.NotEmpty(t, tmpls["summaries.html"])
}
func TestLoadTemplates_GoodDebug(t *testing.T) {
fDebug = true
box := packr.NewBox("./files")
tmpls, err := loadTemplates(box)
require.NoError(t, err)
assert.NotNil(t, tmpls)
assert.NotEmpty(t, tmpls)
fDebug = false
}
func TestLoadResources_GoodDebug(t *testing.T) {
err := loadResources(resourcesPath)
assert.NoError(t, err)
assert.NotEmpty(t, tmpls)
assert.NotEmpty(t, contracts)
}
func TestLoadResources_None(t *testing.T) {
err := loadResources("/nonexistent")
assert.Error(t, err)
assert.Empty(t, tmpls)
assert.Empty(t, contracts)
}