// NewListBottleContext parses the incoming request URL and body, performs validations and creates the // context used by the bottle controller list action. func NewListBottleContext(c *goa.Context) (*ListBottleContext, error) { var err error ctx := ListBottleContext{Context: c} rawAccountID := c.Get("accountID") if rawAccountID != "" { if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil { ctx.AccountID = int(accountID) } else { err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err) } } rawYears := c.Get("years") if rawYears != "" { elemsYears := strings.Split(rawYears, ",") elemsYears2 := make([]int, len(elemsYears)) for i, rawElem := range elemsYears { if elem, err2 := strconv.Atoi(rawElem); err2 == nil { elemsYears2[i] = int(elem) } else { err = goa.InvalidParamTypeError("elem", rawElem, "integer", err) } } ctx.Years = elemsYears2 } return &ctx, err }
// NewShowAccountContext parses the incoming request URL and body, performs validations and creates the // context used by the account controller show action. func NewShowAccountContext(c *goa.Context) (*ShowAccountContext, error) { var err error ctx := ShowAccountContext{Context: c} rawAccountID := c.Get("accountID") if rawAccountID != "" { if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil { ctx.AccountID = int(accountID) } else { err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err) } } return &ctx, err }
Describe("ResponseStatus", func() { It("returns 0 if not initialized", func() { Ω(ctx.ResponseStatus()).Should(Equal(0)) }) }) Describe("ResponseLength", func() { It("returns 0 if not initialized", func() { Ω(ctx.ResponseLength()).Should(Equal(0)) }) }) Describe("Get", func() { It(`returns "", false if not initialized`, func() { p := ctx.Get("foo") Ω(p).Should(Equal("")) }) }) Describe("GetMany", func() { It("returns nil if not initialized", func() { Ω(ctx.GetMany("foo")).Should(BeNil()) }) }) Describe("RawPayload", func() { It("returns nil if not initialized", func() { Ω(ctx.RawPayload()).Should(BeNil()) }) })
var p url.Values BeforeEach(func() { var err error r, err = http.NewRequest("GET", "/foo", nil) Ω(err).ShouldNot(HaveOccurred()) rw = new(TestResponseWriter) p = url.Values{"id": []string{"42"}, "sort": []string{"asc"}} }) JustBeforeEach(func() { handleFunc(rw, r, p) }) It("creates a handle that handles the request", func() { i := ctx.Get("id") Ω(i).Should(Equal("42")) s := ctx.Get("sort") Ω(s).Should(Equal("asc")) tw := rw.(*TestResponseWriter) Ω(tw.Status).Should(Equal(respStatus)) Ω(tw.Body).Should(Equal(respContent)) }) Context("and middleware", func() { middlewareCalled := false BeforeEach(func() { s.Use(TMiddleware(&middlewareCalled)) })