-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure_test.go
42 lines (35 loc) · 1.08 KB
/
configure_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
package configure
import (
"fmt"
"log"
"testing"
)
func defaultListen(filepath string) {
log.Println(fmt.Sprintf("file '%s' has been changed", filepath))
}
func TestWatch(t *testing.T) {
file, _ := Watch("example1.txt", defaultListen)
r1 := file.Filename()
e1 := "example1.txt"
// 输出:http
r2 := file.Section("server").Key("protocol").Val()
e2 := "http"
r3 := file.Section("").Key("app_mode").Description()
e3 := "possible values : production, development"
if r1 != e1 || r2 != e2 || r3 != e3 {
t.Errorf("expected '%s', '%s', '%s' but got '%s', '%s', '%s'", e1, e2, e3, r1, r2, r3)
}
}
func TestWatchWithOption(t *testing.T) {
file, _ := WatchWithOption("example2.txt", defaultListen, Option{Separation: "\t"})
r1 := file.Filename()
e1 := "example2.txt"
// 输出:http
r2 := file.Section("server").Key("protocol").Val()
e2 := "http"
r3 := file.Section("").Key("app_mode").Description()
e3 := "possible values : production, development"
if r1 != e1 || r2 != e2 || r3 != e3 {
t.Errorf("expected '%s', '%s', '%s' but got '%s', '%s', '%s'", e1, e2, e3, r1, r2, r3)
}
}