github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/commands/organization/set_quota_test.go (about) 1 package organization_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/quotas/quotasfakes" 5 "code.cloudfoundry.org/cli/cf/commandregistry" 6 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 7 "code.cloudfoundry.org/cli/cf/models" 8 "code.cloudfoundry.org/cli/cf/requirements" 9 "code.cloudfoundry.org/cli/cf/requirements/requirementsfakes" 10 testcmd "code.cloudfoundry.org/cli/cf/util/testhelpers/commands" 11 testconfig "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration" 12 testterm "code.cloudfoundry.org/cli/cf/util/testhelpers/terminal" 13 14 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 ) 18 19 var _ = Describe("set-quota command", func() { 20 var ( 21 ui *testterm.FakeUI 22 quotaRepo *quotasfakes.FakeQuotaRepository 23 requirementsFactory *requirementsfakes.FakeFactory 24 configRepo coreconfig.Repository 25 deps commandregistry.Dependency 26 ) 27 28 updateCommandDependency := func(pluginCall bool) { 29 deps.UI = ui 30 deps.Config = configRepo 31 deps.RepoLocator = deps.RepoLocator.SetQuotaRepository(quotaRepo) 32 commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("set-quota").SetDependency(deps, pluginCall)) 33 } 34 35 runCommand := func(args ...string) bool { 36 return testcmd.RunCLICommand("set-quota", args, requirementsFactory, updateCommandDependency, false, ui) 37 } 38 39 BeforeEach(func() { 40 ui = new(testterm.FakeUI) 41 quotaRepo = new(quotasfakes.FakeQuotaRepository) 42 configRepo = testconfig.NewRepositoryWithDefaults() 43 requirementsFactory = new(requirementsfakes.FakeFactory) 44 }) 45 46 It("fails with usage when provided too many or two few args", func() { 47 runCommand("org") 48 Expect(ui.Outputs()).To(ContainSubstrings( 49 []string{"Incorrect Usage", "Requires", "arguments"}, 50 )) 51 52 runCommand("org", "quota", "extra-stuff") 53 Expect(ui.Outputs()).To(ContainSubstrings( 54 []string{"Incorrect Usage", "Requires", "arguments"}, 55 )) 56 57 }) 58 59 It("fails requirements when not logged in", func() { 60 requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) 61 Expect(runCommand("my-org", "my-quota")).To(BeFalse()) 62 }) 63 64 Context("when logged in", func() { 65 BeforeEach(func() { 66 org := models.Organization{} 67 org.Name = "my-org" 68 org.GUID = "my-org-guid" 69 orgReq := new(requirementsfakes.FakeOrganizationRequirement) 70 orgReq.GetOrganizationReturns(org) 71 requirementsFactory.NewOrganizationRequirementReturns(orgReq) 72 73 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 74 }) 75 76 It("assigns a quota to an org", func() { 77 quota := models.QuotaFields{Name: "my-quota", GUID: "my-quota-guid"} 78 quotaRepo.FindByNameReturns(quota, nil) 79 80 runCommand("my-org", "my-quota") 81 82 Expect(ui.Outputs()).To(ContainSubstrings( 83 []string{"Setting quota", "my-quota", "my-org", "my-user"}, 84 []string{"OK"}, 85 )) 86 87 Expect(quotaRepo.FindByNameArgsForCall(0)).To(Equal("my-quota")) 88 orgGUID, quotaGUID := quotaRepo.AssignQuotaToOrgArgsForCall(0) 89 Expect(orgGUID).To(Equal("my-org-guid")) 90 Expect(quotaGUID).To(Equal("my-quota-guid")) 91 }) 92 }) 93 })