github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/api/plugin/client_test.go (about)

     1  package plugin_test
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"runtime"
     7  
     8  	. "code.cloudfoundry.org/cli/api/plugin"
     9  	"code.cloudfoundry.org/cli/api/plugin/pluginfakes"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/ghttp"
    13  )
    14  
    15  var _ = Describe("Plugin Client", func() {
    16  	var client *Client
    17  
    18  	BeforeEach(func() {
    19  		client = NewTestClient()
    20  	})
    21  
    22  	Describe("WrapConnection", func() {
    23  		var fakeConnectionWrapper *pluginfakes.FakeConnectionWrapper
    24  
    25  		BeforeEach(func() {
    26  			fakeConnectionWrapper = new(pluginfakes.FakeConnectionWrapper)
    27  			fakeConnectionWrapper.WrapReturns(fakeConnectionWrapper)
    28  		})
    29  
    30  		It("wraps the existing connection in the provided wrapper", func() {
    31  			client.WrapConnection(fakeConnectionWrapper)
    32  			Expect(fakeConnectionWrapper.WrapCallCount()).To(Equal(1))
    33  
    34  			client.GetPluginRepository("does-not-matter")
    35  			Expect(fakeConnectionWrapper.MakeCallCount()).To(Equal(1))
    36  		})
    37  	})
    38  
    39  	Describe("User Agent", func() {
    40  		BeforeEach(func() {
    41  			server.AppendHandlers(
    42  				CombineHandlers(
    43  					VerifyRequest(http.MethodGet, "/list"),
    44  					VerifyHeaderKV("User-Agent", fmt.Sprintf("CF CLI API Plugin Test/Unknown (%s; %s %s)", runtime.Version(), runtime.GOARCH, runtime.GOOS)),
    45  					RespondWith(http.StatusOK, "{}"),
    46  				),
    47  			)
    48  		})
    49  
    50  		It("adds a user agent header", func() {
    51  			client.GetPluginRepository(server.URL())
    52  			Expect(server.ReceivedRequests()).To(HaveLen(1))
    53  		})
    54  	})
    55  })