github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v3action/application_summary_test.go (about) 1 package v3action_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/v3action" 7 "code.cloudfoundry.org/cli/actor/v3action/v3actionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 11 "code.cloudfoundry.org/cli/types" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("Application Summary Actions", func() { 18 var ( 19 actor *Actor 20 fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient 21 ) 22 23 BeforeEach(func() { 24 fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient) 25 actor = NewActor(fakeCloudControllerClient, nil, nil, nil) 26 }) 27 28 Describe("GetApplicationSummaryByNameAndSpace", func() { 29 var ( 30 appName string 31 spaceGUID string 32 withObfuscatedValues bool 33 34 summary ApplicationSummary 35 warnings Warnings 36 executeErr error 37 ) 38 39 BeforeEach(func() { 40 appName = "some-app-name" 41 spaceGUID = "some-space-guid" 42 withObfuscatedValues = true 43 }) 44 45 JustBeforeEach(func() { 46 summary, warnings, executeErr = actor.GetApplicationSummaryByNameAndSpace(appName, spaceGUID, withObfuscatedValues) 47 }) 48 49 When("retrieving the application is successful", func() { 50 BeforeEach(func() { 51 fakeCloudControllerClient.GetApplicationsReturns( 52 []ccv3.Application{ 53 { 54 Name: "some-app-name", 55 GUID: "some-app-guid", 56 State: constant.ApplicationStarted, 57 }, 58 }, 59 ccv3.Warnings{"some-warning"}, 60 nil, 61 ) 62 }) 63 64 When("retrieving the process information is successful", func() { 65 BeforeEach(func() { 66 listedProcess := ccv3.Process{ 67 GUID: "some-process-guid", 68 Type: "some-type", 69 Command: *types.NewFilteredString("[Redacted Value]"), 70 MemoryInMB: types.NullUint64{Value: 32, IsSet: true}, 71 } 72 fakeCloudControllerClient.GetApplicationProcessesReturns( 73 []ccv3.Process{listedProcess}, 74 ccv3.Warnings{"some-process-warning"}, 75 nil, 76 ) 77 78 explicitlyCalledProcess := listedProcess 79 explicitlyCalledProcess.Command = *types.NewFilteredString("some-start-command") 80 fakeCloudControllerClient.GetApplicationProcessByTypeReturns( 81 explicitlyCalledProcess, 82 ccv3.Warnings{"get-process-by-type-warning"}, 83 nil, 84 ) 85 86 fakeCloudControllerClient.GetProcessInstancesReturns( 87 []ccv3.ProcessInstance{ 88 { 89 State: constant.ProcessInstanceRunning, 90 CPU: 0.01, 91 MemoryUsage: 1000000, 92 DiskUsage: 2000000, 93 MemoryQuota: 3000000, 94 DiskQuota: 4000000, 95 Index: 0, 96 Details: "some details", 97 }, 98 }, 99 ccv3.Warnings{"some-process-stats-warning"}, 100 nil, 101 ) 102 }) 103 104 When("app has droplet", func() { 105 BeforeEach(func() { 106 fakeCloudControllerClient.GetApplicationDropletCurrentReturns( 107 ccv3.Droplet{ 108 Stack: "some-stack", 109 Buildpacks: []ccv3.DropletBuildpack{ 110 { 111 Name: "some-buildpack", 112 }, 113 }, 114 Image: "docker/some-image", 115 }, 116 ccv3.Warnings{"some-droplet-warning"}, 117 nil, 118 ) 119 }) 120 121 It("returns the summary and warnings with droplet information", func() { 122 Expect(executeErr).ToNot(HaveOccurred()) 123 Expect(summary).To(Equal(ApplicationSummary{ 124 Application: Application{ 125 Name: "some-app-name", 126 GUID: "some-app-guid", 127 State: constant.ApplicationStarted, 128 }, 129 CurrentDroplet: Droplet{ 130 Stack: "some-stack", 131 Image: "docker/some-image", 132 Buildpacks: []Buildpack{ 133 { 134 Name: "some-buildpack", 135 }, 136 }, 137 }, 138 ProcessSummaries: []ProcessSummary{ 139 { 140 Process: Process{ 141 GUID: "some-process-guid", 142 MemoryInMB: types.NullUint64{Value: 32, IsSet: true}, 143 Type: "some-type", 144 Command: *types.NewFilteredString("some-start-command"), 145 }, 146 InstanceDetails: []ProcessInstance{ 147 { 148 State: constant.ProcessInstanceRunning, 149 CPU: 0.01, 150 MemoryUsage: 1000000, 151 DiskUsage: 2000000, 152 MemoryQuota: 3000000, 153 DiskQuota: 4000000, 154 Index: 0, 155 Details: "some details", 156 }, 157 }, 158 }, 159 }, 160 })) 161 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning", "get-process-by-type-warning", "some-process-stats-warning", "some-droplet-warning")) 162 163 Expect(fakeCloudControllerClient.GetApplicationsCallCount()).To(Equal(1)) 164 Expect(fakeCloudControllerClient.GetApplicationsArgsForCall(0)).To(ConsistOf( 165 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"some-app-name"}}, 166 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{"some-space-guid"}}, 167 )) 168 169 Expect(fakeCloudControllerClient.GetApplicationDropletCurrentCallCount()).To(Equal(1)) 170 Expect(fakeCloudControllerClient.GetApplicationDropletCurrentArgsForCall(0)).To(Equal("some-app-guid")) 171 172 Expect(fakeCloudControllerClient.GetApplicationProcessesCallCount()).To(Equal(1)) 173 Expect(fakeCloudControllerClient.GetApplicationProcessesArgsForCall(0)).To(Equal("some-app-guid")) 174 175 Expect(fakeCloudControllerClient.GetApplicationProcessByTypeCallCount()).To(Equal(1)) 176 appGUID, processType := fakeCloudControllerClient.GetApplicationProcessByTypeArgsForCall(0) 177 Expect(appGUID).To(Equal("some-app-guid")) 178 Expect(processType).To(Equal("some-type")) 179 180 Expect(fakeCloudControllerClient.GetProcessInstancesCallCount()).To(Equal(1)) 181 Expect(fakeCloudControllerClient.GetProcessInstancesArgsForCall(0)).To(Equal("some-process-guid")) 182 }) 183 184 When("getting the current droplet returns an error", func() { 185 var expectedErr error 186 187 BeforeEach(func() { 188 expectedErr = errors.New("some error") 189 fakeCloudControllerClient.GetApplicationDropletCurrentReturns( 190 ccv3.Droplet{}, 191 ccv3.Warnings{"some-droplet-warning"}, 192 expectedErr, 193 ) 194 }) 195 196 It("returns the error", func() { 197 Expect(executeErr).To(Equal(expectedErr)) 198 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning", "get-process-by-type-warning", "some-process-stats-warning", "some-droplet-warning")) 199 }) 200 }) 201 }) 202 203 When("app does not have current droplet", func() { 204 BeforeEach(func() { 205 fakeCloudControllerClient.GetApplicationDropletCurrentReturns( 206 ccv3.Droplet{}, 207 ccv3.Warnings{"some-droplet-warning"}, 208 ccerror.DropletNotFoundError{}, 209 ) 210 }) 211 212 It("returns the summary and warnings without droplet information", func() { 213 Expect(executeErr).ToNot(HaveOccurred()) 214 Expect(summary).To(Equal(ApplicationSummary{ 215 Application: Application{ 216 Name: "some-app-name", 217 GUID: "some-app-guid", 218 State: constant.ApplicationStarted, 219 }, 220 ProcessSummaries: []ProcessSummary{ 221 { 222 Process: Process{ 223 GUID: "some-process-guid", 224 MemoryInMB: types.NullUint64{Value: 32, IsSet: true}, 225 Type: "some-type", 226 Command: *types.NewFilteredString("some-start-command"), 227 }, 228 InstanceDetails: []ProcessInstance{ 229 { 230 State: constant.ProcessInstanceRunning, 231 CPU: 0.01, 232 MemoryUsage: 1000000, 233 DiskUsage: 2000000, 234 MemoryQuota: 3000000, 235 DiskQuota: 4000000, 236 Index: 0, 237 Details: "some details", 238 }, 239 }, 240 }, 241 }, 242 })) 243 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning", "get-process-by-type-warning", "some-process-stats-warning", "some-droplet-warning")) 244 245 Expect(fakeCloudControllerClient.GetApplicationsCallCount()).To(Equal(1)) 246 Expect(fakeCloudControllerClient.GetApplicationsArgsForCall(0)).To(ConsistOf( 247 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"some-app-name"}}, 248 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{"some-space-guid"}}, 249 )) 250 251 Expect(fakeCloudControllerClient.GetApplicationDropletCurrentCallCount()).To(Equal(1)) 252 Expect(fakeCloudControllerClient.GetApplicationDropletCurrentArgsForCall(0)).To(Equal("some-app-guid")) 253 254 Expect(fakeCloudControllerClient.GetApplicationProcessesCallCount()).To(Equal(1)) 255 Expect(fakeCloudControllerClient.GetApplicationProcessesArgsForCall(0)).To(Equal("some-app-guid")) 256 257 Expect(fakeCloudControllerClient.GetApplicationProcessByTypeCallCount()).To(Equal(1)) 258 appGUID, processType := fakeCloudControllerClient.GetApplicationProcessByTypeArgsForCall(0) 259 Expect(appGUID).To(Equal("some-app-guid")) 260 Expect(processType).To(Equal("some-type")) 261 262 Expect(fakeCloudControllerClient.GetProcessInstancesCallCount()).To(Equal(1)) 263 Expect(fakeCloudControllerClient.GetProcessInstancesArgsForCall(0)).To(Equal("some-process-guid")) 264 }) 265 }) 266 }) 267 268 When("getting the app process instances returns an error", func() { 269 var expectedErr error 270 271 BeforeEach(func() { 272 fakeCloudControllerClient.GetApplicationProcessesReturns( 273 []ccv3.Process{ 274 { 275 GUID: "some-process-guid", 276 Type: "some-type", 277 }, 278 }, 279 ccv3.Warnings{"some-process-warning"}, 280 nil, 281 ) 282 283 fakeCloudControllerClient.GetApplicationProcessByTypeReturns( 284 ccv3.Process{}, 285 ccv3.Warnings{"get-process-by-type-warning"}, 286 nil, 287 ) 288 289 expectedErr = errors.New("some error") 290 fakeCloudControllerClient.GetProcessInstancesReturns( 291 []ccv3.ProcessInstance{}, 292 ccv3.Warnings{"some-process-stats-warning"}, 293 expectedErr, 294 ) 295 }) 296 297 It("returns the error", func() { 298 Expect(executeErr).To(Equal(expectedErr)) 299 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning", "get-process-by-type-warning", "some-process-stats-warning")) 300 }) 301 }) 302 }) 303 304 When("getting the app processes returns an error", func() { 305 var expectedErr error 306 307 BeforeEach(func() { 308 fakeCloudControllerClient.GetApplicationsReturns( 309 []ccv3.Application{ 310 { 311 Name: "some-app-name", 312 GUID: "some-app-guid", 313 State: constant.ApplicationStarted, 314 }, 315 }, 316 ccv3.Warnings{"some-warning"}, 317 nil, 318 ) 319 320 expectedErr = errors.New("some error") 321 fakeCloudControllerClient.GetApplicationProcessesReturns( 322 []ccv3.Process{{Type: constant.ProcessTypeWeb}}, 323 ccv3.Warnings{"some-process-warning"}, 324 expectedErr, 325 ) 326 }) 327 328 It("returns the error", func() { 329 Expect(executeErr).To(Equal(expectedErr)) 330 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning")) 331 }) 332 }) 333 }) 334 })