-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig_test.go
62 lines (50 loc) · 1.31 KB
/
config_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
package hime
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConfig(t *testing.T) {
t.Parallel()
t.Run("Config1", func(t *testing.T) {
assert.NotPanics(t, func() {
app := New()
app.ParseConfigFile("testdata/config1.yaml")
// globals
assert.Equal(t, mapLen(&app.globals), 1)
assert.Equal(t, app.Global("data1"), "test")
assert.Nil(t, app.Global("invalid"))
// routes
assert.Len(t, app.routes, 2)
assert.Equal(t, app.Route("index"), "/")
assert.Equal(t, app.Route("about"), "/about")
// templates
assert.Len(t, app.template, 2)
assert.Contains(t, app.template, "main")
assert.Contains(t, app.template, "main2")
})
})
t.Run("Config2", func(t *testing.T) {
assert.NotPanics(t, func() {
app := New()
app.ParseConfigFile("testdata/config2.yaml")
assert.Equal(t, mapLen(&app.globals), 0)
assert.Len(t, app.routes, 0)
assert.Len(t, app.template, 0)
})
})
t.Run("ConfigNotFound", func(t *testing.T) {
assert.Panics(t, func() {
New().ParseConfigFile("testdata/notexists.yaml")
})
})
t.Run("Invalid1", func(t *testing.T) {
assert.Panics(t, func() {
New().ParseConfigFile("testdata/invalid1.yaml")
})
})
t.Run("Invalid2", func(t *testing.T) {
assert.Panics(t, func() {
New().ParseConfigFile("testdata/invalid2.yaml")
})
})
}