-
Notifications
You must be signed in to change notification settings - Fork 315
/
config_test.go
119 lines (104 loc) · 2.08 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package git
import (
"os"
"testing"
)
var tempConfig = "./temp.gitconfig"
func setupConfig() (*Config, error) {
var (
c *Config
err error
)
c, err = OpenOndisk(tempConfig)
if err != nil {
return nil, err
}
err = c.SetString("foo.bar", "baz")
if err != nil {
return nil, err
}
err = c.SetBool("foo.bool", true)
if err != nil {
return nil, err
}
err = c.SetInt32("foo.int32", 32)
if err != nil {
return nil, err
}
err = c.SetInt64("foo.int64", 64)
if err != nil {
return nil, err
}
return c, err
}
func cleanupConfig() {
os.Remove(tempConfig)
}
type TestRunner func(*Config, *testing.T)
var tests = []TestRunner{
// LookupString
func(c *Config, t *testing.T) {
val, err := c.LookupString("foo.bar")
if err != nil {
t.Errorf("Got LookupString error: '%v', expected none\n", err)
}
if val != "baz" {
t.Errorf("Got '%s' from LookupString, expected 'bar'\n", val)
}
},
// LookupBool
func(c *Config, t *testing.T) {
val, err := c.LookupBool("foo.bool")
if err != nil {
t.Errorf("Got LookupBool error: '%v', expected none\n", err)
}
if !val {
t.Errorf("Got %t from LookupBool, expected 'false'\n", val)
}
},
// LookupInt32
func(c *Config, t *testing.T) {
val, err := c.LookupInt32("foo.int32")
if err != nil {
t.Errorf("Got LookupInt32 error: '%v', expected none\n", err)
}
if val != 32 {
t.Errorf("Got %v, expected 32\n", val)
}
},
// LookupInt64
func(c *Config, t *testing.T) {
val, err := c.LookupInt64("foo.int64")
if err != nil {
t.Errorf("Got LookupInt64 error: '%v', expected none\n", err)
}
if val != 64 {
t.Errorf("Got %v, expected 64\n", val)
}
},
}
func TestConfigLookups(t *testing.T) {
t.Parallel()
var (
err error
c *Config
)
c, err = setupConfig()
defer cleanupConfig()
if err != nil {
t.Errorf("Setup error: '%v'. Expected none\n", err)
return
}
defer c.Free()
for _, test := range tests {
test(c, t)
}
}
func TestOpenDefault(t *testing.T) {
c, err := OpenDefault()
if err != nil {
t.Errorf("OpenDefault error: '%v'. Expected none\n", err)
return
}
defer c.Free()
}