github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/client_test.go (about) 1 package ccv2_test 2 3 import ( 4 "fmt" 5 "net/http" 6 "runtime" 7 8 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/ccv2fakes" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/ghttp" 14 ) 15 16 var _ = Describe("Cloud Controller Client", func() { 17 var ( 18 client *Client 19 ) 20 21 BeforeEach(func() { 22 client = NewTestClient() 23 }) 24 25 Describe("WrapConnection", func() { 26 var fakeConnectionWrapper *ccv2fakes.FakeConnectionWrapper 27 28 BeforeEach(func() { 29 fakeConnectionWrapper = new(ccv2fakes.FakeConnectionWrapper) 30 fakeConnectionWrapper.WrapReturns(fakeConnectionWrapper) 31 }) 32 33 It("wraps the existing connection in the provided wrapper", func() { 34 client.WrapConnection(fakeConnectionWrapper) 35 Expect(fakeConnectionWrapper.WrapCallCount()).To(Equal(1)) 36 37 client.DeleteServiceBinding("does-not-matter") 38 Expect(fakeConnectionWrapper.MakeCallCount()).To(Equal(1)) 39 }) 40 }) 41 42 Describe("User Agent", func() { 43 BeforeEach(func() { 44 expectedUserAgent := fmt.Sprintf("CF CLI API V2 Test/Unknown (%s; %s %s)", runtime.Version(), runtime.GOARCH, runtime.GOOS) 45 server.AppendHandlers( 46 CombineHandlers( 47 VerifyRequest(http.MethodGet, "/v2/apps"), 48 VerifyHeaderKV("User-Agent", expectedUserAgent), 49 RespondWith(http.StatusOK, "{}"), 50 ), 51 ) 52 }) 53 54 It("adds a user agent header", func() { 55 client.GetApplications() 56 Expect(server.ReceivedRequests()).To(HaveLen(2)) 57 }) 58 }) 59 })