It("invokes the delegate's Failed callback", func() { Eventually(process.Wait()).Should(Receive(HaveOccurred())) Ω(taskDelegate.FailedCallCount()).Should(Equal(1)) err := taskDelegate.FailedArgsForCall(0) Ω(err).Should(BeAssignableToTypeOf(MissingInputsError{})) Ω(err.(MissingInputsError).Inputs).Should(ConsistOf("some-other-input")) }) }) }) Context("when the process exits 0", func() { BeforeEach(func() { fakeProcess.WaitReturns(0, nil) }) It("saves the exit status property", func() { Eventually(process.Wait()).Should(Receive(BeNil())) Ω(fakeContainer.SetPropertyCallCount()).Should(Equal(2)) name, value := fakeContainer.SetPropertyArgsForCall(1) Ω(name).Should(Equal("concourse:exit-status")) Ω(value).Should(Equal("0")) }) It("is successful", func() { Eventually(process.Wait()).Should(Receive(BeNil()))
}) It("returns the error", func() { _, err := container.CurrentMemoryLimits() Ω(err).Should(Equal(disaster)) }) }) }) Describe("Run", func() { It("sends a run request and returns the process id and a stream", func() { fakeConnection.RunStub = func(handle string, spec garden.ProcessSpec, io garden.ProcessIO) (garden.Process, error) { process := new(wfakes.FakeProcess) process.IDReturns(42) process.WaitReturns(123, nil) go func() { defer GinkgoRecover() _, err := fmt.Fprintf(io.Stdout, "stdout data") Ω(err).ShouldNot(HaveOccurred()) _, err = fmt.Fprintf(io.Stderr, "stderr data") Ω(err).ShouldNot(HaveOccurred()) }() return process, nil } spec := garden.ProcessSpec{
Context("when the container is not found", func() { It("fails", func() { serverBackend.LookupReturns(nil, errors.New("not found")) _, err := container.Attach(123, garden.ProcessIO{}) Ω(err).Should(HaveOccurred()) }) }) Context("when waiting on the process fails server-side", func() { BeforeEach(func() { fakeContainer.AttachStub = func(id uint32, io garden.ProcessIO) (garden.Process, error) { process := new(fakes.FakeProcess) process.IDReturns(42) process.WaitReturns(0, errors.New("oh no!")) return process, nil } }) It("bubbles the error up", func() { process, err := container.Attach(42, garden.ProcessIO{}) Ω(err).ShouldNot(HaveOccurred()) _, err = process.Wait() Ω(err).Should(HaveOccurred()) Ω(err.Error()).Should(ContainSubstring("oh no!")) }) })
var oldContainer *gardenFakes.FakeContainer var fakeProcess *gardenFakes.FakeProcess BeforeEach(func() { fakeContainer = &gardenFakes.FakeContainer{} oldContainer = &gardenFakes.FakeContainer{} oldContainer.HandleReturns("old-guid") fakeProcess = &gardenFakes.FakeProcess{} }) Context("When garden is healthy", func() { BeforeEach(func() { gardenClient.CreateReturns(fakeContainer, nil) gardenClient.ContainersReturns([]garden.Container{oldContainer}, nil) fakeContainer.RunReturns(fakeProcess, nil) fakeProcess.WaitReturns(0, nil) }) It("drives a container lifecycle", func() { err := gardenChecker.Healthcheck(logger) By("Fetching any pre-existing healthcheck containers") Expect(gardenClient.ContainersCallCount()).To(Equal(1)) By("Deleting all pre-existing-containers") //call count is two because we also expect to destroy the container we create Expect(gardenClient.DestroyCallCount()).To(Equal(2)) guid := gardenClient.DestroyArgsForCall(0) Expect(guid).To(Equal("old-guid")) By("Creates the container")
portMappings, exportNetworkEnvVars, fakeClock, ) }) Describe("Perform", func() { var stepErr error JustBeforeEach(func() { stepErr = step.Perform() }) Context("when the script succeeds", func() { BeforeEach(func() { spawnedProcess.WaitReturns(0, nil) }) It("does not return an error", func() { Expect(stepErr).NotTo(HaveOccurred()) }) It("executes the command in the passed-in container", func() { ranHandle, spec, _ := gardenClient.Connection.RunArgsForCall(0) Expect(ranHandle).To(Equal(handle)) Expect(spec.Path).To(Equal("sudo")) Expect(spec.Args).To(Equal([]string{"reboot"})) Expect(spec.Dir).To(Equal("/some-dir")) Expect(*spec.Limits.Nofile).To(BeNumerically("==", fileDescriptorLimit)) Expect(spec.Env).To(ContainElement("A=1")) Expect(spec.Env).To(ContainElement("B=2"))
It("forwards the error to the response", func() { var hijackOutput atc.HijackOutput err := conn.ReadJSON(&hijackOutput) Expect(err).NotTo(HaveOccurred()) Expect(hijackOutput).To(Equal(atc.HijackOutput{ Error: "oh no!", })) }) }) }) Context("when waiting on the process fails", func() { BeforeEach(func() { fakeProcess.WaitReturns(0, errors.New("oh no!")) }) It("forwards the error to the response", func() { var hijackOutput atc.HijackOutput err := conn.ReadJSON(&hijackOutput) Expect(err).NotTo(HaveOccurred()) Expect(hijackOutput).To(Equal(atc.HijackOutput{ Error: "oh no!", })) }) }) }) })