1
package httpbakery_test
8
"github.com/juju/testing/httptesting"
10
"gopkg.in/macaroon.v1"
12
"gopkg.in/macaroon-bakery.v0/httpbakery"
15
type ErrorSuite struct{}
17
var _ = gc.Suite(&ErrorSuite{})
19
func (s *ErrorSuite) TestWriteDischargeRequiredError(c *gc.C) {
20
m, err := macaroon.New([]byte("secret"), "id", "a location")
21
c.Assert(err, gc.IsNil)
26
expectedResponse httpbakery.Error
28
about: `write discharge required with "an error" but no path`,
30
err: errors.New("an error"),
31
expectedResponse: httpbakery.Error{
32
Code: httpbakery.ErrDischargeRequired,
34
Info: &httpbakery.ErrorInfo{
39
about: `write discharge required with "an error" but and set a path`,
40
path: "http://foobar:1234",
41
err: errors.New("an error"),
42
expectedResponse: httpbakery.Error{
43
Code: httpbakery.ErrDischargeRequired,
45
Info: &httpbakery.ErrorInfo{
47
MacaroonPath: "http://foobar:1234",
51
about: `write discharge required with nil error but set a path`,
52
path: "http://foobar:1234",
54
expectedResponse: httpbakery.Error{
55
Code: httpbakery.ErrDischargeRequired,
56
Message: httpbakery.ErrDischargeRequired.Error(),
57
Info: &httpbakery.ErrorInfo{
59
MacaroonPath: "http://foobar:1234",
65
for i, t := range tests {
66
c.Logf("Running test %d %s", i, t.about)
67
response := httptest.NewRecorder()
68
httpbakery.WriteDischargeRequiredError(response, m, t.path, t.err)
69
httptesting.AssertJSONResponse(c, response, http.StatusProxyAuthRequired, t.expectedResponse)