github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/service_instance_test.go (about) 1 package requirements_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/apifakes" 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("ServiceInstanceRequirement", func() { 13 var repo *apifakes.FakeServiceRepository 14 15 BeforeEach(func() { 16 repo = new(apifakes.FakeServiceRepository) 17 }) 18 19 Context("when a service instance with the given name can be found", func() { 20 It("succeeds", func() { 21 instance := models.ServiceInstance{} 22 instance.Name = "my-service" 23 instance.GUID = "my-service-guid" 24 repo.FindInstanceByNameReturns(instance, nil) 25 26 req := NewServiceInstanceRequirement("my-service", repo) 27 28 err := req.Execute() 29 Expect(err).NotTo(HaveOccurred()) 30 Expect(repo.FindInstanceByNameArgsForCall(0)).To(Equal("my-service")) 31 Expect(req.GetServiceInstance()).To(Equal(instance)) 32 }) 33 }) 34 35 Context("when a service instance with the given name can't be found", func() { 36 It("errors", func() { 37 repo.FindInstanceByNameReturns(models.ServiceInstance{}, errors.NewModelNotFoundError("Service instance", "my-service")) 38 err := NewServiceInstanceRequirement("foo", repo).Execute() 39 Expect(err).To(HaveOccurred()) 40 Expect(err.Error()).To(ContainSubstring("Service instance my-service not found")) 41 }) 42 }) 43 })