github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/diego_application_test.go (about) 1 package requirements_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/cf/models" 7 "code.cloudfoundry.org/cli/cf/requirements" 8 9 "code.cloudfoundry.org/cli/cf/api/applications/applicationsfakes" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("DiegoApplication", func() { 16 var ( 17 req requirements.DiegoApplicationRequirement 18 appRepo *applicationsfakes.FakeRepository 19 appName string 20 ) 21 22 BeforeEach(func() { 23 appName = "fake-app-name" 24 appRepo = new(applicationsfakes.FakeRepository) 25 req = requirements.NewDiegoApplicationRequirement(appName, appRepo) 26 }) 27 28 Describe("GetApplication", func() { 29 It("returns an empty application", func() { 30 Expect(req.GetApplication()).To(Equal(models.Application{})) 31 }) 32 33 Context("when the requirement has been executed", func() { 34 BeforeEach(func() { 35 app := models.Application{} 36 app.Diego = true 37 app.GUID = "fake-app-guid" 38 appRepo.ReadReturns(app, nil) 39 40 Expect(req.Execute()).ToNot(HaveOccurred()) 41 }) 42 43 It("returns the application", func() { 44 Expect(req.GetApplication().GUID).To(Equal("fake-app-guid")) 45 }) 46 }) 47 }) 48 49 Describe("Execute", func() { 50 Context("when the returned application is a DEA application", func() { 51 BeforeEach(func() { 52 app := models.Application{} 53 app.Diego = false 54 appRepo.ReadReturns(app, nil) 55 }) 56 57 It("fails with error", func() { 58 err := req.Execute() 59 Expect(err).To(HaveOccurred()) 60 Expect(err.Error()).To(ContainSubstring("The app is running on the DEA backend, which does not support this command.")) 61 }) 62 }) 63 64 Context("when the returned application is a Diego application", func() { 65 BeforeEach(func() { 66 app := models.Application{} 67 app.Diego = true 68 appRepo.ReadReturns(app, nil) 69 }) 70 71 It("succeeds", func() { 72 err := req.Execute() 73 Expect(err).NotTo(HaveOccurred()) 74 }) 75 }) 76 77 Context("when finding the application results in an error", func() { 78 BeforeEach(func() { 79 appRepo.ReadReturns(models.Application{}, errors.New("find-err")) 80 }) 81 82 It("fails with error", func() { 83 err := req.Execute() 84 Expect(err.Error()).To(ContainSubstring("find-err")) 85 }) 86 }) 87 }) 88 })