github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/api/cloudcontroller/ccv3/job_url_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 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("Job URL", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client = NewTestClient() 18 }) 19 20 Describe("DeleteApplication", func() { 21 var ( 22 jobLocation JobURL 23 warnings Warnings 24 executeErr error 25 ) 26 27 JustBeforeEach(func() { 28 jobLocation, warnings, executeErr = client.DeleteApplication("some-app-guid") 29 }) 30 31 Context("when the application is deleted successfully", func() { 32 BeforeEach(func() { 33 server.AppendHandlers( 34 CombineHandlers( 35 VerifyRequest(http.MethodDelete, "/v3/apps/some-app-guid"), 36 RespondWith(http.StatusAccepted, ``, 37 http.Header{ 38 "X-Cf-Warnings": {"some-warning"}, 39 "Location": {"/v3/jobs/some-location"}, 40 }, 41 ), 42 ), 43 ) 44 }) 45 46 It("returns all warnings", func() { 47 Expect(executeErr).ToNot(HaveOccurred()) 48 Expect(jobLocation).To(Equal(JobURL("/v3/jobs/some-location"))) 49 Expect(warnings).To(ConsistOf("some-warning")) 50 }) 51 }) 52 53 Context("when deleting the application returns an error", func() { 54 BeforeEach(func() { 55 response := `{ 56 "errors": [ 57 { 58 "code": 1001, 59 "detail": "Request invalid due to parse error: invalid request body", 60 "title": "CF-MessageParseError" 61 }, 62 { 63 "code": 10010, 64 "detail": "App not found", 65 "title": "CF-ResourceNotFound" 66 } 67 ] 68 }` 69 server.AppendHandlers( 70 CombineHandlers( 71 VerifyRequest(http.MethodDelete, "/v3/apps/some-app-guid"), 72 RespondWith(http.StatusBadRequest, response, http.Header{"X-Cf-Warnings": {"some-warning"}}), 73 ), 74 ) 75 }) 76 77 It("returns all warnings", func() { 78 Expect(executeErr).To(MatchError(ccerror.MultiError{ 79 ResponseCode: http.StatusBadRequest, 80 Errors: []ccerror.V3Error{ 81 { 82 Code: 1001, 83 Detail: "Request invalid due to parse error: invalid request body", 84 Title: "CF-MessageParseError", 85 }, 86 { 87 Code: 10010, 88 Detail: "App not found", 89 Title: "CF-ResourceNotFound", 90 }, 91 }, 92 })) 93 Expect(warnings).To(ConsistOf("some-warning")) 94 }) 95 }) 96 }) 97 98 Describe("UpdateApplicationApplyManifest", func() { 99 var ( 100 manifestBody []byte 101 102 jobURL JobURL 103 warnings Warnings 104 executeErr error 105 ) 106 107 JustBeforeEach(func() { 108 jobURL, warnings, executeErr = client.UpdateApplicationApplyManifest( 109 "some-app-guid", 110 manifestBody, 111 ) 112 }) 113 114 Context("when the manifest application is successful", func() { 115 var expectedJobURL string 116 117 BeforeEach(func() { 118 manifestBody = []byte("fake-yaml-body") 119 expectedJobURL = "i-am-a-job-url" 120 121 server.AppendHandlers( 122 CombineHandlers( 123 VerifyRequest(http.MethodPost, "/v3/apps/some-app-guid/actions/apply_manifest"), 124 VerifyHeaderKV("Content-type", "application/x-yaml"), 125 VerifyBody(manifestBody), 126 RespondWith(http.StatusAccepted, "", http.Header{ 127 "X-Cf-Warnings": {"this is a warning"}, 128 "Location": {expectedJobURL}, 129 }), 130 ), 131 ) 132 }) 133 134 It("returns the job URL and warnings", func() { 135 Expect(executeErr).NotTo(HaveOccurred()) 136 Expect(warnings).To(ConsistOf("this is a warning")) 137 138 Expect(jobURL).To(Equal(JobURL(expectedJobURL))) 139 }) 140 }) 141 142 Context("when the manifest application fails", func() { 143 BeforeEach(func() { 144 response := `{ 145 "errors": [ 146 { 147 "code": 1001, 148 "detail": "Request invalid due to parse error: invalid request body", 149 "title": "CF-MessageParseError" 150 }, 151 { 152 "code": 10010, 153 "detail": "App not found", 154 "title": "CF-ResourceNotFound" 155 } 156 ] 157 }` 158 server.AppendHandlers( 159 CombineHandlers( 160 VerifyRequest(http.MethodPost, "/v3/apps/some-app-guid/actions/apply_manifest"), 161 VerifyHeaderKV("Content-type", "application/x-yaml"), 162 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 163 ), 164 ) 165 }) 166 167 It("returns the error and all warnings", func() { 168 Expect(executeErr).To(MatchError(ccerror.MultiError{ 169 ResponseCode: http.StatusTeapot, 170 Errors: []ccerror.V3Error{ 171 { 172 Code: 1001, 173 Detail: "Request invalid due to parse error: invalid request body", 174 Title: "CF-MessageParseError", 175 }, 176 { 177 Code: 10010, 178 Detail: "App not found", 179 Title: "CF-ResourceNotFound", 180 }, 181 }, 182 })) 183 Expect(warnings).To(ConsistOf("this is a warning")) 184 }) 185 }) 186 }) 187 })