1
0
mirror of https://github.com/shirou/mqttcli.git synced 2025-04-26 13:49:17 +08:00
mqttcli/config_test.go
2014-12-15 23:45:24 +09:00

35 lines
692 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")
}
}