1
0
mirror of https://github.com/shirou/mqttcli.git synced 2025-04-24 13:48:57 +08:00
mqttcli/config_test.go
sabith c7210e3587 Try using a install script like dep
Signed-off-by: sabith <sabithksme@gmail.com>
2018-07-17 23:00:06 -07:00

48 lines
1005 B
Go

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)
}
}