github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/process_instance_test.go (about) 1 package ccv3_test 2 3 import ( 4 "net/http" 5 "time" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 8 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/ghttp" 13 ) 14 15 var _ = Describe("ProcessInstance", func() { 16 var client *Client 17 18 BeforeEach(func() { 19 client, _ = NewTestClient() 20 }) 21 22 Describe("DeleteApplicationProcessInstance", func() { 23 var ( 24 warnings Warnings 25 executeErr error 26 ) 27 28 JustBeforeEach(func() { 29 warnings, executeErr = client.DeleteApplicationProcessInstance("some-app-guid", "some-process-type", 666) 30 }) 31 32 When("the cloud controller returns an error", func() { 33 BeforeEach(func() { 34 response := `{ 35 "errors": [ 36 { 37 "code": 10010, 38 "detail": "Process not found", 39 "title": "CF-ResourceNotFound" 40 } 41 ] 42 }` 43 44 server.AppendHandlers( 45 CombineHandlers( 46 VerifyRequest(http.MethodDelete, "/v3/apps/some-app-guid/processes/some-process-type/instances/666"), 47 RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"warning-1"}}), 48 ), 49 ) 50 }) 51 52 It("returns the error and all warnings", func() { 53 Expect(executeErr).To(MatchError(ccerror.ProcessNotFoundError{})) 54 Expect(warnings).To(ConsistOf("warning-1")) 55 }) 56 }) 57 58 When("the delete is successful", func() { 59 BeforeEach(func() { 60 server.AppendHandlers( 61 CombineHandlers( 62 VerifyRequest(http.MethodDelete, "/v3/apps/some-app-guid/processes/some-process-type/instances/666"), 63 RespondWith(http.StatusNoContent, "", http.Header{"X-Cf-Warnings": {"warning-1"}}), 64 ), 65 ) 66 }) 67 68 It("returns all warnings", func() { 69 Expect(executeErr).ToNot(HaveOccurred()) 70 Expect(warnings).To(ConsistOf("warning-1")) 71 }) 72 }) 73 }) 74 75 Describe("GetProcessInstances", func() { 76 var ( 77 processes []ProcessInstance 78 warnings Warnings 79 executeErr error 80 ) 81 82 JustBeforeEach(func() { 83 processes, warnings, executeErr = client.GetProcessInstances("some-process-guid") 84 }) 85 86 When("the process exists", func() { 87 BeforeEach(func() { 88 response := `{ 89 "resources": [ 90 { 91 "type": "web", 92 "state": "RUNNING", 93 "usage": { 94 "cpu": 0.01, 95 "mem": 1000000, 96 "disk": 2000000, 97 "log_rate": 5000 98 }, 99 "mem_quota": 2000000, 100 "disk_quota": 4000000, 101 "log_rate_limit": 10000, 102 "isolation_segment": "example_iso_segment", 103 "index": 0, 104 "uptime": 123, 105 "details": "some details" 106 }, 107 { 108 "type": "web", 109 "state": "RUNNING", 110 "usage": { 111 "cpu": 0.02, 112 "mem": 8000000, 113 "disk": 16000000, 114 "log_rate": 32000 115 }, 116 "mem_quota": 16000000, 117 "disk_quota": 32000000, 118 "log_rate_limit": 64000, 119 "isolation_segment": "example_iso_segment", 120 "index": 1, 121 "uptime": 456 122 } 123 ] 124 }` 125 server.AppendHandlers( 126 CombineHandlers( 127 VerifyRequest(http.MethodGet, "/v3/processes/some-process-guid/stats"), 128 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"warning-1"}}), 129 ), 130 ) 131 }) 132 133 It("returns a list of instances for the given process and all warnings", func() { 134 Expect(executeErr).ToNot(HaveOccurred()) 135 136 Expect(processes).To(ConsistOf( 137 ProcessInstance{ 138 CPU: 0.01, 139 Details: "some details", 140 DiskQuota: 4000000, 141 DiskUsage: 2000000, 142 Index: 0, 143 IsolationSegment: "example_iso_segment", 144 MemoryQuota: 2000000, 145 MemoryUsage: 1000000, 146 LogRateLimit: 10000, 147 LogRate: 5000, 148 State: constant.ProcessInstanceRunning, 149 Type: "web", 150 Uptime: 123 * time.Second, 151 }, 152 ProcessInstance{ 153 CPU: 0.02, 154 DiskQuota: 32000000, 155 DiskUsage: 16000000, 156 Index: 1, 157 IsolationSegment: "example_iso_segment", 158 MemoryQuota: 16000000, 159 MemoryUsage: 8000000, 160 LogRateLimit: 64000, 161 LogRate: 32000, 162 State: constant.ProcessInstanceRunning, 163 Type: "web", 164 Uptime: 456 * time.Second, 165 }, 166 )) 167 Expect(warnings).To(ConsistOf("warning-1")) 168 }) 169 }) 170 171 When("cloud controller returns an error", func() { 172 BeforeEach(func() { 173 response := `{ 174 "errors": [ 175 { 176 "code": 10010, 177 "detail": "Process not found", 178 "title": "CF-ResourceNotFound" 179 } 180 ] 181 }` 182 server.AppendHandlers( 183 CombineHandlers( 184 VerifyRequest(http.MethodGet, "/v3/processes/some-process-guid/stats"), 185 RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"warning-1"}}), 186 ), 187 ) 188 }) 189 190 It("returns the error and all warnings", func() { 191 Expect(executeErr).To(MatchError(ccerror.ProcessNotFoundError{})) 192 Expect(warnings).To(ConsistOf("warning-1")) 193 }) 194 }) 195 }) 196 })