forked from verless/verless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpl_test.go
More file actions
73 lines (62 loc) · 1.65 KB
/
tpl_test.go
File metadata and controls
73 lines (62 loc) · 1.65 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
package tpl
import (
"path/filepath"
"testing"
"text/template"
"github.com/verless/verless/test"
"github.com/verless/verless/theme"
)
const (
projectPath = "../example"
testKey = "test key"
invalidKey = "invalid key"
)
// TestRegister checks if the Register function register all templates
// correctly and if it doesn't allow overwriting a template by default.
func TestRegister(t *testing.T) {
// Don't use a map as the execution order is important here.
tests := []struct {
testName string
force bool
expectedError error
key string
}{
{
testName: "first template",
key: "test key",
},
{
testName: "second template",
key: "test key2",
},
{
testName: "same template again",
key: "test key2",
expectedError: ErrAlreadyRegistered,
},
{
testName: "same template again with force true",
key: "test key2",
force: true,
},
}
for _, testCase := range tests {
t.Logf("Testing '%s'", testCase.testName)
pageTplPath := filepath.Join(theme.TemplatePath(projectPath, theme.Default), theme.PageTemplate)
_, err := Register(testCase.key, pageTplPath, testCase.force)
test.ExpectedError(t, testCase.expectedError, err)
}
}
// TestGet checks if the Get function correctly returns a registered
// template.
func TestGet(t *testing.T) {
if templates == nil {
templates = make(map[string]*template.Template)
}
templates[testKey] = &template.Template{}
tpl, err := Get(testKey)
test.Ok(t, err)
test.Assert(t, tpl == templates[testKey], "template has to be in map")
_, err = Get(invalidKey)
test.Assert(t, err != nil, "template key is invalid")
}