This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuncregistry_test.go
89 lines (82 loc) · 2.18 KB
/
funcregistry_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
package template
import (
"strings"
"testing"
)
func TestIsSet(t *testing.T) {
data := make(map[string]interface{})
data["test"] = "testValue"
funcs := &FuncRegistry{TemplateData: data}
ok := funcs.isSet("test")
if !ok {
t.Error("expected true but got false")
}
ok = funcs.isSet("testFalse")
if ok {
t.Error("expected false but got true")
}
}
func TestDefaultOrValue(t *testing.T) {
data := make(map[string]interface{})
data["test"] = "testValue"
funcs := &FuncRegistry{TemplateData: data}
value := funcs.defaultOrValue("test", "testDefault")
if value != "testValue" {
t.Errorf("expected 'testValue' but got %s", value)
}
value = funcs.defaultOrValue("testDefaultValue", "testDefault")
if value != "testDefault" {
t.Errorf("expected 'testDefault' but got %s", value)
}
}
func TestInFormat(t *testing.T) {
data := make(map[string]interface{})
data["test"] = []string{"test1", "test2"}
funcs := &FuncRegistry{TemplateData: data}
query := funcs.inFormat("test")
if query != "('test1', 'test2')" {
t.Errorf("expected ('test1', 'test2'), but got %s", query)
}
data["test"] = "test1"
funcs = &FuncRegistry{TemplateData: data}
query = funcs.inFormat("test")
if query != "('test1')" {
t.Errorf("expected ('test1'), but got %s", query)
}
}
func TestSplit(t *testing.T) {
data := make(map[string]interface{})
list3itens := "test1,test2,test3"
data["list3itens"] = list3itens
funcs := &FuncRegistry{TemplateData: data}
query := funcs.split(list3itens, ",")
s := strings.Split(list3itens, ",")
if len(query) != 3 {
t.Errorf("expected (3), but got %d", len(query))
}
if len(query) != len(s) {
t.Errorf("expected (%d), but got %d", len(query), len(s))
}
}
func TestRegistryAllFuncs(t *testing.T) {
data := make(map[string]interface{})
data["test"] = "testValue"
funcs := &FuncRegistry{TemplateData: data}
fmap := funcs.RegistryAllFuncs()
_, ok := fmap["isSet"]
if !ok {
t.Error("func `isSet` is not registred")
}
_, ok = fmap["defaultOrValue"]
if !ok {
t.Error("func `defaultOrValue` is not registred")
}
_, ok = fmap["inFormat"]
if !ok {
t.Error("func `in` is not registred")
}
_, ok = fmap["split"]
if !ok {
t.Error("func `split` is not registred")
}
}