github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v7/org_quotas_command_test.go (about) 1 package v7_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/command/commandfakes" 9 . "code.cloudfoundry.org/cli/command/v7" 10 "code.cloudfoundry.org/cli/command/v7/v7fakes" 11 "code.cloudfoundry.org/cli/types" 12 "code.cloudfoundry.org/cli/util/configv3" 13 "code.cloudfoundry.org/cli/util/ui" 14 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 . "github.com/onsi/gomega/gbytes" 18 ) 19 20 var _ = Describe("org-quotas command", func() { 21 var ( 22 cmd OrgQuotasCommand 23 testUI *ui.UI 24 fakeConfig *commandfakes.FakeConfig 25 fakeSharedActor *commandfakes.FakeSharedActor 26 fakeActor *v7fakes.FakeOrgQuotasActor 27 executeErr error 28 args []string 29 binaryName string 30 ) 31 32 BeforeEach(func() { 33 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 34 fakeConfig = new(commandfakes.FakeConfig) 35 fakeSharedActor = new(commandfakes.FakeSharedActor) 36 fakeActor = new(v7fakes.FakeOrgQuotasActor) 37 args = nil 38 39 cmd = OrgQuotasCommand{ 40 UI: testUI, 41 Config: fakeConfig, 42 SharedActor: fakeSharedActor, 43 Actor: fakeActor, 44 } 45 46 binaryName = "faceman" 47 fakeConfig.BinaryNameReturns(binaryName) 48 }) 49 50 JustBeforeEach(func() { 51 executeErr = cmd.Execute(args) 52 }) 53 54 When("running the command successfully", func() { 55 BeforeEach(func() { 56 fakeConfig.CurrentUserReturns(configv3.User{Name: "apple"}, nil) 57 orgQuotas := []v7action.OrganizationQuota{ 58 { 59 Name: "org-quota-1", 60 61 TotalMemory: types.NullInt{Value: 1048576, IsSet: true}, 62 InstanceMemory: types.NullInt{Value: 32, IsSet: true}, 63 TotalAppInstances: types.NullInt{Value: 3, IsSet: true}, 64 65 TotalServiceInstances: types.NullInt{Value: 3, IsSet: true}, 66 PaidServicePlans: true, 67 68 TotalRoutes: types.NullInt{Value: 5, IsSet: true}, 69 TotalRoutePorts: types.NullInt{Value: 2, IsSet: true}, 70 }, 71 } 72 fakeActor.GetOrganizationQuotasReturns(orgQuotas, v7action.Warnings{"some-warning-1", "some-warning-2"}, nil) 73 }) 74 75 It("should print text indicating the command status", func() { 76 Expect(executeErr).NotTo(HaveOccurred()) 77 Expect(testUI.Out).To(Say(`Getting org quotas as apple\.\.\.`)) 78 Expect(testUI.Err).To(Say("some-warning-1")) 79 Expect(testUI.Err).To(Say("some-warning-2")) 80 }) 81 82 It("retrieves and displays all quotas", func() { 83 Expect(executeErr).NotTo(HaveOccurred()) 84 Expect(fakeActor.GetOrganizationQuotasCallCount()).To(Equal(1)) 85 Expect(testUI.Out).To(Say(`name\s+total memory\s+instance memory\s+routes\s+service instances\s+paid service plans\s+app instances\s+route ports`)) 86 Expect(testUI.Out).To(Say(`org-quota-1\s+1T\s+32M\s+5\s+3\s+allowed\s+3\s+2`)) 87 }) 88 89 When("there are limits that have not been configured", func() { 90 BeforeEach(func() { 91 orgQuotas := []v7action.OrganizationQuota{ 92 { 93 Name: "default", 94 95 TotalMemory: types.NullInt{Value: 0, IsSet: false}, 96 InstanceMemory: types.NullInt{Value: 0, IsSet: false}, 97 TotalAppInstances: types.NullInt{Value: 0, IsSet: false}, 98 99 TotalServiceInstances: types.NullInt{Value: 0, IsSet: false}, 100 PaidServicePlans: true, 101 102 TotalRoutes: types.NullInt{Value: 0, IsSet: false}, 103 TotalRoutePorts: types.NullInt{Value: 0, IsSet: false}, 104 }, 105 } 106 fakeActor.GetOrganizationQuotasReturns(orgQuotas, v7action.Warnings{"some-warning-1", "some-warning-2"}, nil) 107 108 }) 109 110 It("should convert default values from the API into readable outputs", func() { 111 Expect(executeErr).NotTo(HaveOccurred()) 112 Expect(testUI.Out).To(Say(`name\s+total memory\s+instance memory\s+routes\s+service instances\s+paid service plans\s+app instances\s+route ports`)) 113 Expect(testUI.Out).To(Say(`default\s+unlimited\s+unlimited\s+unlimited\s+unlimited\s+allowed\s+unlimited\s+unlimited`)) 114 115 }) 116 }) 117 }) 118 119 When("the environment is not set up correctly", func() { 120 BeforeEach(func() { 121 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 122 }) 123 124 It("returns an error", func() { 125 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 126 127 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 128 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 129 Expect(checkTargetedOrg).To(BeFalse()) 130 Expect(checkTargetedSpace).To(BeFalse()) 131 }) 132 }) 133 134 When("getting quotas fails", func() { 135 BeforeEach(func() { 136 fakeActor.GetOrganizationQuotasReturns(nil, v7action.Warnings{"some-warning-1", "some-warning-2"}, errors.New("some-error")) 137 }) 138 139 It("prints warnings and returns error", func() { 140 Expect(executeErr).To(MatchError("some-error")) 141 142 Expect(testUI.Err).To(Say("some-warning-1")) 143 Expect(testUI.Err).To(Say("some-warning-2")) 144 }) 145 }) 146 })