MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / TestClient_GetSystemClient

Function TestClient_GetSystemClient

pkg/apiclient/apiclient_test.go:20–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18var qa = question.NewAskProvider(nil)
19
20func TestClient_GetSystemClient(t *testing.T) {
21 api := testutil.NewMockHttpServer()
22
23 t.Run("GetSystemClient returns the client", func(t *testing.T) {
24 apiKeyCredential, _ := octopusApiClient.NewApiKey(placeholderApiKey)
25 factory, err := apiclient.NewClientFactory(testutil.NewMockHttpClientWithTransport(api), serverUrl, apiKeyCredential, "", qa)
26 testutil.RequireSuccess(t, err)
27
28 clientReceiver := testutil.GoBegin2(
29 func() (*octopusApiClient.Client, error) {
30 return factory.GetSystemClient(&apiclient.FakeRequesterContext{})
31 })
32
33 //clientReceiver2 := testutil.GoBegin2(func () (*octopusApiClient.Client, error) { factory.GetSystemClient(&apiclient.FakeRequesterContext{})
34 api.ExpectRequest(t, "GET", "/api/").RespondWith(root)
35 api.ExpectRequest(t, "GET", "/api/spaces").RespondWith(root)
36
37 systemClient, err := testutil.ReceivePair(clientReceiver)
38 if !testutil.AssertSuccess(t, err) {
39 return
40 }
41
42 assert.NotNil(t, systemClient)
43 })
44
45 t.Run("GetSystemClient called twice returns the same client instance", func(t *testing.T) {
46 apiKeyCredential, _ := octopusApiClient.NewApiKey(placeholderApiKey)
47 factory, err := apiclient.NewClientFactory(testutil.NewMockHttpClientWithTransport(api), serverUrl, apiKeyCredential, "", qa)
48 testutil.RequireSuccess(t, err)
49 clientReceiver := testutil.GoBegin2(
50 func() (*octopusApiClient.Client, error) {
51 return factory.GetSystemClient(&apiclient.FakeRequesterContext{})
52 })
53
54 api.ExpectRequest(t, "GET", "/api/").RespondWith(root)
55 api.ExpectRequest(t, "GET", "/api/spaces").RespondWith(root)
56
57 systemClient, err := testutil.ReceivePair(clientReceiver)
58 if !testutil.AssertSuccess(t, err) {
59 return
60 }
61
62 // Note that if this were to invoke any network requests, the test would fail because the mock API is not
63 // prepared for that
64 systemClient2, err := factory.GetSystemClient(&apiclient.FakeRequesterContext{})
65 if !testutil.AssertSuccess(t, err) {
66 return
67 }
68 assert.Same(t, systemClient, systemClient2)
69 })
70
71 t.Run("GetSystemClient contains the access token in the right header if supplied", func(t *testing.T) {
72 accessTokenCredential, _ := octopusApiClient.NewAccessToken("token")
73 factory, err := apiclient.NewClientFactory(testutil.NewMockHttpClientWithTransport(api), serverUrl, accessTokenCredential, "", qa)
74 testutil.RequireSuccess(t, err)
75
76 clientReceiver := testutil.GoBegin2(
77 func() (*octopusApiClient.Client, error) {

Callers

nothing calls this directly

Calls 11

GetSystemClientMethod · 0.95
ExpectRequestMethod · 0.95
NewMockHttpServerFunction · 0.92
NewClientFactoryFunction · 0.92
RequireSuccessFunction · 0.92
GoBegin2Function · 0.92
ReceivePairFunction · 0.92
AssertSuccessFunction · 0.92
RespondWithMethod · 0.80
ExpectHeaderMethod · 0.80

Tested by

no test coverage detected