Context("when the task is in completed state", func() { BeforeEach(func() { taskDef = model_helpers.NewValidTaskDefinition() err := etcdDB.DesireTask(logger, taskDef, taskGuid, domain) Expect(err).NotTo(HaveOccurred()) _, err = etcdDB.StartTask(logger, taskGuid, cellId) Expect(err).NotTo(HaveOccurred()) err = etcdDB.CompleteTask(logger, taskGuid, cellId, false, "", "") Expect(err).NotTo(HaveOccurred()) }) It("returns an error", func() { Expect(cancelError).To(HaveOccurred()) Expect(cancelError).To(Equal(models.NewTaskTransitionError(models.Task_Completed, models.Task_Completed))) }) }) Context("when the task is in resolving state", func() { BeforeEach(func() { taskDef = model_helpers.NewValidTaskDefinition() err := etcdDB.DesireTask(logger, taskDef, taskGuid, domain) Expect(err).NotTo(HaveOccurred()) _, err = etcdDB.StartTask(logger, taskGuid, cellId) Expect(err).NotTo(HaveOccurred()) err = etcdDB.CompleteTask(logger, taskGuid, cellId, false, "", "") Expect(err).NotTo(HaveOccurred())
handler.Delete(responseRecorder, request) }) It("succeeds", func() { Expect(fakeClient.ResolvingTaskCallCount()).To(Equal(1)) Expect(fakeClient.ResolvingTaskArgsForCall(0)).To(Equal("the-task-guid")) Expect(fakeClient.ResolveTaskCallCount()).To(Equal(1)) Expect(fakeClient.ResolveTaskArgsForCall(0)).To(Equal("the-task-guid")) Expect(responseRecorder.Code).To(Equal(http.StatusOK)) }) Context("when marking the task as resolving fails", func() { Context("with invalid transition", func() { BeforeEach(func() { resolvingErr = models.NewTaskTransitionError(models.Task_Running, models.Task_Pending) }) It("fails with a 409", func() { Expect(fakeClient.ResolvingTaskCallCount()).To(Equal(1)) Expect(fakeClient.ResolvingTaskArgsForCall(0)).To(Equal("the-task-guid")) Expect(responseRecorder.Code).To(Equal(http.StatusConflict)) }) }) Context("with resource not found", func() { BeforeEach(func() { resolvingErr = models.ErrResourceNotFound })