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