}) Context("when executing the task errors", func() { disaster := errors.New("oh no!") BeforeEach(func() { taskStep.RunReturns(disaster) }) It("does not run any outputs", func() { Ω(outputStep.RunCallCount()).Should(BeZero()) }) It("finishes with error", func() { Ω(fakeDelegate.FinishCallCount()).Should(Equal(1)) _, cbErr, _, _ := fakeDelegate.FinishArgsForCall(0) Ω(cbErr).Should(MatchError(ContainSubstring(disaster.Error()))) }) }) Context("when executing the task succeeds", func() { BeforeEach(func() { taskStep.RunReturns(nil) taskStep.ResultStub = successResult(true) }) Context("when the output should perform on success", func() { BeforeEach(func() { outputPlan.Conditions = atc.Conditions{atc.ConditionSuccess} })
build, err := execEngine.CreateBuild(logger, buildModel, plan) Expect(err).NotTo(HaveOccurred()) build.Resume(logger) Expect(inputStep.RunCallCount()).To(Equal(1)) Expect(inputStep.ReleaseCallCount()).To(Equal(1)) Expect(taskStep.RunCallCount()).To(Equal(1)) Expect(inputStep.ReleaseCallCount()).To(Equal(1)) Expect(outputStep.RunCallCount()).To(Equal(0)) Expect(outputStep.ReleaseCallCount()).To(Equal(0)) _, cbErr, successful, aborted := fakeDelegate.FinishArgsForCall(0) Expect(cbErr).NotTo(HaveOccurred()) Expect(successful).To(Equal(exec.Success(false))) Expect(aborted).To(BeFalse()) }) }) Context("when a step in the aggregate fails the step fails", func() { BeforeEach(func() { inputStep.ResultStub = successResult(false) }) It("only run the failure hooks", func() { plan := atc.Plan{ Location: &atc.Location{}, OnSuccess: &atc.OnSuccessPlan{
Location: &atc.Location{}, Task: &atc.TaskPlan{ Name: "some-resource", Config: &atc.TaskConfig{}, }, }, }, } build, err := execEngine.CreateBuild(buildModel, plan) Ω(err).ShouldNot(HaveOccurred()) build.Resume(logger) Ω(inputStep.RunCallCount()).Should(Equal(1)) Ω(inputStep.ReleaseCallCount()).Should((BeNumerically(">", 0))) Ω(taskStep.RunCallCount()).Should(Equal(0)) Ω(fakeDelegate.FinishCallCount()).Should(Equal(1)) _, err, succeeded, aborted := fakeDelegate.FinishArgsForCall(0) Ω(err.Error()).Should(ContainSubstring(exec.ErrStepTimedOut.Error())) Ω(succeeded).Should(Equal(exec.Success(false))) Ω(aborted).Should(BeFalse()) }) }) }) })