コード例 #1
0
	Describe("Run", func() {
		It("tries to find stemcell with given stemcell cid", func() {
			_, err := action.Run(1234)
			Expect(err).ToNot(HaveOccurred())

			Expect(stemcellFinder.FindID).To(Equal(1234))
		})

		Context("when stemcell is found with given stemcell cid", func() {
			var (
				stemcell *fakestem.FakeStemcell
			)

			BeforeEach(func() {
				stemcell = fakestem.NewFakeStemcell(1234, "fake-stemcell-id", fakestem.FakeStemcellKind)
				stemcellFinder.FindStemcell = stemcell
				stemcellFinder.FindFound = true
			})

			It("does not delete stemcell", func() {
				_, err := action.Run(1234)
				Expect(err).ToNot(HaveOccurred())

				Expect(stemcell.DeleteCalled).To(BeFalse())
			})

			It("logs instead of returning error if deleting stemcell fails", func() {
				stemcell.DeleteErr = errors.New("fake-delete-err")

				_, err := action.Run(1234)
				Expect(err).ToNot(HaveOccurred())
コード例 #2
0
var _ = Describe("CreateStemcell", func() {
	var (
		stemcellFinder *fakestem.FakeFinder
		action         CreateStemcell
	)

	BeforeEach(func() {
		stemcellFinder = &fakestem.FakeFinder{}
		action = NewCreateStemcell(stemcellFinder)
	})

	Describe("Run", func() {
		It("returns id for created stemcell from image path", func() {
			stemcellFinder.FindFound, stemcellFinder.FindErr = true, nil
			stemcellFinder.FindStemcell = fakestem.NewFakeStemcell(1234, "fake-stemcell-id", fakestem.FakeStemcellKind)

			id, err := action.Run("fake-path", CreateStemcellCloudProps{Uuid: "fake-stemcell-id"})
			Expect(err).ToNot(HaveOccurred())
			Expect(id).To(Equal(StemcellCID(1234).String()))
		})

		It("returns error if creating stemcell fails", func() {
			stemcellFinder.FindFound, stemcellFinder.FindErr = false, errors.New("fake-add-err")

			id, err := action.Run("fake-path", CreateStemcellCloudProps{Uuid: "fake-stemcell-id"})
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-add-err"))
			Expect(id).To(Equal(StemcellCID(0).String()))
		})
	})