It("returns an http status created", func() { request = handlers.NewTestRequest(route) routesHandler.Upsert(responseRecorder, request) Expect(responseRecorder.Code).To(Equal(http.StatusCreated)) }) It("accepts a list of routes in the body", func() { route = append(route, route[0]) route[1].IP = "5.4.3.2" request = handlers.NewTestRequest(route) routesHandler.Upsert(responseRecorder, request) Expect(responseRecorder.Code).To(Equal(http.StatusCreated)) Expect(database.SaveRouteCallCount()).To(Equal(2)) Expect(database.SaveRouteArgsForCall(0)).To(Equal(route[0])) Expect(database.SaveRouteArgsForCall(1)).To(Equal(route[1])) }) It("accepts route_service_url parameters", func() { route[0].RouteServiceUrl = "https://my-rs.com" request = handlers.NewTestRequest(route) routesHandler.Upsert(responseRecorder, request) Expect(responseRecorder.Code).To(Equal(http.StatusCreated)) Expect(database.SaveRouteCallCount()).To(Equal(1)) Expect(database.SaveRouteArgsForCall(0)).To(Equal(route[0])) }) It("logs the route declaration", func() {
func expectInvalidInput(responseRecorder *httptest.ResponseRecorder, database *fake_db.FakeDB, logger *lagertest.TestLogger) { Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest)) Expect(responseRecorder.Body.String()).To(ContainSubstring("Each tcp mapping requires a positive host port")) Expect(database.SaveRouteCallCount()).To(Equal(0)) Expect(logger.Logs()[0].Message).To(ContainSubstring("error")) }