Browse Source

add test for invalid URL passed to NewRequest

also add specific error type checking for invalid JSON test
Will Norris 13 years ago
parent
commit
158c7cec39
1 changed files with 16 additions and 1 deletions
  1. +16
    -1
      github/github_test.go

+ 16
- 1
github/github_test.go View File

@ -7,6 +7,7 @@
package github
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
@ -91,7 +92,21 @@ func TestNewRequest_invalidJSON(t *testing.T) {
_, err := c.NewRequest("GET", "/", &T{})
if err == nil {
t.Error("Expected JSON marshalling error.")
t.Error("Expected error to be returned.")
}
if err, ok := err.(*json.UnsupportedTypeError); !ok {
t.Errorf("Expected a JSON error; got %#v.", err)
}
}
func TestNewRequest_badURL(t *testing.T) {
c := NewClient(nil)
_, err := c.NewRequest("GET", ":", nil)
if err == nil {
t.Error("Expected error to be returned.")
}
if err, ok := err.(*url.Error); !ok || err.Op != "parse" {
t.Errorf("Expected a URL parsing error; got %+v.", err)
}
}


Loading…
Cancel
Save