Expect(actualResourceTypes).To(Equal(resourceTypes)) Expect(workerC.SatisfyingCallCount()).To(Equal(1)) actualSpec, actualResourceTypes = workerC.SatisfyingArgsForCall(0) Expect(actualSpec).To(Equal(spec.WorkerSpec())) Expect(actualResourceTypes).To(Equal(resourceTypes)) }) It("creates using a random worker", func() { for i := 1; i < 100; i++ { // account for initial create in JustBefore createdContainer, createErr := pool.CreateContainer(logger, nil, fakeImageFetchingDelegate, id, Metadata{}, spec, resourceTypes) Expect(createErr).NotTo(HaveOccurred()) Expect(createdContainer).To(Equal(fakeContainer)) } Expect(workerA.CreateContainerCallCount()).To(BeNumerically("~", workerB.CreateContainerCallCount(), 50)) Expect(workerC.CreateContainerCallCount()).To(BeZero()) }) Context("when creating the container fails", func() { disaster := errors.New("nope") BeforeEach(func() { workerA.CreateContainerReturns(nil, disaster) workerB.CreateContainerReturns(nil, disaster) }) It("returns the error", func() { Expect(createErr).To(Equal(disaster)) }) })
It("looked for the sources on the correct worker", func() { Expect(inputSource1.VolumeOnCallCount()).To(Equal(1)) actualWorker := inputSource1.VolumeOnArgsForCall(0) Expect(actualWorker).To(Equal(satisfyingWorker)) Expect(inputSource2.VolumeOnCallCount()).To(Equal(1)) actualWorker = inputSource2.VolumeOnArgsForCall(0) Expect(actualWorker).To(Equal(satisfyingWorker)) Expect(inputSource3.VolumeOnCallCount()).To(Equal(1)) actualWorker = inputSource3.VolumeOnArgsForCall(0) Expect(actualWorker).To(Equal(satisfyingWorker)) }) It("creates the container with the cache volume", func() { Expect(satisfyingWorker.CreateContainerCallCount()).To(Equal(1)) _, id, spec := satisfyingWorker.CreateContainerArgsForCall(0) Expect(id).To(Equal(session.ID)) resourceSpec := spec.(worker.ResourceTypeContainerSpec) Expect(resourceSpec.Type).To(Equal(string(initType))) Expect(resourceSpec.Env).To(Equal([]string{"a=1", "b=2"})) Expect(resourceSpec.Ephemeral).To(BeTrue()) Expect(resourceSpec.Tags).To(ConsistOf("resource", "tags")) Expect(resourceSpec.Mounts).To(ConsistOf([]worker.VolumeMount{ { Volume: inputVolume1, MountPath: "/tmp/build/put/source-1-name", }, {
Ω(workerB.SatisfiesCallCount()).Should(Equal(1)) Ω(workerB.SatisfiesArgsForCall(0)).Should(Equal(spec)) Ω(workerC.SatisfiesCallCount()).Should(Equal(1)) Ω(workerC.SatisfiesArgsForCall(0)).Should(Equal(spec)) }) It("creates using a random worker", func() { for i := 1; i < 100; i++ { // account for initial create in JustBefore createdContainer, createErr := pool.CreateContainer(id, spec) Ω(createErr).ShouldNot(HaveOccurred()) Ω(createdContainer).Should(Equal(fakeContainer)) } Ω(workerA.CreateContainerCallCount()).Should(BeNumerically("~", workerB.CreateContainerCallCount(), 50)) Ω(workerC.CreateContainerCallCount()).Should(BeZero()) }) Context("when creating the container fails", func() { disaster := errors.New("nope") BeforeEach(func() { workerA.CreateContainerReturns(nil, disaster) workerB.CreateContainerReturns(nil, disaster) }) It("returns the error", func() { Ω(createErr).Should(Equal(disaster)) }) })