httpClient *http.Client ) BeforeEach(func() { httpClient = cf_http.NewClient() statusCodes = make(chan int) reqCount = make(chan struct{}) fakeServer.RouteToHandler("POST", "/the-callback/url", func(w http.ResponseWriter, req *http.Request) { w.WriteHeader(<-statusCodes) }) callbackURL = fakeServer.URL() + "/the-callback/url" taskDB = new(dbfakes.FakeTaskDB) taskDB.ResolvingTaskReturns(nil) taskDB.DeleteTaskReturns(nil) }) simulateTaskCompleting := func(signals <-chan os.Signal, ready chan<- struct{}) error { close(ready) task = model_helpers.NewValidTask("the-task-guid") task.CompletionCallbackUrl = callbackURL taskworkpool.HandleCompletedTask(logger, httpClient, taskDB, task) return nil } var process ifrit.Process JustBeforeEach(func() { process = ifrit.Invoke(ifrit.RunFunc(simulateTaskCompleting)) })
Expect(fakeTaskDB.DeleteTaskCallCount()).To(Equal(1)) _, taskGuid := fakeTaskDB.DeleteTaskArgsForCall(0) Expect(taskGuid).To(Equal("task-guid")) Expect(responseRecorder.Code).To(Equal(http.StatusOK)) response := &models.TaskLifecycleResponse{} err := response.Unmarshal(responseRecorder.Body.Bytes()) Expect(err).NotTo(HaveOccurred()) Expect(response.Error).To(BeNil()) }) }) Context("when the DB returns an unrecoverable error", func() { BeforeEach(func() { fakeTaskDB.DeleteTaskReturns(models.NewUnrecoverableError(nil)) }) It("logs and writes to the exit channel", func() { Eventually(logger).Should(gbytes.Say("unrecoverable-error")) Eventually(exitCh).Should(Receive()) }) }) Context("when desiring the task fails", func() { BeforeEach(func() { fakeTaskDB.DeleteTaskReturns(models.ErrUnknownError) }) It("responds with an error", func() { Expect(responseRecorder.Code).To(Equal(http.StatusOK))