diff --git a/client/client_test.go b/client/client_test.go index 7455769d..5a3c15f4 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -90,9 +90,18 @@ func TestAPI(t *testing.T) { client := &fakeAPIClient{T: t, ch: make(chan fakeAPIResponse, 1)} now := time.Now() + u, err := url.Parse("http://example.com") + if err != nil { + t.Errorf("unexpected error: %v", err) + } statusData := &ServerStatus{ - ConfigYAML: "{}", - ConfigJSON: &config.Config{}, + ConfigYAML: "{}", + ConfigJSON: &config.Config{ + Global: &config.GlobalConfig{ + PagerdutyURL: &config.URL{URL: u}, + SMTPSmarthost: config.HostPort{Host: "localhost", Port: "25"}, + }, + }, VersionInfo: map[string]string{"version": "v1"}, Uptime: now, ClusterStatus: &ClusterStatus{Peers: []PeerStatus{}}, diff --git a/config/config.go b/config/config.go index 29981d22..5294e4da 100644 --- a/config/config.go +++ b/config/config.go @@ -516,6 +516,28 @@ func (hp *HostPort) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } +// UnmarshalJSON implements the json.Unmarshaler interface for HostPort. +func (hp *HostPort) UnmarshalJSON(data []byte) error { + var ( + s string + err error + ) + if err = json.Unmarshal(data, &s); err != nil { + return err + } + if s == "" { + return nil + } + hp.Host, hp.Port, err = net.SplitHostPort(s) + if err != nil { + return err + } + if hp.Port == "" { + return errors.Errorf("address %q: port cannot be empty", s) + } + return nil +} + // MarshalYAML implements the yaml.Marshaler interface for HostPort. func (hp HostPort) MarshalYAML() (interface{}, error) { return hp.String(), nil