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