Exemplo n.º 1
0
	It("creates a http error", func() {
		Ω(valErr).ShouldNot(BeNil())
		Ω(valErr).Should(BeAssignableToTypeOf(&goa.Error{}))
		err := valErr.(*goa.Error)
		Ω(err.Detail).Should(ContainSubstring(name))
		Ω(err.Detail).Should(ContainSubstring("%d", val))
		Ω(err.Detail).Should(ContainSubstring(expected))
	})
})

var _ = Describe("MissingParaerror", func() {
	var valErr error
	name := "param"

	JustBeforeEach(func() {
		valErr = goa.MissingParamError(name)
	})

	It("creates a http error", func() {
		Ω(valErr).ShouldNot(BeNil())
		Ω(valErr).Should(BeAssignableToTypeOf(&goa.Error{}))
		err := valErr.(*goa.Error)
		Ω(err.Detail).Should(ContainSubstring(name))
	})
})

var _ = Describe("InvalidAttributeTypeError", func() {
	var valErr error
	ctx := "ctx"
	val := 42
	expected := "43"
Exemplo n.º 2
0
		Ω(logger.InfoEntries[3].Data).Should(HaveLen(12))
		Ω(logger.InfoEntries[3].Data[0]).Should(Equal("req_id"))
		Ω(logger.InfoEntries[3].Data[2]).Should(Equal("status"))
		Ω(logger.InfoEntries[3].Data[3]).Should(Equal(200))
		Ω(logger.InfoEntries[3].Data[4]).Should(Equal("bytes"))
		Ω(logger.InfoEntries[3].Data[5]).Should(Equal(5))
		Ω(logger.InfoEntries[3].Data[6]).Should(Equal("time"))
		Ω(logger.InfoEntries[3].Data[8]).Should(Equal("ctrl"))
		Ω(logger.InfoEntries[3].Data[9]).Should(Equal("test"))
		Ω(logger.InfoEntries[3].Data[10]).Should(Equal("action"))
		Ω(logger.InfoEntries[3].Data[11]).Should(Equal("goo"))
	})

	It("logs error codes", func() {
		h := func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
			return goa.MissingParamError("foo")
		}
		rw.ParentHeader = make(http.Header)
		lg := middleware.LogRequest(false)(middleware.ErrorHandler(service, false)(h))
		Ω(lg(ctx, rw, req)).ShouldNot(HaveOccurred())
		Ω(logger.InfoEntries).Should(HaveLen(2))
		Ω(logger.InfoEntries[0].Data).Should(HaveLen(10))
		Ω(logger.InfoEntries[0].Data[0]).Should(Equal("req_id"))
		Ω(logger.InfoEntries[0].Data[2]).Should(Equal("POST"))
		Ω(logger.InfoEntries[0].Data[3]).Should(Equal("/goo?param=value"))

		Ω(logger.InfoEntries[1].Data).Should(HaveLen(14))
		Ω(logger.InfoEntries[1].Data[0]).Should(Equal("req_id"))
		Ω(logger.InfoEntries[1].Data[2]).Should(Equal("status"))
		Ω(logger.InfoEntries[1].Data[3]).Should(Equal(400))
		Ω(logger.InfoEntries[1].Data[4]).Should(Equal("error"))