It("creates a build with the found inputs", func() { err := scheduler.BuildLatestInputs(logger, job, resources) Ω(err).ShouldNot(HaveOccurred()) Ω(fakePipelineDB.CreateJobBuildForCandidateInputsCallCount()).Should(Equal(1)) buildJob := fakePipelineDB.CreateJobBuildForCandidateInputsArgsForCall(0) Ω(buildJob).Should(Equal("some-job")) }) Context("when creating the build succeeds", func() { BeforeEach(func() { fakePipelineDB.CreateJobBuildForCandidateInputsReturns( db.Build{ ID: 128, Name: "42", }, true, nil, ) fakePipelineDB.GetNextPendingBuildReturns( db.Build{ ID: 128, Name: "42", }, nil, ) }) Context("and it can be scheduled", func() { BeforeEach(func() {
JustBeforeEach(func() { err = scheduler.BuildLatestInputs(logger, someVersions, job, resources, resourceTypes) }) Context("loading versions db", func() { BeforeEach(func() { pendingBuild := db.Build{ Status: db.StatusPending, } buildPrep := db.BuildPreparation{ Inputs: map[string]db.BuildPreparationStatus{}, } fakeBuildsDB.GetBuildPreparationReturns(buildPrep, true, nil) fakePipelineDB.CreateJobBuildForCandidateInputsReturns(pendingBuild, true, nil) fakePipelineDB.GetNextPendingBuildReturns(pendingBuild, true, nil) fakePipelineDB.GetNextPendingBuildBySerialGroupReturns(pendingBuild, true, nil) fakePipelineDB.UpdateBuildToScheduledReturns(true, nil) }) It("does not happen", func() { Expect(fakePipelineDB.LoadVersionsDBCallCount()).To(Equal(0)) }) }) It("checks if they are already used for a build", func() { Expect(err).NotTo(HaveOccurred()) Expect(fakePipelineDB.GetLatestInputVersionsCallCount()).To(Equal(1)) versions, jobName, inputs := fakePipelineDB.GetLatestInputVersionsArgsForCall(0)