github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/feature_flag_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 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("Feature Flag", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client = NewTestClient() 18 }) 19 20 Describe("GetConfigFeatureFlags", func() { 21 var ( 22 featureFlags []FeatureFlag 23 warnings Warnings 24 err error 25 ) 26 27 JustBeforeEach(func() { 28 featureFlags, warnings, err = client.GetConfigFeatureFlags() 29 }) 30 31 Context("when no errors are encountered", func() { 32 BeforeEach(func() { 33 response := `[ 34 { 35 "name": "feature-flag-1", 36 "enabled": true 37 }, 38 { 39 "name": "feature-flag-2", 40 "enabled": false 41 } 42 ]` 43 server.AppendHandlers( 44 CombineHandlers( 45 VerifyRequest(http.MethodGet, "/v2/config/feature_flags"), 46 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"warning"}}), 47 )) 48 }) 49 50 It("returns the feature flags and all warnings", func() { 51 Expect(err).NotTo(HaveOccurred()) 52 Expect(featureFlags).To(Equal([]FeatureFlag{ 53 {Name: "feature-flag-1", Enabled: true}, 54 {Name: "feature-flag-2", Enabled: false}, 55 })) 56 Expect(warnings).To(ConsistOf("warning")) 57 }) 58 }) 59 60 Context("when an error is encountered", func() { 61 BeforeEach(func() { 62 response := `{ 63 "code": 10001, 64 "description": "Some Error", 65 "error_code": "CF-SomeError" 66 }` 67 server.AppendHandlers( 68 CombineHandlers( 69 VerifyRequest(http.MethodGet, "/v2/config/feature_flags"), 70 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}), 71 )) 72 }) 73 74 It("returns an error and all warnings", func() { 75 Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{ 76 ResponseCode: http.StatusTeapot, 77 V2ErrorResponse: ccerror.V2ErrorResponse{ 78 Code: 10001, 79 Description: "Some Error", 80 ErrorCode: "CF-SomeError", 81 }, 82 })) 83 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 84 }) 85 }) 86 }) 87 })