Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}},
Expand Down
22 changes: 22 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down