catalogConfig = config.Catalog catalogController = controllers.NewCatalog(catalogConfig) }) Describe("#Show", func() { var goaContext *goa.Context var catalogContext *app.ShowCatalogContext var responseWriter *httptest.ResponseRecorder BeforeEach(func() { gctx := context.Background() req := http.Request{} responseWriter = httptest.NewRecorder() params := url.Values{} payload := map[string]string{} goaContext = goa.NewContext(gctx, &req, responseWriter, params, payload) var err error catalogContext, err = app.NewShowCatalogContext(goaContext) Expect(err).ToNot(HaveOccurred()) }) It("writes the correct catalog information to the context", func() { err := catalogController.Show(catalogContext) Expect(err).ToNot(HaveOccurred()) Expect(responseWriter.Body.String()).To(Equal(`{"services":[{"bindable":true,"description":"in memory keystore","id":"my-service-id","metadata":{"what":"about"},"name":"memcached","plan_updatable":false,"plans":[{"description":"shared 100mb memory limit","free":true,"id":"first-plan-id","name":"100mb"},{"description":"shared 1024mb memory limit","free":false,"id":"second-plan-id","name":"1024mb"}]}]}`)) }) }) })
It("returns the middleware", func() { Ω(fmt.Sprintf("%#v", middleware)).Should(Equal(fmt.Sprintf("%#v", goa.Middleware(goaMiddlewareFunc)))) Ω(mErr).ShouldNot(HaveOccurred()) }) }) Context("with a context", func() { var ctx *goa.Context BeforeEach(func() { req, err := http.NewRequest("GET", "/goo", nil) Ω(err).ShouldNot(HaveOccurred()) rw := new(TestResponseWriter) params := url.Values{"foo": []string{"bar"}} ctx = goa.NewContext(nil, req, rw, params, nil) Ω(ctx.ResponseStatus()).Should(Equal(0)) }) Context("using a goa handler", func() { BeforeEach(func() { var goaHandler goa.Handler = func(ctx *goa.Context) error { ctx.JSON(200, "ok") return nil } input = goaHandler }) It("wraps it in a middleware", func() { Ω(mErr).ShouldNot(HaveOccurred()) h := func(ctx *goa.Context) error { return nil }
var spec *jwt.Specification var req *http.Request var err error var token *jwtg.Token var tokenString string params := url.Values{"param": []string{"value"}, "query": []string{"qvalue"}} payload := map[string]interface{}{"payload": 42} validFunc := func(token *jwtg.Token) (interface{}, error) { return signingKey, nil } BeforeEach(func() { req, err = http.NewRequest("POST", "/goo", strings.NewReader(`{"payload":42}`)) Ω(err).ShouldNot(HaveOccurred()) rw := new(TestResponseWriter) ctx = goa.NewContext(nil, goa.New("test"), req, rw, params) ctx.SetPayload(payload) spec = &jwt.Specification{ AllowParam: true, ValidationFunc: validFunc, } token = jwtg.New(jwtg.SigningMethodHS256) token.Claims["exp"] = time.Now().Add(time.Hour * 24).Unix() token.Claims["random"] = "42" tokenString, err = token.SignedString(signingKey) Ω(err).ShouldNot(HaveOccurred()) }) It("requires a jwt token be present", func() { h := func(ctx *goa.Context) error {
"strings" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/raphael/goa" "golang.org/x/net/context" "gopkg.in/inconshreveable/log15.v2" ) var _ = Describe("Context", func() { var logger log15.Logger var ctx *goa.Context BeforeEach(func() { gctx := context.Background() ctx = goa.NewContext(gctx, goa.New("test"), nil, nil, nil) ctx.Logger = logger }) Describe("SetValue", func() { key := "answer" val := 42 BeforeEach(func() { ctx.SetValue(key, val) }) It("sets the value in the context.Context", func() { v := ctx.Value(key) Ω(v).Should(Equal(val)) })
var req *http.Request var err error var token *jwtg.Token var tokenString string params := map[string]string{"param": "value"} query := map[string][]string{"query": []string{"qvalue"}} payload := map[string]interface{}{"payload": 42} validFunc := func(token *jwtg.Token) (interface{}, error) { return signingKey, nil } BeforeEach(func() { req, err = http.NewRequest("POST", "/goo", strings.NewReader(`{"payload":42}`)) Ω(err).ShouldNot(HaveOccurred()) rw := new(TestResponseWriter) ctx = goa.NewContext(nil, req, rw, params, query, payload) spec = &jwt.Specification{ AllowParam: true, ValidationFunc: validFunc, } token = jwtg.New(jwtg.SigningMethodHS256) token.Claims["exp"] = time.Now().Add(time.Hour * 24).Unix() token.Claims["random"] = "42" tokenString, err = token.SignedString(signingKey) Ω(err).ShouldNot(HaveOccurred()) }) It("requires a jwt token be present", func() { h := func(ctx *goa.Context) error { ctx.JSON(200, "ok")
Ω(fmt.Sprintf("%#v", middleware)).Should(Equal(fmt.Sprintf("%#v", goa.Middleware(goaMiddlewareFunc)))) Ω(mErr).ShouldNot(HaveOccurred()) }) }) Context("with a context", func() { var service goa.Service var ctx *goa.Context BeforeEach(func() { service = goa.New("test") req, err := http.NewRequest("GET", "/goo", nil) Ω(err).ShouldNot(HaveOccurred()) rw := new(TestResponseWriter) params := url.Values{"foo": []string{"bar"}} ctx = goa.NewContext(nil, service, req, rw, params) Ω(ctx.ResponseStatus()).Should(Equal(0)) }) Context("using a goa handler", func() { BeforeEach(func() { var goaHandler goa.Handler = func(ctx *goa.Context) error { ctx.Respond(200, "ok") return nil } input = goaHandler }) It("wraps it in a middleware", func() { Ω(mErr).ShouldNot(HaveOccurred()) h := func(ctx *goa.Context) error { return nil }
Ω(fmt.Sprintf("%#v", middleware)).Should(Equal(fmt.Sprintf("%#v", goa.Middleware(goaMiddlewareFunc)))) Ω(mErr).ShouldNot(HaveOccurred()) }) }) Context("with a context", func() { var service goa.Service var ctx *goa.Context BeforeEach(func() { service = goa.New("test") req, err := http.NewRequest("GET", "/goo", nil) Ω(err).ShouldNot(HaveOccurred()) rw := new(testResponseWriter) params := url.Values{"foo": []string{"bar"}} ctx = goa.NewContext(nil, service, req, rw, params) Ω(ctx.ResponseStatus()).Should(Equal(0)) }) Context("using a goa handler", func() { BeforeEach(func() { var goaHandler goa.Handler = func(ctx *goa.Context) error { ctx.Respond(200, "ok") return nil } input = goaHandler }) It("wraps it in a middleware", func() { Ω(mErr).ShouldNot(HaveOccurred()) h := func(ctx *goa.Context) error { return nil }