-
Notifications
You must be signed in to change notification settings - Fork 7
/
template_test.go
46 lines (42 loc) · 957 Bytes
/
template_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
package gin
import (
"os"
"testing"
"github.com/goravel/framework/support/file"
"github.com/stretchr/testify/assert"
)
func TestNewTemplate(t *testing.T) {
tests := []struct {
name string
setup func()
expectError error
expectRender bool
}{
{
name: "resources/views directory not found",
setup: func() {},
},
{
name: "resources/views directory is empty",
setup: func() {
assert.Nil(t, os.MkdirAll("resources/views", os.ModePerm))
},
},
{
name: "resources/views directory is not empty",
setup: func() {
assert.Nil(t, file.Create("resources/views/index.html", "Hello, World!"))
},
expectRender: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test.setup()
r, err := NewTemplate(RenderOptions{})
assert.Equal(t, test.expectRender, r != nil)
assert.Equal(t, test.expectError, err)
assert.Nil(t, file.Remove("resources"))
})
}
}