예제 #1
0
				Context("when the error is not emittable", func() {
					BeforeEach(func() {
						substepPerformError = errors.New("some error")
					})

					It("returns a timeout error which does not include the error returned by the substep", func() {
						Expect(err).To(HaveOccurred())
						Expect(err).To(BeAssignableToTypeOf(&steps.EmittableError{}))
						Expect(err.Error()).NotTo(ContainSubstring("some error"))
						Expect(err.(*steps.EmittableError).WrappedError()).To(Equal(substepPerformError))
					})
				})

				Context("when the error is emittable", func() {
					BeforeEach(func() {
						substepPerformError = steps.NewEmittableError(nil, "some error")
					})

					It("returns a timeout error which includes the error returned by the substep", func() {
						Expect(err).To(HaveOccurred())
						Expect(err).To(BeAssignableToTypeOf(&steps.EmittableError{}))
						Expect(err.Error()).To(ContainSubstring("some error"))
						Expect(err.(*steps.EmittableError).WrappedError()).To(Equal(substepPerformError))
					})
				})
			})
		})
	})

	Describe("Cancel", func() {
		It("cancels the nested step", func() {
예제 #2
0
import (
	"errors"

	"github.com/cloudfoundry-incubator/executor/depot/steps"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EmittableError", func() {
	wrappedError := errors.New("the wrapped error")

	It("should satisfy the error interface", func() {
		var err error
		err = steps.NewEmittableError(wrappedError, "Fancy")
		Expect(err).To(HaveOccurred())
	})

	Describe("WrappedError", func() {
		It("returns the wrapped error message", func() {
			err := steps.NewEmittableError(wrappedError, "Fancy emittable message")
			Expect(err.WrappedError()).To(Equal(wrappedError))
		})

		Context("when the wrapped error is nil", func() {
			It("should not blow up", func() {
				err := steps.NewEmittableError(nil, "Fancy emittable message")
				Expect(err.WrappedError()).To(BeNil())
			})
		})
예제 #3
0
					"test.upload-step.failed-to-parse-url",
				}))

			})
		})

		Context("when there is an error initiating the stream", func() {
			errStream := errors.New("stream error")

			BeforeEach(func() {
				gardenClient.Connection.StreamOutReturns(nil, errStream)
			})

			It("returns the appropriate error", func() {
				err := step.Perform()
				Expect(err).To(MatchError(steps.NewEmittableError(errStream, steps.ErrEstablishStream)))
			})

			It("logs the step", func() {
				err := step.Perform()
				Expect(err).To(HaveOccurred())
				Expect(logger.TestSink.LogMessages()).To(ConsistOf([]string{
					"test.upload-step.upload-starting",
					"test.upload-step.failed-to-stream-out",
				}))

			})
		})

		Context("when there is an error in reading the data from the stream", func() {
			errStream := errors.New("stream error")
예제 #4
0
			Context("and there is a failure message", func() {
				BeforeEach(func() {
					failureMessage = "FAIL"
				})

				It("should emit the failure message", func() {
					step.Perform()

					Expect(stdoutBuffer.String()).To(Equal("RUNNING\n"))
					Expect(stderrBuffer.String()).To(Equal("FAIL\n"))
				})

				Context("with an emittable error", func() {
					BeforeEach(func() {
						errorToReturn = steps.NewEmittableError(errors.New("bam!"), "Failed to reticulate")
					})

					It("should print out the emittable error", func() {
						step.Perform()

						Expect(stdoutBuffer.String()).To(Equal("RUNNING\n"))
						Expect(stderrBuffer.String()).To(Equal("FAIL: Failed to reticulate\n"))
					})

					It("logs the error", func() {
						step.Perform()

						logs := logger.TestSink.Logs()
						Expect(logs).To(HaveLen(1))
예제 #5
0
				spawnedProcess.WaitReturns(0, nil)
			})

			It("does not enforce it on the process", func() {
				_, spec, _ := gardenClient.Connection.RunArgsForCall(0)
				Expect(spec.Limits.Nofile).To(BeNil())
			})
		})

		Context("when the script has a non-zero exit code", func() {
			BeforeEach(func() {
				spawnedProcess.WaitReturns(19, nil)
			})

			It("should return an emittable error with the exit code", func() {
				Expect(stepErr).To(MatchError(steps.NewEmittableError(nil, "Exited with status 19")))
			})
		})

		Context("when Garden errors", func() {
			disaster := errors.New("I, like, tried but failed")

			BeforeEach(func() {
				runError = disaster
			})

			It("returns the error", func() {
				Expect(stepErr).To(Equal(disaster))
			})

			It("logs the step", func() {