diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-28 15:02:25 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-10-28 15:02:25 +0100 |
commit | 419ea1639230c5a7613962cbcbe0eb8b9e1ad078 (patch) | |
tree | 5d62c97c8d29d4bef9f4892783ca446f4ee7cdab /clients/http/common_test.go | |
parent | 7d6c5a56c0b63705378f125523876de1a97fd1ce (diff) | |
download | go-git-419ea1639230c5a7613962cbcbe0eb8b9e1ad078.tar.gz |
clients: helpful error handling
Diffstat (limited to 'clients/http/common_test.go')
-rw-r--r-- | clients/http/common_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/clients/http/common_test.go b/clients/http/common_test.go index b672801..7bd9708 100644 --- a/clients/http/common_test.go +++ b/clients/http/common_test.go @@ -1,9 +1,45 @@ package http import ( + "net/http" "testing" . "gopkg.in/check.v1" ) func Test(t *testing.T) { TestingT(t) } + +type SuiteCommon struct{} + +var _ = Suite(&SuiteCommon{}) + +func (s *SuiteCommon) TestNewHTTPError200(c *C) { + res := &http.Response{StatusCode: 200} + res.StatusCode = 200 + err := NewHTTPError(res) + c.Assert(err, IsNil) +} + +func (s *SuiteCommon) TestNewHTTPError401(c *C) { + s.testNewHTTPError(c, 401, "permanent client error.*not found.*") +} + +func (s *SuiteCommon) TestNewHTTPError404(c *C) { + s.testNewHTTPError(c, 404, "permanent client error.*not found.*") +} + +func (s *SuiteCommon) TestNewHTTPError40x(c *C) { + s.testNewHTTPError(c, 402, "unexpected client error.*") +} + +func (s *SuiteCommon) testNewHTTPError(c *C, code int, msg string) { + req, _ := http.NewRequest("GET", "foo", nil) + res := &http.Response{ + StatusCode: code, + Request: req, + } + + err := NewHTTPError(res) + c.Assert(err, NotNil) + c.Assert(err, ErrorMatches, msg) +} |