forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
71 lines (60 loc) · 1.67 KB
/
client_test.go
File metadata and controls
71 lines (60 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ccv3_test
import (
"fmt"
"net/http"
"runtime"
. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/ccv3fakes"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/ghttp"
)
var _ = Describe("Cloud Controller Client", func() {
var (
client *Client
)
BeforeEach(func() {
client, _ = NewTestClient()
})
Describe("WrapConnection", func() {
var fakeConnectionWrapper *ccv3fakes.FakeConnectionWrapper
BeforeEach(func() {
fakeConnectionWrapper = new(ccv3fakes.FakeConnectionWrapper)
fakeConnectionWrapper.WrapReturns(fakeConnectionWrapper)
})
It("wraps the existing connection in the provided wrapper", func() {
client.WrapConnection(fakeConnectionWrapper)
Expect(fakeConnectionWrapper.WrapCallCount()).To(Equal(1))
client.GetApplicationTasks("fake-guid")
Expect(fakeConnectionWrapper.MakeCallCount()).To(Equal(1))
})
})
Describe("User Agent", func() {
BeforeEach(func() {
expectedUserAgent := fmt.Sprintf("CF CLI API V3 Test/Unknown (%s; %s %s)", runtime.Version(), runtime.GOARCH, runtime.GOOS)
rootResponse := fmt.Sprintf(`
{
"links": {
"cloud_controller_v3": {
"href": "%s/v3",
"meta": {
"version": "3.0.0-alpha.5"
}
}
}
}`, server.URL())
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodGet, "/"),
VerifyHeaderKV("User-Agent", expectedUserAgent),
RespondWith(http.StatusOK, rootResponse),
),
)
})
It("adds a user agent header", func() {
_, _, err := client.GetRoot()
Expect(err).ToNot(HaveOccurred())
Expect(server.ReceivedRequests()).To(HaveLen(1))
})
})
})