github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/uaa/client_test.go (about) 1 package uaa_test 2 3 import ( 4 "fmt" 5 "net/http" 6 "runtime" 7 8 . "code.cloudfoundry.org/cli/api/uaa" 9 "code.cloudfoundry.org/cli/api/uaa/uaafakes" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/ghttp" 14 ) 15 16 var _ = Describe("UAA Client", func() { 17 var ( 18 client *Client 19 20 fakeConfig *uaafakes.FakeConfig 21 ) 22 23 BeforeEach(func() { 24 fakeConfig = NewTestConfig() 25 26 client = NewTestUAAClientAndStore(fakeConfig) 27 }) 28 29 Describe("Request Headers", func() { 30 Describe("User-Agent", func() { 31 var userAgent string 32 BeforeEach(func() { 33 userAgent = fmt.Sprintf("CF CLI UAA API Test/Unknown (%s; %s %s)", 34 runtime.Version(), 35 runtime.GOARCH, 36 runtime.GOOS, 37 ) 38 server.AppendHandlers( 39 CombineHandlers( 40 VerifyRequest(http.MethodPost, "/oauth/token"), 41 VerifyHeaderKV("User-Agent", userAgent), 42 RespondWith(http.StatusOK, "{}"), 43 )) 44 }) 45 46 It("adds the User-Agent header to requests", func() { 47 _, err := client.RefreshAccessToken("") 48 Expect(err).ToNot(HaveOccurred()) 49 50 Expect(server.ReceivedRequests()).To(HaveLen(2)) 51 }) 52 }) 53 54 Describe("Conection", func() { 55 BeforeEach(func() { 56 server.AppendHandlers( 57 CombineHandlers( 58 VerifyRequest(http.MethodPost, "/oauth/token"), 59 VerifyHeaderKV("Connection", "close"), 60 RespondWith(http.StatusOK, "{}"), 61 )) 62 }) 63 64 It("forcefully closes the connection after each request", func() { 65 _, err := client.RefreshAccessToken("") 66 Expect(err).ToNot(HaveOccurred()) 67 68 Expect(server.ReceivedRequests()).To(HaveLen(2)) 69 }) 70 }) 71 }) 72 })