Exemplo n.º 1
0
			Ω(app.Name()).Should(Equal(appName))
			Ω(app.Logger).ShouldNot(BeNil())
			Ω(app.ServeMux).ShouldNot(BeNil())
		})
	})

	Describe("Use", func() {
		Context("with a valid middleware", func() {
			var m goa.Middleware

			BeforeEach(func() {
				m = middleware.RequestID()
			})

			JustBeforeEach(func() {
				s.Use(m)
			})

			It("adds the middleware", func() {
				ctrl := s.NewController("test")
				Ω(ctrl.MiddlewareChain()).Should(HaveLen(1))
				Ω(ctrl.MiddlewareChain()[0]).Should(BeAssignableToTypeOf(middleware.RequestID()))
			})
		})
	})

	Describe("HandleFunc", func() {
		const resName = "res"
		const actName = "act"
		var handler, unmarshaler goa.Handler
		const respStatus = 200
Exemplo n.º 2
0
			rw = &TestResponseWriter{ParentHeader: make(http.Header)}
		})

		JustBeforeEach(func() {
			s.Mux.ServeHTTP(rw, req)
		})

		It("handles requests with no registered handlers", func() {
			Ω(string(rw.Body)).Should(Equal(`{"code":"not_found","status":404,"detail":"/foo"}` + "\n"))
		})

		Context("with middleware", func() {
			middlewareCalled := false

			BeforeEach(func() {
				s.Use(TMiddleware(&middlewareCalled))
				// trigger finalize
				ctrl := s.NewController("test")
				ctrl.MuxHandler("", nil, nil)
			})

			It("calls the middleware", func() {
				Ω(middlewareCalled).Should(BeTrue())
			})
		})

		Context("middleware and multiple controllers", func() {
			middlewareCalled := 0

			BeforeEach(func() {
				s.Use(CMiddleware(&middlewareCalled))