github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/domain_test.go (about) 1 package requirements_test 2 3 import ( 4 testapi "github.com/cloudfoundry/cli/cf/api/fakes" 5 "github.com/cloudfoundry/cli/cf/configuration/core_config" 6 "github.com/cloudfoundry/cli/cf/errors" 7 "github.com/cloudfoundry/cli/cf/models" 8 . "github.com/cloudfoundry/cli/cf/requirements" 9 testassert "github.com/cloudfoundry/cli/testhelpers/assert" 10 testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" 11 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("DomainRequirement", func() { 17 var config core_config.ReadWriter 18 var ui *testterm.FakeUI 19 20 BeforeEach(func() { 21 ui = new(testterm.FakeUI) 22 config = testconfig.NewRepository() 23 config.SetOrganizationFields(models.OrganizationFields{Guid: "the-org-guid"}) 24 }) 25 26 It("succeeds when the domain is found", func() { 27 domain := models.DomainFields{Name: "example.com", Guid: "domain-guid"} 28 domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgDomain: []models.DomainFields{domain}} 29 domainReq := NewDomainRequirement("example.com", ui, config, domainRepo) 30 success := domainReq.Execute() 31 32 Expect(success).To(BeTrue()) 33 Expect(domainRepo.FindByNameInOrgName).To(Equal("example.com")) 34 Expect(domainRepo.FindByNameInOrgGuid).To(Equal("the-org-guid")) 35 Expect(domainReq.GetDomain()).To(Equal(domain)) 36 }) 37 38 It("fails when the domain is not found", func() { 39 domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgApiResponse: errors.NewModelNotFoundError("Domain", "")} 40 domainReq := NewDomainRequirement("example.com", ui, config, domainRepo) 41 42 testassert.AssertPanic(testterm.QuietPanic, func() { 43 domainReq.Execute() 44 }) 45 }) 46 47 It("fails when an error occurs fetching the domain", func() { 48 domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgApiResponse: errors.NewWithError("", errors.New(""))} 49 domainReq := NewDomainRequirement("example.com", ui, config, domainRepo) 50 51 testassert.AssertPanic(testterm.QuietPanic, func() { 52 domainReq.Execute() 53 }) 54 }) 55 })