/
config_test.go
87 lines (77 loc) · 1.44 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
package omega
import (
"code.google.com/p/gcfg"
"fmt"
"testing"
)
var (
isSetup = false
basehttpConfig = BaseHttpConfig{
Hostname: "",
Port: 8080,
Root: "/var/www",
}
testHttpConf = Config{
Http: struct {
BaseHttpConfig
MaxClients int
MaxProc int
KeepAlive bool
Timeout int
}{
BaseHttpConfig: basehttpConfig,
MaxClients: 100,
MaxProc: 0,
KeepAlive: false,
Timeout: 30,
},
Log: struct {
LogLevel string
Syslog bool
LogFormat string
}{
LogLevel: "warn",
Syslog: false,
LogFormat: "{Unix-Time}: {METHOD}, {URI} - {Referer}|{IP}|{User-Agent}",
},
}
)
func setup() error {
if !isSetup {
err := gcfg.ReadFileInto(&cfg, configFile)
if err != nil {
isSetup = false
return err
}
}
isSetup = true
return nil
}
func loadConfig() error {
err := gcfg.ReadFileInto(&cfg, configFile)
if err != nil {
return err
}
return nil
}
func TestHttpConf(t *testing.T) {
err := setup()
if err != nil {
t.Errorf("Error: %v\n", err)
}
if cfg.Http != testHttpConf.Http {
t.Errorf("Invalid HTTP Configuration, Expected: %v, Got: %v", testHttpConf, cfg.Http)
}
}
func TestLogConf(t *testing.T) {
err := setup()
if err != nil {
t.Errorf("Error: %v\n", err)
}
if cfg.Log != testHttpConf.Log {
t.Errorf("Invalid Log configuration, Exptected: %v, Got: %v", testHttpConf.Log, cfg.Log)
}
}
func TestHostsConf(t *testing.T) {
// Leave for now
}