aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/client/http/common_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-11-08 23:46:38 +0100
committerGitHub <noreply@github.com>2016-11-08 23:46:38 +0100
commitac095bb12c4d29722b60ba9f20590fa7cfa6bc7d (patch)
tree223f36f336ba3414b1e45cac8af6c4744a5d7ef6 /plumbing/client/http/common_test.go
parente523701393598f4fa241dd407af9ff8925507a1a (diff)
downloadgo-git-ac095bb12c4d29722b60ba9f20590fa7cfa6bc7d.tar.gz
new plumbing package (#118)
* plumbing: now core was renamed to core, and formats and clients moved inside
Diffstat (limited to 'plumbing/client/http/common_test.go')
-rw-r--r--plumbing/client/http/common_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/plumbing/client/http/common_test.go b/plumbing/client/http/common_test.go
new file mode 100644
index 0000000..287897d
--- /dev/null
+++ b/plumbing/client/http/common_test.go
@@ -0,0 +1,52 @@
+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) TestNewBasicAuth(c *C) {
+ a := NewBasicAuth("foo", "qux")
+
+ c.Assert(a.Name(), Equals, "http-basic-auth")
+ c.Assert(a.String(), Equals, "http-basic-auth - foo:*******")
+}
+
+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, "authorization required")
+}
+
+func (s *SuiteCommon) TestNewHTTPError404(c *C) {
+ s.testNewHTTPError(c, 404, "repository 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)
+}