-
Notifications
You must be signed in to change notification settings - Fork 201
/
configparser_test.go
60 lines (53 loc) · 2.25 KB
/
configparser_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
package main
import (
"fmt"
"testing"
"github.com/uniqush/log"
"github.com/uniqush/uniqush-push/db"
"github.com/uniqush/uniqush-push/push"
"github.com/uniqush/uniqush-push/testutil"
)
func TestOpenConfig(t *testing.T) {
c, err := OpenConfig("conf/uniqush-push.conf")
if err != nil {
t.Fatalf("Unexpected error loading example config: %v", err)
}
fmt.Printf("c: %#v\n", c)
getString := func(section, setting string) string {
s, loadErr := c.GetString(section, setting)
if loadErr != nil {
t.Errorf("Failed to get section %q setting %q: %v", section, setting, loadErr)
}
return s
}
testutil.ExpectStringEquals(t, "on", getString("WebFrontend", "log"), "unexpected data for log")
testutil.ExpectStringEquals(t, "standard", getString("WebFrontend", "loglevel"), "unexpected data for loglevel")
testutil.ExpectStringEquals(t, "localhost:9898", getString("WebFrontend", "addr"), "unexpected data for addr")
dbConf := LoadDatabaseConfig(c)
expectedDbConf := &db.DatabaseConfig{
Engine: "redis",
Name: "0",
Host: "localhost",
Port: -1, // redis db package converts this to default redis port
SlaveHost: "",
SlavePort: -1,
EverySec: 600, // TODO: Change configparser.go to make this 60?
LeastDirty: 10,
CacheSize: 1024,
PushServiceManager: push.GetPushServiceManager(),
}
testutil.ExpectEquals(t, *expectedDbConf, *dbConf, "expected config settings to be parsed")
}
func TestExtractLogLevel(t *testing.T) {
expectLogLevelForName := func(level int, loglevel string) {
actualLevel, warningMsg := extractLogLevel(loglevel)
testutil.ExpectStringEquals(t, "", warningMsg, "expected no warning")
testutil.ExpectEquals(t, level, actualLevel, "expected log level to be parsed")
}
expectLogLevelForName(log.LOGLEVEL_WARN, "warn")
expectLogLevelForName(log.LOGLEVEL_ERROR, "error")
expectLogLevelForName(log.LOGLEVEL_INFO, "standard")
level, warningMsg := extractLogLevel("blue")
testutil.ExpectStringEquals(t, `Unsupported loglevel "blue". Supported values: alert, error, warn/warning, standard/verbose/info, and debug`, warningMsg, "expected a warning message")
testutil.ExpectEquals(t, log.LOGLEVEL_INFO, level, "expected INFO level fallback")
}