github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/spacequota/unset_space_quota_test.go (about) 1 package spacequota_test 2 3 import ( 4 testapi "github.com/cloudfoundry/cli/cf/api/fakes" 5 "github.com/cloudfoundry/cli/cf/api/space_quotas/fakes" 6 "github.com/cloudfoundry/cli/cf/command_registry" 7 "github.com/cloudfoundry/cli/cf/configuration/core_config" 8 "github.com/cloudfoundry/cli/cf/models" 9 testcmd "github.com/cloudfoundry/cli/testhelpers/commands" 10 testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" 11 testreq "github.com/cloudfoundry/cli/testhelpers/requirements" 12 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 13 14 . "github.com/cloudfoundry/cli/testhelpers/matchers" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 ) 18 19 var _ = Describe("unset-space-quota command", func() { 20 var ( 21 ui *testterm.FakeUI 22 quotaRepo *fakes.FakeSpaceQuotaRepository 23 spaceRepo *testapi.FakeSpaceRepository 24 requirementsFactory *testreq.FakeReqFactory 25 configRepo core_config.Repository 26 deps command_registry.Dependency 27 ) 28 29 updateCommandDependency := func(pluginCall bool) { 30 deps.Ui = ui 31 deps.Config = configRepo 32 deps.RepoLocator = deps.RepoLocator.SetSpaceQuotaRepository(quotaRepo) 33 deps.RepoLocator = deps.RepoLocator.SetSpaceRepository(spaceRepo) 34 command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("unset-space-quota").SetDependency(deps, pluginCall)) 35 } 36 37 BeforeEach(func() { 38 ui = &testterm.FakeUI{} 39 configRepo = testconfig.NewRepositoryWithDefaults() 40 quotaRepo = &fakes.FakeSpaceQuotaRepository{} 41 spaceRepo = &testapi.FakeSpaceRepository{} 42 requirementsFactory = &testreq.FakeReqFactory{} 43 }) 44 45 runCommand := func(args ...string) bool { 46 return testcmd.RunCliCommand("unset-space-quota", args, requirementsFactory, updateCommandDependency, false) 47 } 48 49 It("fails with usage when provided too many or two few args", func() { 50 runCommand("space") 51 Expect(ui.Outputs).To(ContainSubstrings( 52 []string{"Incorrect Usage", "Requires", "arguments"}, 53 )) 54 55 runCommand("space", "quota", "extra-stuff") 56 Expect(ui.Outputs).To(ContainSubstrings( 57 []string{"Incorrect Usage", "Requires", "arguments"}, 58 )) 59 }) 60 61 Describe("requirements", func() { 62 It("requires the user to be logged in", func() { 63 requirementsFactory.LoginSuccess = false 64 65 Expect(runCommand("space", "quota")).To(BeFalse()) 66 }) 67 68 It("requires the user to target an org", func() { 69 requirementsFactory.TargetedOrgSuccess = false 70 71 Expect(runCommand("space", "quota")).To(BeFalse()) 72 }) 73 }) 74 75 Context("when requirements are met", func() { 76 BeforeEach(func() { 77 requirementsFactory.LoginSuccess = true 78 requirementsFactory.TargetedOrgSuccess = true 79 }) 80 81 It("unassigns a quota from a space", func() { 82 space := models.Space{ 83 SpaceFields: models.SpaceFields{ 84 Name: "my-space", 85 Guid: "my-space-guid", 86 }, 87 } 88 89 quota := models.SpaceQuota{Name: "my-quota", Guid: "my-quota-guid"} 90 91 quotaRepo.FindByNameReturns(quota, nil) 92 spaceRepo.FindByNameName = space.Name 93 spaceRepo.Spaces = []models.Space{space} 94 95 runCommand("my-space", "my-quota") 96 97 Expect(ui.Outputs).To(ContainSubstrings( 98 []string{"Unassigning space quota", "my-quota", "my-space", "my-user"}, 99 []string{"OK"}, 100 )) 101 102 Expect(quotaRepo.FindByNameArgsForCall(0)).To(Equal("my-quota")) 103 spaceGuid, quotaGuid := quotaRepo.UnassignQuotaFromSpaceArgsForCall(0) 104 Expect(spaceGuid).To(Equal("my-space-guid")) 105 Expect(quotaGuid).To(Equal("my-quota-guid")) 106 }) 107 }) 108 })