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"}) }) It("blows up when a port does not fit into a uint16", func() { json := `[{"route":"my-route.com","ip":"1.2.3.4", "port":65537}]` request = handlers.NewTestRequest(json) routesHandler.Upsert(responseRecorder, request) Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest)) Expect(responseRecorder.Body.String()).To(ContainSubstring("cannot unmarshal number 65537 into Go value of type uint16")) }) It("does not write to the key-value store backend", func() { request = handlers.NewTestRequest(route) routesHandler.Upsert(responseRecorder, request)