github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/domain_test.go (about) 1 package requirements_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/apifakes" 5 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 6 "code.cloudfoundry.org/cli/cf/errors" 7 "code.cloudfoundry.org/cli/cf/models" 8 . "code.cloudfoundry.org/cli/cf/requirements" 9 testconfig "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("DomainRequirement", func() { 15 var config coreconfig.ReadWriter 16 17 BeforeEach(func() { 18 config = testconfig.NewRepository() 19 config.SetOrganizationFields(models.OrganizationFields{GUID: "the-org-guid"}) 20 }) 21 22 It("succeeds when the domain is found", func() { 23 domain := models.DomainFields{Name: "example.com", GUID: "domain-guid"} 24 domainRepo := new(apifakes.FakeDomainRepository) 25 domainRepo.FindByNameInOrgReturns(domain, nil) 26 domainReq := NewDomainRequirement("example.com", config, domainRepo) 27 err := domainReq.Execute() 28 29 Expect(err).NotTo(HaveOccurred()) 30 orgName, orgGUID := domainRepo.FindByNameInOrgArgsForCall(0) 31 Expect(orgName).To(Equal("example.com")) 32 Expect(orgGUID).To(Equal("the-org-guid")) 33 Expect(domainReq.GetDomain()).To(Equal(domain)) 34 }) 35 36 It("fails when the domain is not found", func() { 37 domainRepo := new(apifakes.FakeDomainRepository) 38 domainRepo.FindByNameInOrgReturns(models.DomainFields{}, errors.NewModelNotFoundError("Domain", "")) 39 domainReq := NewDomainRequirement("example.com", config, domainRepo) 40 41 err := domainReq.Execute() 42 Expect(err).To(HaveOccurred()) 43 Expect(err.Error()).To(ContainSubstring("Domain")) 44 Expect(err.Error()).To(ContainSubstring("not found")) 45 }) 46 47 It("fails when an error occurs fetching the domain", func() { 48 domainRepo := new(apifakes.FakeDomainRepository) 49 domainRepo.FindByNameInOrgReturns(models.DomainFields{}, errors.New("an-error")) 50 domainReq := NewDomainRequirement("example.com", config, domainRepo) 51 52 err := domainReq.Execute() 53 Expect(err).To(HaveOccurred()) 54 Expect(err.Error()).To(ContainSubstring("an-error")) 55 }) 56 })