Skip to content

Commit

Permalink
Merge pull request #8 from leucos/sub_type-fix
Browse files Browse the repository at this point in the history
Fixes inconsistent API typing for sub_type
  • Loading branch information
bitfield authored Nov 3, 2018
2 parents 8237ad0 + e9bfdbf commit 285bb82
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
17 changes: 16 additions & 1 deletion pkg/testdata/getMonitors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"pagination": {
"offset": 0,
"limit": 50,
"total": 2
"total": 3
},
"monitors": [
{
Expand Down Expand Up @@ -73,6 +73,21 @@
"duration": 22
}
]
},
{
"id": 777559666,
"friendly_name": "My FTP Server",
"url": "ftp.mywebpage.com",
"type": 4,
"sub_type": 3,
"keyword_type": null,
"keyword_value": "",
"http_username": "",
"http_password": "",
"port": 21,
"interval": 60,
"status": 2,
"create_datetime": 0
}
]
}
12 changes: 6 additions & 6 deletions pkg/uptimerobot.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (a AlertContact) String() string {

// Monitor represents an UptimeRobot monitor.
type Monitor struct {
ID int64 `json:"id"`
FriendlyName string `json:"friendly_name"`
URL string `json:"url"`
Type int `json:"type"`
SubType string `json:"sub_type"`
// keyword_type is returned as either an integer or an empty string,
ID int64 `json:"id"`
FriendlyName string `json:"friendly_name"`
URL string `json:"url"`
Type int `json:"type"`
SubType interface{} `json:"sub_type"`
// keyword_type and sub_type are returned as either an integer or an empty string,
// which Go doesn't allow: https://github.com/golang/go/issues/22182
KeywordType interface{} `json:"keyword_type"`
KeywordValue string `json:"keyword_value"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/uptimerobot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func fakeGetMonitorsHandler(req *http.Request) (*http.Response, error) {
}

func TestGetMonitors(t *testing.T) {
want := []string{"Google", "My Web Page"}
want := []string{"Google", "My Web Page", "My FTP Server"}
c := New("dummy")
mockClient := MockHTTPClient{
DoFunc: fakeGetMonitorsHandler,
Expand Down

0 comments on commit 285bb82

Please sign in to comment.