github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/application_test.go (about) 1 package requirements_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/applications/applicationsfakes" 5 "code.cloudfoundry.org/cli/cf/errors" 6 "code.cloudfoundry.org/cli/cf/models" 7 . "code.cloudfoundry.org/cli/cf/requirements" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("ApplicationRequirement", func() { 13 var appRepo *applicationsfakes.FakeRepository 14 15 BeforeEach(func() { 16 appRepo = new(applicationsfakes.FakeRepository) 17 }) 18 19 It("succeeds when an app with the given name exists", func() { 20 app := models.Application{} 21 app.Name = "my-app" 22 app.GUID = "my-app-guid" 23 appRepo.ReadReturns(app, nil) 24 25 appReq := NewApplicationRequirement("foo", appRepo) 26 27 err := appReq.Execute() 28 Expect(err).NotTo(HaveOccurred()) 29 30 Expect(appRepo.ReadArgsForCall(0)).To(Equal("foo")) 31 Expect(appReq.GetApplication()).To(Equal(app)) 32 }) 33 34 It("fails when an app with the given name cannot be found", func() { 35 appError := errors.NewModelNotFoundError("app", "foo") 36 appRepo.ReadReturns(models.Application{}, appError) 37 38 err := NewApplicationRequirement("foo", appRepo).Execute() 39 Expect(err).To(HaveOccurred()) 40 Expect(err).To(Equal(appError)) 41 }) 42 })