github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/application_instance_status_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 7 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("Application Instance Status", func() { 15 var client *Client 16 17 BeforeEach(func() { 18 client = NewTestClient() 19 }) 20 21 Describe("GetApplicationApplicationInstanceStatuses", func() { 22 var ( 23 appGUID string 24 25 instances map[int]ApplicationInstanceStatus 26 warnings Warnings 27 executeErr error 28 ) 29 30 BeforeEach(func() { 31 appGUID = "some-app-guid" 32 }) 33 34 JustBeforeEach(func() { 35 instances, warnings, executeErr = client.GetApplicationApplicationInstanceStatuses(appGUID) 36 }) 37 38 Context("when the app is found", func() { 39 BeforeEach(func() { 40 response := `{ 41 "0": { 42 "state": "RUNNING", 43 "isolation_segment": "some-isolation-segment", 44 "stats": { 45 "usage": { 46 "disk": 66392064, 47 "mem": 29880320, 48 "cpu": 0.13511219703079957, 49 "time": "2014-06-19 22:37:58 +0000" 50 }, 51 "name": "app_name", 52 "uris": [ 53 "app_name.example.com" 54 ], 55 "host": "10.0.0.1", 56 "port": 61035, 57 "uptime": 65007, 58 "mem_quota": 536870912, 59 "disk_quota": 1073741824, 60 "fds_quota": 16384 61 } 62 }, 63 "1": { 64 "state": "STARTING", 65 "isolation_segment": "some-isolation-segment", 66 "stats": { 67 "usage": { 68 "disk": 66392064, 69 "mem": 29880320, 70 "cpu": 0.13511219703079957, 71 "time": "2014-06-19 22:37:58 +0000" 72 }, 73 "name": "app_name", 74 "uris": [ 75 "app_name.example.com" 76 ], 77 "host": "10.0.0.1", 78 "port": 61035, 79 "uptime": 65007, 80 "mem_quota": 536870912, 81 "disk_quota": 1073741824, 82 "fds_quota": 16384 83 } 84 } 85 }` 86 87 server.AppendHandlers( 88 CombineHandlers( 89 VerifyRequest(http.MethodGet, "/v2/apps/some-app-guid/stats"), 90 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 91 ), 92 ) 93 }) 94 95 It("returns the app instances and warnings", func() { 96 Expect(executeErr).ToNot(HaveOccurred()) 97 Expect(instances).To(Equal( 98 map[int]ApplicationInstanceStatus{ 99 0: { 100 CPU: 0.13511219703079957, 101 Disk: 66392064, 102 DiskQuota: 1073741824, 103 ID: 0, 104 IsolationSegment: "some-isolation-segment", 105 Memory: 29880320, 106 MemoryQuota: 536870912, 107 State: constant.ApplicationInstanceRunning, 108 Uptime: 65007, 109 }, 110 1: { 111 CPU: 0.13511219703079957, 112 Disk: 66392064, 113 DiskQuota: 1073741824, 114 ID: 1, 115 IsolationSegment: "some-isolation-segment", 116 Memory: 29880320, 117 MemoryQuota: 536870912, 118 State: constant.ApplicationInstanceStarting, 119 Uptime: 65007, 120 }, 121 }, 122 )) 123 124 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 125 }) 126 }) 127 128 Context("when the client returns an error", func() { 129 BeforeEach(func() { 130 response := `{ 131 "code": 100004, 132 "description": "The app could not be found: some-app-guid", 133 "error_code": "CF-AppNotFound" 134 }` 135 server.AppendHandlers( 136 CombineHandlers( 137 VerifyRequest(http.MethodGet, "/v2/apps/some-app-guid/stats"), 138 RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 139 ), 140 ) 141 }) 142 143 It("returns the error and warnings", func() { 144 Expect(executeErr).To(MatchError(ccerror.ResourceNotFoundError{ 145 Message: "The app could not be found: some-app-guid", 146 })) 147 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 148 }) 149 }) 150 }) 151 })