github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/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  
    65  		It("adds a user agent header", func() {
    66  			_, _, err := client.GetInfo()
    67  			Expect(err).ToNot(HaveOccurred())
    68  			Expect(server.ReceivedRequests()).To(HaveLen(1))
    69  		})
    70  	})
    71  })