Expect(containerDelegate.DeleteContainerCallCount()).To(Equal(0))
					})

					It("does not try to run the container", func() {
						Expect(containerDelegate.RunContainerCallCount()).To(Equal(0))
					})
				})

				Context("when claiming succeeds", func() {
					It("runs the container", func() {
						Expect(containerDelegate.RunContainerCallCount()).To(Equal(1))

						expectedRunRequest, err := rep.NewRunRequestFromDesiredLRP(container.Guid, desiredLRP, &expectedLrpKey, &expectedInstanceKey)
						Expect(err).NotTo(HaveOccurred())

						delegateLogger, runRequest := containerDelegate.RunContainerArgsForCall(0)
						Expect(*runRequest).To(Equal(expectedRunRequest))
						Expect(delegateLogger.SessionName()).To(Equal(expectedSessionName))
					})

					Context("when running fails", func() {
						BeforeEach(func() {
							containerDelegate.RunContainerReturns(false)
						})

						It("removes the actual LRP", func() {
							Expect(bbsClient.RemoveActualLRPCallCount()).To(Equal(1))
							processGuid, index := bbsClient.RemoveActualLRPArgsForCall(0)

							Expect(processGuid).To(Equal(expectedLrpKey.ProcessGuid))
							Expect(int32(index)).To(Equal(expectedLrpKey.Index))
Exemple #2
0
		})
	}

	itRunsTheContainer := func(logger *lagertest.TestLogger) {
		itSetsTheTaskToRunning(logger)

		It("runs the container", func() {
			Expect(containerDelegate.RunContainerCallCount()).To(Equal(1))

			task, err := bbsClient.TaskByGuid(taskGuid)
			Expect(err).NotTo(HaveOccurred())

			expectedRunRequest, err := rep.NewRunRequestFromTask(task)
			Expect(err).NotTo(HaveOccurred())

			_, runRequest := containerDelegate.RunContainerArgsForCall(0)
			Expect(*runRequest).To(Equal(expectedRunRequest))
		})

		Context("when running the container fails", func() {
			BeforeEach(func() {
				containerDelegate.RunContainerReturns(false)
			})

			itCompletesTheTaskWithFailure("failed to run container")(logger)
		})
	}

	itDoesNothing := func(logger *lagertest.TestLogger) {
		It("does not run the container", func() {
			Expect(containerDelegate.RunContainerCallCount()).To(Equal(0))