github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv2/stack_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("Stack", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client = NewTestClient() 18 }) 19 20 Describe("GetStack", func() { 21 Context("when the stack is found", func() { 22 BeforeEach(func() { 23 response := `{ 24 "metadata": { 25 "guid": "some-stack-guid" 26 }, 27 "entity": { 28 "name": "some-stack-name", 29 "description": "some stack description" 30 } 31 }` 32 33 server.AppendHandlers( 34 CombineHandlers( 35 VerifyRequest(http.MethodGet, "/v2/stacks/some-stack-guid"), 36 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 37 ), 38 ) 39 }) 40 41 It("returns the stack and warnings", func() { 42 stack, warnings, err := client.GetStack("some-stack-guid") 43 Expect(err).ToNot(HaveOccurred()) 44 Expect(stack).To(Equal(Stack{ 45 Description: "some stack description", 46 GUID: "some-stack-guid", 47 Name: "some-stack-name", 48 })) 49 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 50 }) 51 }) 52 53 Context("when the client returns an error", func() { 54 BeforeEach(func() { 55 response := `{ 56 "code": 250003, 57 "description": "The stack could not be found: some-stack-guid", 58 "error_code": "CF-StackNotFound" 59 }` 60 server.AppendHandlers( 61 CombineHandlers( 62 VerifyRequest(http.MethodGet, "/v2/stacks/some-stack-guid"), 63 RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 64 ), 65 ) 66 }) 67 68 It("returns the error and warnings", func() { 69 _, warnings, err := client.GetStack("some-stack-guid") 70 Expect(err).To(MatchError(cloudcontroller.ResourceNotFoundError{ 71 Message: "The stack could not be found: some-stack-guid", 72 })) 73 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 74 }) 75 }) 76 }) 77 })