// NewUpdateBottleContext parses the incoming request URL and body, performs validations and creates the // context used by the bottle controller update action. func NewUpdateBottleContext(c *goa.Context) (*UpdateBottleContext, error) { var err error ctx := UpdateBottleContext{Context: c} rawAccountID, ok := c.Get("accountID") if ok { if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil { ctx.AccountID = int(accountID) } else { err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err) } } rawBottleID, ok := c.Get("bottleID") if ok { if bottleID, err2 := strconv.Atoi(rawBottleID); err2 == nil { ctx.BottleID = int(bottleID) } else { err = goa.InvalidParamTypeError("bottleID", rawBottleID, "integer", err) } } p, err := NewUpdateBottlePayload(c.Payload()) if err != nil { return nil, err } ctx.Payload = p return &ctx, err }
// 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, ok := c.Get("accountID") if ok { if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil { ctx.AccountID = int(accountID) } else { err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err) } } rawYears, ok := c.Get("years") if ok { 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 ctx.HasYears = true } return &ctx, err }
// NewDeleteAccountContext parses the incoming request URL and body, performs validations and creates the // context used by the account controller delete action. func NewDeleteAccountContext(c *goa.Context) (*DeleteAccountContext, error) { var err error ctx := DeleteAccountContext{Context: c} rawAccountID := c.Get("accountID") if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil { ctx.AccountID = int(accountID) } else { err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err) } return &ctx, err }
// NewListSeriesContext parses the incoming request URL and body, performs validations and creates the // context used by the series controller list action. func NewListSeriesContext(c *goa.Context) (*ListSeriesContext, error) { var err error ctx := ListSeriesContext{Context: c} rawAccountID, ok := c.Get("accountID") if ok { 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("Payload", func() { It("returns nil if not initialized", func() { Ω(ctx.Payload()).Should(BeNil()) }) })
BeforeEach(func() { var err error r, err = http.NewRequest("GET", "/foo", nil) Ω(err).ShouldNot(HaveOccurred()) rw = new(TestResponseWriter) id := httprouter.Param{Key: "id", Value: "42"} query := httprouter.Param{Key: "sort", Value: "asc"} p = httprouter.Params{id, query} }) JustBeforeEach(func() { httpHandle(rw, r, p) }) It("creates a handle that handles the request", func() { i, ok := ctx.Get("id") Ω(ok).Should(BeTrue()) Ω(i).Should(Equal("42")) s, ok := ctx.Get("sort") Ω(ok).Should(BeTrue()) Ω(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))
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, ok := ctx.Get("foo") Ω(p).Should(Equal("")) Ω(ok).Should(BeFalse()) }) }) Describe("GetMany", func() { It("returns nil if not initialized", func() { Ω(ctx.GetMany("foo")).Should(BeNil()) }) }) Describe("Payload", func() { It("returns nil if not initialized", func() { Ω(ctx.Payload()).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)) })