github.com/loafoe/cli@v7.1.0+incompatible/cf/requirements/organization_test.go (about) 1 package requirements_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/cf/api/organizations/organizationsfakes" 7 "code.cloudfoundry.org/cli/cf/models" 8 . "code.cloudfoundry.org/cli/cf/requirements" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("OrganizationRequirement", func() { 14 var orgRepo *organizationsfakes.FakeOrganizationRepository 15 BeforeEach(func() { 16 orgRepo = new(organizationsfakes.FakeOrganizationRepository) 17 }) 18 19 Context("when an org with the given name exists", func() { 20 It("succeeds", func() { 21 org := models.Organization{} 22 org.Name = "my-org-name" 23 org.GUID = "my-org-guid" 24 orgReq := NewOrganizationRequirement("my-org-name", orgRepo) 25 26 orgRepo.ListOrgsReturns([]models.Organization{org}, nil) 27 orgRepo.FindByNameReturns(org, nil) 28 29 err := orgReq.Execute() 30 Expect(err).NotTo(HaveOccurred()) 31 Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-org-name")) 32 Expect(orgReq.GetOrganization()).To(Equal(org)) 33 }) 34 }) 35 36 It("fails when the org with the given name does not exist", func() { 37 orgError := errors.New("not found") 38 orgRepo.FindByNameReturns(models.Organization{}, orgError) 39 40 err := NewOrganizationRequirement("foo", orgRepo).Execute() 41 Expect(err).To(HaveOccurred()) 42 Expect(err).To(Equal(orgError)) 43 }) 44 })