github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/organization_test.go (about) 1 package requirements_test 2 3 import ( 4 "errors" 5 6 test_org "github.com/cloudfoundry/cli/cf/api/organizations/fakes" 7 "github.com/cloudfoundry/cli/cf/models" 8 . "github.com/cloudfoundry/cli/cf/requirements" 9 testassert "github.com/cloudfoundry/cli/testhelpers/assert" 10 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("OrganizationRequirement", func() { 16 var ( 17 ui *testterm.FakeUI 18 ) 19 20 BeforeEach(func() { 21 ui = new(testterm.FakeUI) 22 }) 23 24 Context("when an org with the given name exists", func() { 25 It("succeeds", func() { 26 org := models.Organization{} 27 org.Name = "my-org-name" 28 org.Guid = "my-org-guid" 29 orgRepo := &test_org.FakeOrganizationRepository{} 30 orgReq := NewOrganizationRequirement("my-org-name", ui, orgRepo) 31 32 orgRepo.ListOrgsReturns([]models.Organization{org}, nil) 33 orgRepo.FindByNameReturns(org, nil) 34 35 Expect(orgReq.Execute()).To(BeTrue()) 36 Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-org-name")) 37 Expect(orgReq.GetOrganization()).To(Equal(org)) 38 }) 39 }) 40 41 It("fails when the org with the given name does not exist", func() { 42 orgRepo := &test_org.FakeOrganizationRepository{} 43 44 orgRepo.FindByNameReturns(models.Organization{}, errors.New("not found")) 45 46 testassert.AssertPanic(testterm.QuietPanic, func() { 47 NewOrganizationRequirement("foo", ui, orgRepo).Execute() 48 }) 49 }) 50 })