(t *testing.T)
| 18 | var qa = question.NewAskProvider(nil) |
| 19 | |
| 20 | func 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) { |
nothing calls this directly
no test coverage detected