-
Notifications
You must be signed in to change notification settings - Fork 22
/
config_test.go
47 lines (41 loc) · 1005 Bytes
/
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
package main
import (
"encoding/json"
"testing"
)
func Test_ConfigUnmarshalJSON(t *testing.T) {
c := Config{}
j := `{"host": "h", "port": 1883}`
err := json.Unmarshal([]byte(j), &c)
if err != nil {
t.Error(err)
}
if c.Port != 1883 {
t.Error("port(int) is not correctly read")
}
if c.Host != "h" || c.UserName != "" || c.Password != "" {
t.Error("parse failed")
}
j = `{"host": "h", "port": "1883", "username": "u"}`
err = json.Unmarshal([]byte(j), &c)
if err != nil {
t.Error(err)
}
if c.Port != 1883 {
t.Error("port(string) is not correctly read")
}
if c.Host != "h" || c.UserName != "u" || c.Password != "" {
t.Error("parse failed with username set")
}
}
func Test_ConfigCert(t *testing.T) {
c := Config{}
j := `{"caCert": "ca", "clientCert": "client", "privateKey": "key"}`
err := json.Unmarshal([]byte(j), &c)
if err != nil {
t.Error(err)
}
if c.CaCert != "ca" || c.ClientCert != "client" || c.PrivateKey != "key" {
t.Errorf("parse failed, %+v", c)
}
}