It("tries to find stemcell with given stemcell cid", func() { stemcellFinder.FindFound = true vmCreator.CreateVM = fakevm.NewFakeVM(1234) _, err := action.Run("fake-agent-id", stemcellCID, vmCloudProp, networks, diskLocality, env) Expect(err).ToNot(HaveOccurred()) }) 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("returns id for created VM", func() { vmCreator.CreateVM = fakevm.NewFakeVM(1234) id, err := action.Run("fake-agent-id", stemcellCID, vmCloudProp, networks, diskLocality, env) Expect(err).ToNot(HaveOccurred()) Expect(id).To(Equal(VMCID(1234))) }) It("creates VM with requested agent ID, stemcell, cloud properties, and networks", func() { vmCreator.CreateVM = fakevm.NewFakeVM(1234) _, err := action.Run("fake-agent-id", stemcellCID, vmCloudProp, networks, diskLocality, env)
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))) }) 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))) }) })