github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv3/client_test.go (about) 1 package ccv3_test 2 3 import ( 4 "fmt" 5 "net/http" 6 "runtime" 7 8 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/ccv3fakes" 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 *ccv3fakes.FakeConnectionWrapper 27 28 BeforeEach(func() { 29 fakeConnectionWrapper = new(ccv3fakes.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.GetApplicationTasks("fake-guid") 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 V3 Test/Unknown (%s; %s %s)", runtime.Version(), runtime.GOARCH, runtime.GOOS) 45 rootResponse := fmt.Sprintf(` 46 { 47 "links": { 48 "cloud_controller_v3": { 49 "href": "%s/v3", 50 "meta": { 51 "version": "3.0.0-alpha.5" 52 } 53 } 54 } 55 }`, server.URL()) 56 server.AppendHandlers( 57 CombineHandlers( 58 VerifyRequest(http.MethodGet, "/"), 59 VerifyHeaderKV("User-Agent", expectedUserAgent), 60 RespondWith(http.StatusOK, rootResponse), 61 ), 62 ) 63 64 server.AppendHandlers( 65 CombineHandlers( 66 VerifyRequest(http.MethodGet, "/v3"), 67 VerifyHeaderKV("User-Agent", expectedUserAgent), 68 RespondWith(http.StatusOK, "{}"), 69 ), 70 ) 71 }) 72 73 It("adds a user agent header", func() { 74 _, _, _, err := client.Info() 75 Expect(err).ToNot(HaveOccurred()) 76 Expect(server.ReceivedRequests()).To(HaveLen(4)) 77 }) 78 }) 79 })