Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfield committed Jul 30, 2018
1 parent b7d2c2e commit 9051f72
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion pkg/uptimerobot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ func TestGetAccountDetails(t *testing.T) {
}
}

func badAccountDetailsHandler(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBufferString(`{
"stat": "false",
"error": {"message": "Somebody set up us the bomb"}}`)),
}, nil
}

func TestAPIErrorResponse(t *testing.T) {
c := New("dummy")
mockClient := MockHTTPClient{
DoFunc: badAccountDetailsHandler,
}
c.http = &mockClient
_, err := c.GetAccountDetails()
if err == nil {
t.Error("API call with error response returned non-nil error")
}
}

func TestDebugFlag(t *testing.T) {
c := New("dummy")
out := &bytes.Buffer{}
Expand Down Expand Up @@ -253,4 +274,19 @@ func TestFriendlyType(t *testing.T) {
if got != want {
t.Errorf("FriendlyType(1) = %q, want %q", got, want)
}
}
}

func TestStringMethods(t *testing.T) {
m := Monitor{Type: 1}
if m.String() == "" {
t.Error("m.String() = empty, want non-empty string")
}
a := Account{}
if a.String() == "" {
t.Error("a.String() = empty, want non-empty string")
}
c := AlertContact{}
if c.String() == "" {
t.Error("c.String() = empty, want non-empty string")
}
}

0 comments on commit 9051f72

Please sign in to comment.