github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/command/v3/shared/app_summary_displayer_test.go (about) 1 package shared_test 2 3 import ( 4 "errors" 5 "time" 6 7 "code.cloudfoundry.org/cli/actor/v3action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 9 "code.cloudfoundry.org/cli/command/commandfakes" 10 . "code.cloudfoundry.org/cli/command/v3/shared" 11 "code.cloudfoundry.org/cli/command/v3/shared/sharedfakes" 12 "code.cloudfoundry.org/cli/integration/helpers" 13 "code.cloudfoundry.org/cli/types" 14 "code.cloudfoundry.org/cli/util/configv3" 15 "code.cloudfoundry.org/cli/util/ui" 16 . "github.com/onsi/ginkgo" 17 . "github.com/onsi/gomega" 18 . "github.com/onsi/gomega/gbytes" 19 ) 20 21 var _ = Describe("app summary displayer", func() { 22 var ( 23 appSummaryDisplayer AppSummaryDisplayer 24 input *Buffer 25 output *Buffer 26 testUI *ui.UI 27 fakeConfig *commandfakes.FakeConfig 28 fakeActor *sharedfakes.FakeV3AppSummaryActor 29 appName string 30 executeErr error 31 ) 32 33 BeforeEach(func() { 34 input = NewBuffer() 35 output = NewBuffer() 36 testUI = ui.NewTestUI(input, output, NewBuffer()) 37 fakeConfig = new(commandfakes.FakeConfig) 38 fakeActor = new(sharedfakes.FakeV3AppSummaryActor) 39 appName = "some-app" 40 41 appSummaryDisplayer = AppSummaryDisplayer{ 42 UI: testUI, 43 Config: fakeConfig, 44 Actor: fakeActor, 45 V2AppRouteActor: nil, 46 AppName: appName, 47 } 48 49 fakeConfig.TargetedSpaceReturns(configv3.Space{ 50 GUID: "some-space-guid", 51 Name: "some-space"}) 52 }) 53 54 JustBeforeEach(func() { 55 executeErr = appSummaryDisplayer.DisplayAppProcessInfo() 56 }) 57 58 Describe("DisplayAppProcessInfo", func() { 59 Context("when getting the app summary succeeds", func() { 60 BeforeEach(func() { 61 appSummary := v3action.ApplicationSummary{ 62 ProcessSummaries: v3action.ProcessSummaries{ 63 { 64 Process: v3action.Process{ 65 Type: "console", 66 MemoryInMB: types.NullUint64{Value: 16, IsSet: true}, 67 DiskInMB: types.NullUint64{Value: 512, IsSet: true}, 68 }, 69 InstanceDetails: []v3action.ProcessInstance{ 70 v3action.ProcessInstance{ 71 Index: 0, 72 State: constant.ProcessInstanceRunning, 73 MemoryUsage: 1000000, 74 DiskUsage: 1000000, 75 MemoryQuota: 33554432, 76 DiskQuota: 8000000, 77 Uptime: int(time.Now().Sub(time.Unix(167572800, 0)).Seconds()), 78 }, 79 }, 80 }, 81 { 82 Process: v3action.Process{ 83 Type: constant.ProcessTypeWeb, 84 MemoryInMB: types.NullUint64{Value: 32, IsSet: true}, 85 DiskInMB: types.NullUint64{Value: 1024, IsSet: true}, 86 }, 87 InstanceDetails: []v3action.ProcessInstance{ 88 v3action.ProcessInstance{ 89 Index: 0, 90 State: constant.ProcessInstanceRunning, 91 MemoryUsage: 1000000, 92 DiskUsage: 1000000, 93 MemoryQuota: 33554432, 94 DiskQuota: 2000000, 95 Uptime: int(time.Now().Sub(time.Unix(267321600, 0)).Seconds()), 96 }, 97 v3action.ProcessInstance{ 98 Index: 1, 99 State: constant.ProcessInstanceRunning, 100 MemoryUsage: 2000000, 101 DiskUsage: 2000000, 102 MemoryQuota: 33554432, 103 DiskQuota: 4000000, 104 Uptime: int(time.Now().Sub(time.Unix(330480000, 0)).Seconds()), 105 }, 106 v3action.ProcessInstance{ 107 Index: 2, 108 State: constant.ProcessInstanceRunning, 109 MemoryUsage: 3000000, 110 DiskUsage: 3000000, 111 MemoryQuota: 33554432, 112 DiskQuota: 6000000, 113 Uptime: int(time.Now().Sub(time.Unix(1277164800, 0)).Seconds()), 114 }, 115 }, 116 }, 117 }, 118 } 119 120 fakeActor.GetApplicationSummaryByNameAndSpaceReturns( 121 appSummary, 122 v3action.Warnings{"get-app-summary-warning"}, 123 nil) 124 }) 125 126 It("lists information for each of the processes", func() { 127 Expect(executeErr).ToNot(HaveOccurred()) 128 129 processTable := helpers.ParseV3AppProcessTable(output.Contents()) 130 Expect(len(processTable.Processes)).To(Equal(2)) 131 132 webProcessSummary := processTable.Processes[0] 133 Expect(webProcessSummary.Title).To(Equal("web:3/3")) 134 135 Expect(webProcessSummary.Instances[0].Memory).To(Equal("976.6K of 32M")) 136 Expect(webProcessSummary.Instances[0].Disk).To(Equal("976.6K of 1.9M")) 137 Expect(webProcessSummary.Instances[0].CPU).To(Equal("0.0%")) 138 139 Expect(webProcessSummary.Instances[1].Memory).To(Equal("1.9M of 32M")) 140 Expect(webProcessSummary.Instances[1].Disk).To(Equal("1.9M of 3.8M")) 141 Expect(webProcessSummary.Instances[1].CPU).To(Equal("0.0%")) 142 143 Expect(webProcessSummary.Instances[2].Memory).To(Equal("2.9M of 32M")) 144 Expect(webProcessSummary.Instances[2].Disk).To(Equal("2.9M of 5.7M")) 145 Expect(webProcessSummary.Instances[2].CPU).To(Equal("0.0%")) 146 147 consoleProcessSummary := processTable.Processes[1] 148 Expect(consoleProcessSummary.Title).To(Equal("console:1/1")) 149 150 Expect(consoleProcessSummary.Instances[0].Memory).To(Equal("976.6K of 32M")) 151 Expect(consoleProcessSummary.Instances[0].Disk).To(Equal("976.6K of 7.6M")) 152 Expect(consoleProcessSummary.Instances[0].CPU).To(Equal("0.0%")) 153 154 Expect(testUI.Err).To(Say("get-app-summary-warning")) 155 156 Expect(fakeActor.GetApplicationSummaryByNameAndSpaceCallCount()).To(Equal(1)) 157 passedAppName, spaceName := fakeActor.GetApplicationSummaryByNameAndSpaceArgsForCall(0) 158 Expect(passedAppName).To(Equal("some-app")) 159 Expect(spaceName).To(Equal("some-space-guid")) 160 }) 161 }) 162 163 Context("when getting the app summary fails", func() { 164 BeforeEach(func() { 165 fakeActor.GetApplicationSummaryByNameAndSpaceReturns( 166 v3action.ApplicationSummary{}, 167 v3action.Warnings{"get-app-summary-warning"}, 168 errors.New("some-app-summary-error"), 169 ) 170 }) 171 172 It("returns the error and displays all warnings", func() { 173 Expect(executeErr).To(MatchError("some-app-summary-error")) 174 Expect(testUI.Err).To(Say("get-app-summary-warning")) 175 Expect(output.Contents()).To(HaveLen(0)) 176 }) 177 }) 178 }) 179 })