github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/api/cloudcontroller/ccv3/manifest_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("Application Manifest", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client, _ = NewTestClient() 18 }) 19 20 Describe("GetApplicationManifest", func() { 21 var ( 22 appGUID string 23 24 rawManifest []byte 25 warnings Warnings 26 executeErr error 27 28 expectedYAML []byte 29 ) 30 31 BeforeEach(func() { 32 appGUID = "some-app-guid" 33 }) 34 35 JustBeforeEach(func() { 36 rawManifest, warnings, executeErr = client.GetApplicationManifest(appGUID) 37 }) 38 39 When("getting the manifest is successful", func() { 40 BeforeEach(func() { 41 expectedYAML = []byte("---\n- banana") 42 server.AppendHandlers( 43 CombineHandlers( 44 VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/manifest"), 45 VerifyHeaderKV("Accept", "application/x-yaml"), 46 RespondWith( 47 http.StatusOK, 48 expectedYAML, 49 http.Header{ 50 "Content-Type": {"application/x-yaml"}, 51 "X-Cf-Warnings": {"this is a warning"}, 52 }), 53 ), 54 ) 55 }) 56 57 It("the manifest and warnings", func() { 58 Expect(executeErr).NotTo(HaveOccurred()) 59 Expect(warnings).To(ConsistOf("this is a warning")) 60 61 Expect(rawManifest).To(Equal(expectedYAML)) 62 }) 63 }) 64 65 When("the cloud controller returns errors and warnings", func() { 66 BeforeEach(func() { 67 response := `{ 68 "errors": [ 69 { 70 "code": 10008, 71 "detail": "The request is semantically invalid: command presence", 72 "title": "CF-UnprocessableEntity" 73 }, 74 { 75 "code": 10010, 76 "detail": "App not found", 77 "title": "CF-AppNotFound" 78 } 79 ] 80 }` 81 server.AppendHandlers( 82 CombineHandlers( 83 VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/manifest"), 84 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 85 ), 86 ) 87 }) 88 89 It("returns the error and all warnings", func() { 90 Expect(executeErr).To(MatchError(ccerror.MultiError{ 91 ResponseCode: http.StatusTeapot, 92 Errors: []ccerror.V3Error{ 93 { 94 Code: 10008, 95 Detail: "The request is semantically invalid: command presence", 96 Title: "CF-UnprocessableEntity", 97 }, 98 { 99 Code: 10010, 100 Detail: "App not found", 101 Title: "CF-AppNotFound", 102 }, 103 }, 104 })) 105 Expect(warnings).To(ConsistOf("this is a warning")) 106 }) 107 }) 108 }) 109 })