-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
66 lines (61 loc) · 1.47 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
package EpicServer
import (
"reflect"
"testing"
)
func TestConfigOptions(t *testing.T) {
tests := []struct {
name string
option Option
want *Config
validate func(*testing.T, *Config)
}{
{
name: "set host and port",
option: SetHost("127.0.0.1", 8080),
validate: func(t *testing.T, c *Config) {
if c.Server.Host != "127.0.0.1" || c.Server.Port != 8080 {
t.Errorf("host/port = %s:%d, want 127.0.0.1:8080", c.Server.Host, c.Server.Port)
}
},
},
{
name: "set secret key",
option: SetSecretKey([]byte("test-secret")),
validate: func(t *testing.T, c *Config) {
if !reflect.DeepEqual(c.SecretKey, []byte("test-secret")) {
t.Error("secret key not set correctly")
}
},
},
{
name: "set custom config",
option: SetCustomConfig(map[string]interface{}{"test": true}),
validate: func(t *testing.T, c *Config) {
custom := c.Custom.(map[string]interface{})
if v, ok := custom["test"]; !ok || v != true {
t.Error("custom config not set correctly")
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := &Config{}
tt.option(config)
tt.validate(t, config)
})
}
}
func TestGetCustomConfig(t *testing.T) {
customData := map[string]string{"key": "value"}
s := &Server{
Config: &Config{
Custom: customData,
},
}
got := GetCustomConfig(s)
if !reflect.DeepEqual(got, customData) {
t.Errorf("GetCustomConfig() = %v, want %v", got, customData)
}
}