github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/spacequota/space_quota_test.go (about) 1 package spacequota_test 2 3 import ( 4 "github.com/cloudfoundry/cli/cf/api/space_quotas/fakes" 5 "github.com/cloudfoundry/cli/cf/command_registry" 6 "github.com/cloudfoundry/cli/cf/configuration/core_config" 7 "github.com/cloudfoundry/cli/cf/errors" 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("quotas command", func() { 20 var ( 21 ui *testterm.FakeUI 22 quotaRepo *fakes.FakeSpaceQuotaRepository 23 requirementsFactory *testreq.FakeReqFactory 24 configRepo core_config.Repository 25 deps command_registry.Dependency 26 ) 27 28 updateCommandDependency := func(pluginCall bool) { 29 deps.Ui = ui 30 deps.RepoLocator = deps.RepoLocator.SetSpaceQuotaRepository(quotaRepo) 31 deps.Config = configRepo 32 command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("space-quota").SetDependency(deps, pluginCall)) 33 } 34 35 BeforeEach(func() { 36 ui = &testterm.FakeUI{} 37 quotaRepo = &fakes.FakeSpaceQuotaRepository{} 38 configRepo = testconfig.NewRepositoryWithDefaults() 39 requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true} 40 }) 41 42 runCommand := func(args ...string) bool { 43 return testcmd.RunCliCommand("space-quota", args, requirementsFactory, updateCommandDependency, false) 44 } 45 46 Describe("requirements", func() { 47 It("requires the user to be logged in", func() { 48 requirementsFactory.LoginSuccess = false 49 Expect(runCommand("foo")).ToNot(HavePassedRequirements()) 50 }) 51 52 It("requires the user to target an org", func() { 53 requirementsFactory.TargetedOrgSuccess = false 54 Expect(runCommand("bar")).ToNot(HavePassedRequirements()) 55 }) 56 57 It("fails when a quota name is not provided", func() { 58 requirementsFactory.LoginSuccess = true 59 requirementsFactory.TargetedOrgSuccess = true 60 Expect(runCommand()).ToNot(HavePassedRequirements()) 61 }) 62 }) 63 64 Context("when logged in", func() { 65 JustBeforeEach(func() { 66 requirementsFactory.LoginSuccess = true 67 requirementsFactory.TargetedOrgSuccess = true 68 Expect(runCommand("quota-name")).To(HavePassedRequirements()) 69 }) 70 71 Context("when quotas exist", func() { 72 BeforeEach(func() { 73 quotaRepo.FindByNameReturns( 74 models.SpaceQuota{ 75 Name: "quota-name", 76 MemoryLimit: 1024, 77 InstanceMemoryLimit: -1, 78 RoutesLimit: 111, 79 ServicesLimit: 222, 80 NonBasicServicesAllowed: true, 81 OrgGuid: "my-org-guid", 82 }, nil) 83 }) 84 85 It("lists the specific quota info", func() { 86 Expect(quotaRepo.FindByNameArgsForCall(0)).To(Equal("quota-name")) 87 Expect(ui.Outputs).To(ContainSubstrings( 88 []string{"Getting space quota quota-name info as", "my-user"}, 89 []string{"OK"}, 90 []string{"total memory limit", "1G"}, 91 []string{"instance memory limit", "unlimited"}, 92 []string{"routes", "111"}, 93 []string{"service", "222"}, 94 []string{"non basic services", "allowed"}, 95 )) 96 }) 97 98 Context("when the services are unlimited", func() { 99 BeforeEach(func() { 100 quotaRepo.FindByNameReturns( 101 models.SpaceQuota{ 102 Name: "quota-name", 103 MemoryLimit: 1024, 104 InstanceMemoryLimit: 14, 105 RoutesLimit: 111, 106 ServicesLimit: -1, 107 NonBasicServicesAllowed: true, 108 OrgGuid: "my-org-guid", 109 }, nil) 110 111 }) 112 113 It("replaces -1 with unlimited", func() { 114 Expect(quotaRepo.FindByNameArgsForCall(0)).To(Equal("quota-name")) 115 Expect(ui.Outputs).To(ContainSubstrings( 116 []string{"Getting space quota quota-name info as", "my-user"}, 117 []string{"OK"}, 118 []string{"total memory limit", "1G"}, 119 []string{"instance memory limit", "14M"}, 120 []string{"routes", "111"}, 121 []string{"service", "unlimited"}, 122 []string{"non basic services", "allowed"}, 123 )) 124 }) 125 }) 126 }) 127 Context("when an error occurs fetching quotas", func() { 128 BeforeEach(func() { 129 quotaRepo.FindByNameReturns(models.SpaceQuota{}, errors.New("I haz a borken!")) 130 }) 131 132 It("prints an error", func() { 133 Expect(ui.Outputs).To(ContainSubstrings( 134 []string{"Getting space quota quota-name info as", "my-user"}, 135 []string{"FAILED"}, 136 )) 137 }) 138 }) 139 }) 140 141 })