attempt1Step *fakes.FakeStep attempt2Factory *fakes.FakeStepFactory attempt2Step *fakes.FakeStep attempt3Factory *fakes.FakeStepFactory attempt3Step *fakes.FakeStep stepFactory StepFactory step Step ) BeforeEach(func() { attempt1Factory = new(fakes.FakeStepFactory) attempt1Step = new(fakes.FakeStep) attempt1Factory.UsingReturns(attempt1Step) attempt2Factory = new(fakes.FakeStepFactory) attempt2Step = new(fakes.FakeStep) attempt2Factory.UsingReturns(attempt2Step) attempt3Factory = new(fakes.FakeStepFactory) attempt3Step = new(fakes.FakeStep) attempt3Factory.UsingReturns(attempt3Step) stepFactory = Retry{attempt1Factory, attempt2Factory, attempt3Factory} step = stepFactory.Using(nil, nil) }) Context("when attempt 1 succeeds", func() { BeforeEach(func() {
inputStepFactory *execfakes.FakeStepFactory inputStep *execfakes.FakeStep outputStepFactory *execfakes.FakeStepFactory outputStep *execfakes.FakeStep dependentStepFactory *execfakes.FakeStepFactory dependentStep *execfakes.FakeStep ) BeforeEach(func() { taskStepFactory = new(execfakes.FakeStepFactory) taskStep = new(execfakes.FakeStep) taskStep.ResultStub = successResult(true) taskStepFactory.UsingReturns(taskStep) fakeFactory.TaskReturns(taskStepFactory) inputStepFactory = new(execfakes.FakeStepFactory) inputStep = new(execfakes.FakeStep) inputStep.ResultStub = successResult(true) inputStepFactory.UsingReturns(inputStep) fakeFactory.GetReturns(inputStepFactory) outputStepFactory = new(execfakes.FakeStepFactory) outputStep = new(execfakes.FakeStep) outputStep.ResultStub = successResult(true) outputStepFactory.UsingReturns(outputStep) fakeFactory.PutReturns(outputStepFactory) dependentStepFactory = new(execfakes.FakeStepFactory)
repo *exec.SourceRepository ensureFactory exec.StepFactory ensureStep exec.Step ) BeforeEach(func() { stepFactory = &fakes.FakeStepFactory{} hookFactory = &fakes.FakeStepFactory{} step = &fakes.FakeStep{} hook = &fakes.FakeStep{} previousStep = &fakes.FakeStep{} stepFactory.UsingReturns(step) hookFactory.UsingReturns(hook) repo = exec.NewSourceRepository() ensureFactory = exec.Ensure(stepFactory, hookFactory) ensureStep = ensureFactory.Using(previousStep, repo) }) It("runs the ensure hook if the step succeeds", func() { step.ResultStub = successResult(true) process := ifrit.Background(ensureStep) Eventually(step.RunCallCount).Should(Equal(1)) Eventually(hook.RunCallCount).Should(Equal(1))
Context("get with nil location", func() { var ( getStepFactory *execfakes.FakeStepFactory getStep *execfakes.FakeStep fakeDelegate *fakes.FakeBuildDelegate fakeGetDelegate *execfakes.FakeGetDelegate plan atc.Plan ) BeforeEach(func() { getStepFactory = new(execfakes.FakeStepFactory) getStep = new(execfakes.FakeStep) getStep.ResultStub = successResult(true) getStepFactory.UsingReturns(getStep) fakeFactory.GetReturns(getStepFactory) fakeDelegate = new(fakes.FakeBuildDelegate) fakeDelegateFactory.DelegateReturns(fakeDelegate) fakeGetDelegate = new(execfakes.FakeGetDelegate) fakeDelegate.InputDelegateReturns(fakeGetDelegate) plan = atc.Plan{ Location: nil, Get: &atc.GetPlan{ Name: "some input", }, } })
repo *exec.SourceRepository onSuccessFactory exec.StepFactory onSuccessStep exec.Step ) BeforeEach(func() { stepFactory = &fakes.FakeStepFactory{} successFactory = &fakes.FakeStepFactory{} step = &fakes.FakeStep{} hook = &fakes.FakeStep{} previousStep = &fakes.FakeStep{} stepFactory.UsingReturns(step) successFactory.UsingReturns(hook) repo = exec.NewSourceRepository() onSuccessFactory = exec.OnSuccess(stepFactory, successFactory) onSuccessStep = onSuccessFactory.Using(previousStep, repo) }) It("runs the success hook if the step succeeds", func() { step.ResultStub = successResult(true) process := ifrit.Background(onSuccessStep) Eventually(step.RunCallCount).Should(Equal(1)) Eventually(hook.RunCallCount).Should(Equal(1))
repo *exec.SourceRepository onFailureFactory exec.StepFactory onFailureStep exec.Step ) BeforeEach(func() { stepFactory = &fakes.FakeStepFactory{} failureFactory = &fakes.FakeStepFactory{} step = &fakes.FakeStep{} hook = &fakes.FakeStep{} previousStep = &fakes.FakeStep{} stepFactory.UsingReturns(step) failureFactory.UsingReturns(hook) repo = exec.NewSourceRepository() onFailureFactory = exec.OnFailure(stepFactory, failureFactory) onFailureStep = onFailureFactory.Using(previousStep, repo) }) It("runs the failure hook if step fails", func() { step.ResultStub = successResult(false) process := ifrit.Background(onFailureStep) Eventually(step.RunCallCount).Should(Equal(1)) Eventually(hook.RunCallCount).Should(Equal(1))
outStep *fakes.FakeStep step Step process ifrit.Process ) BeforeEach(func() { inStep = new(fakes.FakeStep) repo = NewSourceRepository() fakeStepFactory = new(fakes.FakeStepFactory) outStep = new(fakes.FakeStep) outStep.ResultStub = successResult(true) fakeStepFactory.UsingReturns(outStep) conditional = Conditional{ StepFactory: fakeStepFactory, } }) JustBeforeEach(func() { step = conditional.Using(inStep, repo) process = ifrit.Invoke(step) }) itDoesNothing := func() { It("succeeds", func() { Eventually(process.Wait()).Should(Receive(BeNil())) })
runStep *fakes.FakeStep timeout StepFactory step Step startStep chan error process ifrit.Process timeoutDuration atc.Duration ) BeforeEach(func() { startStep = make(chan error, 1) fakeStepFactoryStep = new(fakes.FakeStepFactory) runStep = new(fakes.FakeStep) fakeStepFactoryStep.UsingReturns(runStep) }) JustBeforeEach(func() { timeout = Timeout(fakeStepFactoryStep, timeoutDuration) step = timeout.Using(nil, nil) process = ifrit.Background(step) }) Context("when the process goes beyond the duration", func() { BeforeEach(func() { runStep.ResultStub = successResult(true) timeoutDuration = atc.Duration(1 * time.Second) runStep.RunStub = func(signals <-chan os.Signal, ready chan<- struct{}) error {
) BeforeEach(func() { fakeStepA = new(fakes.FakeStepFactory) fakeStepB = new(fakes.FakeStepFactory) aggregate = Aggregate{ fakeStepA, fakeStepB, } inStep = new(fakes.FakeStep) repo = NewSourceRepository() outStepA = new(fakes.FakeStep) fakeStepA.UsingReturns(outStepA) outStepB = new(fakes.FakeStep) fakeStepB.UsingReturns(outStepB) }) JustBeforeEach(func() { step = aggregate.Using(inStep, repo) process = ifrit.Invoke(step) }) It("uses the input source for all steps", func() { Ω(fakeStepA.UsingCallCount()).Should(Equal(1)) step, repo := fakeStepA.UsingArgsForCall(0) Ω(step).Should(Equal(inStep)) Ω(repo).Should(Equal(repo))
}) Context("running timeout steps", func() { var ( taskStepFactory *execfakes.FakeStepFactory taskStep *execfakes.FakeStep inputStepFactory *execfakes.FakeStepFactory inputStep *execfakes.FakeStep ) BeforeEach(func() { taskStepFactory = new(execfakes.FakeStepFactory) taskStep = new(execfakes.FakeStep) taskStep.ResultStub = successResult(true) taskStepFactory.UsingReturns(taskStep) fakeFactory.TaskReturns(taskStepFactory) inputStepFactory = new(execfakes.FakeStepFactory) inputStep = new(execfakes.FakeStep) inputStep.ResultStub = successResult(true) inputStepFactory.UsingReturns(inputStep) fakeFactory.GetReturns(inputStepFactory) }) Context("constructing steps", func() { var ( fakeDelegate *fakes.FakeBuildDelegate fakeInputDelegate *execfakes.FakeGetDelegate timeout string )
startNextStep chan error finishNextStep chan error step Step process ifrit.Process ) BeforeEach(func() { fakeStepFactoryStep = new(fakes.FakeStepFactory) fakeStepFactoryNextStep = new(fakes.FakeStepFactory) inStep = new(fakes.FakeStep) repo = NewSourceRepository() outStep = new(fakes.FakeStep) fakeStepFactoryStep.UsingReturns(outStep) nextStep = new(fakes.FakeStep) fakeStepFactoryNextStep.UsingReturns(nextStep) startStep = make(chan error, 1) finishStep = make(chan error, 1) startNextStep = make(chan error, 1) finishNextStep = make(chan error, 1) outStep.ResultStub = successResult(true) outStep.RunStub = func(signals <-chan os.Signal, ready chan<- struct{}) error { select { case err := <-startStep: if err != nil {
step Step process ifrit.Process ) BeforeEach(func() { fakeStepFactoryA = new(fakes.FakeStepFactory) fakeStepFactoryB = new(fakes.FakeStepFactory) compose = Compose(fakeStepFactoryA, fakeStepFactoryB) inStep = new(fakes.FakeStep) repo = NewSourceRepository() outStepA = new(fakes.FakeStep) fakeStepFactoryA.UsingReturns(outStepA) outStepB = new(fakes.FakeStep) fakeStepFactoryB.UsingReturns(outStepB) startA = make(chan error, 1) finishA = make(chan error, 1) startB = make(chan error, 1) finishB = make(chan error, 1) outStepA.RunStub = func(signals <-chan os.Signal, ready chan<- struct{}) error { select { case err := <-startA: if err != nil { return err