github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/api/cloudcontroller/ccv3/droplet_test.go (about) 1 package ccv3_test 2 3 import ( 4 "fmt" 5 "net/http" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 8 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("Droplet", func() { 15 var client *Client 16 17 BeforeEach(func() { 18 client = NewTestClient() 19 }) 20 21 Describe("GetApplicationCurrentDroplet", func() { 22 Context("when the application exists", func() { 23 BeforeEach(func() { 24 response := fmt.Sprintf(`{ 25 "stack": "some-stack", 26 "buildpacks": [{ 27 "name": "some-buildpack", 28 "detect_output": "detected-buildpack" 29 }] 30 }`, server.URL()) 31 server.AppendHandlers( 32 CombineHandlers( 33 VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/droplets/current"), 34 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"warning-1"}}), 35 ), 36 ) 37 }) 38 39 It("returns the current droplet for the given app and all warnings", func() { 40 droplet, warnings, err := client.GetApplicationCurrentDroplet("some-app-guid") 41 Expect(err).ToNot(HaveOccurred()) 42 43 Expect(droplet).To(Equal(Droplet{ 44 Stack: "some-stack", 45 Buildpacks: []Buildpack{ 46 { 47 Name: "some-buildpack", 48 DetectOutput: "detected-buildpack", 49 }, 50 }, 51 })) 52 Expect(warnings).To(ConsistOf("warning-1")) 53 }) 54 }) 55 56 Context("when cloud controller returns an error", func() { 57 BeforeEach(func() { 58 response := `{ 59 "errors": [ 60 { 61 "code": 10010, 62 "detail": "App not found", 63 "title": "CF-ResourceNotFound" 64 } 65 ] 66 }` 67 server.AppendHandlers( 68 CombineHandlers( 69 VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/droplets/current"), 70 RespondWith(http.StatusNotFound, response), 71 ), 72 ) 73 }) 74 75 It("returns the error", func() { 76 _, _, err := client.GetApplicationCurrentDroplet("some-app-guid") 77 Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "App not found"})) 78 }) 79 }) 80 }) 81 })