コード例 #1
0
					Expect(responseRecorder.Code).To(Equal(http.StatusCreated))
				})

				It("writes to database backend", func() {
					route[0].LogGuid = "my-guid"

					request = handlers.NewTestRequest(route)
					routesHandler.Upsert(responseRecorder, request)

					Expect(database.SaveRouteCallCount()).To(Equal(1))
					Expect(database.SaveRouteArgsForCall(0)).To(Equal(route[0]))
				})

				Context("when database fails to save", func() {
					BeforeEach(func() {
						database.SaveRouteReturns(errors.New("stuff broke"))
					})

					It("responds with a server error", func() {
						request = handlers.NewTestRequest(route)
						routesHandler.Upsert(responseRecorder, request)

						Expect(responseRecorder.Code).To(Equal(http.StatusInternalServerError))
						Expect(responseRecorder.Body.String()).To(ContainSubstring("stuff broke"))
					})
				})
			})

			Context("when there are errors with the input", func() {
				BeforeEach(func() {
					validator.ValidateCreateReturns(&routing_api.Error{Type: "a type", Message: "error message"})
コード例 #2
0
					Expect(responseRecorder.Code).To(Equal(http.StatusCreated))
				})

				It("writes to database backend", func() {
					route[0].LogGuid = "my-guid"

					request = handlers.NewTestRequest(route)
					routesHandler.Upsert(responseRecorder, request)

					Expect(database.SaveRouteCallCount()).To(Equal(1))
					Expect(database.SaveRouteArgsForCall(0)).To(Equal(route[0]))
				})

				Context("when database fails to save", func() {
					BeforeEach(func() {
						database.SaveRouteReturns(errors.New("stuff broke"))
					})

					It("responds with a server error", func() {
						request = handlers.NewTestRequest(route)
						routesHandler.Upsert(responseRecorder, request)

						Expect(responseRecorder.Code).To(Equal(http.StatusInternalServerError))
						Expect(responseRecorder.Body.String()).To(ContainSubstring("stuff broke"))
					})
				})

				Context("when conflict error is returned", func() {
					BeforeEach(func() {
						database.SaveRouteReturns(db.ErrorConflict)
					})