From 158c7cec39fd4eb6a3f77eddb46c510371143ab6 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 28 May 2013 18:17:55 -0700 Subject: [PATCH] add test for invalid URL passed to NewRequest also add specific error type checking for invalid JSON test --- github/github_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/github/github_test.go b/github/github_test.go index f562721..b852e31 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -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) } }