From 52e7af7142c1a2bf7f8d9b1d2f61007e94c8c9ca Mon Sep 17 00:00:00 2001 From: sanchayata-jain-cko <146939622+sanchayata-jain-cko@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:34:42 +0000 Subject: [PATCH] Add request telemetry for go sdk (#133) * adding telemetry for requests * add test for request metrics queue * tidied test * give option to enable telemetry in invoke function as well * add integration test for telemetry * seperate sending http request into seperate function * add readme for telemetry * fixed formatting in readme * fixed whitespace --- README.md | 14 +++ abc/checkout_previous_sdk_builder.go | 7 +- accounts/client_test.go | 30 +++-- apm/ideal/client_test.go | 3 +- apm/klarna/client_test.go | 12 +- apm/sepa/client_test.go | 6 +- balances/client_test.go | 3 +- client/client.go | 73 ++++++++--- common/request_metrics.go | 44 +++++++ common/request_metrics_test.go | 53 ++++++++ configuration/configuration.go | 17 ++- configuration/sdk_builder.go | 1 + customers/client_test.go | 12 +- disputes/client_test.go | 24 ++-- events/abc/client_test.go | 18 ++- financial/client_test.go | 3 +- forex/client_test.go | 6 +- instruments/abc/client_test.go | 12 +- instruments/nas/client_test.go | 15 ++- issuing/client_issuing_test.go | 63 ++++++---- metadata/client_test.go | 3 +- nas/checkout_default_sdk_builder.go | 7 +- nas/checkout_oauth_sdk_builder.go | 7 +- payments/abc/client_test.go | 24 ++-- payments/contexts/client_test.go | 6 +- payments/hosted/client_test.go | 6 +- payments/links/client_test.go | 6 +- payments/nas/client_test.go | 27 ++-- payments/sessions/client_test.go | 3 +- reconciliation/client_test.go | 18 ++- sessions/client_test.go | 18 ++- sources/client_test.go | 3 +- test/payment_context_test.go | 15 +-- test/telemetry_test.go | 177 +++++++++++++++++++++++++++ tokens/client_test.go | 3 +- transfers/client_test.go | 6 +- webhooks/abc/client_test.go | 18 ++- workflows/client_test.go | 51 +++++--- 38 files changed, 648 insertions(+), 166 deletions(-) create mode 100644 common/request_metrics.go create mode 100644 common/request_metrics_test.go create mode 100644 test/telemetry_test.go diff --git a/README.md b/README.md index 35be9a5..0ea77ce 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,20 @@ The execution of integration tests require the following environment variables s * For default account systems (OAuth): `CHECKOUT_DEFAULT_OAUTH_CLIENT_ID` & `CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET` * For Previous account systems (ABC): `CHECKOUT_PREVIOUS_PUBLIC_KEY` & `CHECKOUT_PREVIOUS_SECRET_KEY` +## Telemetry +Request telementry is enabled by default in the Go SDK. Request latency is included in the telemetry data. Recording the request latency allows Checkout.com to continuously monitor and imporove the merchant experience. + +Request telemetry can be disabled by opting out during checkout_sdk_builder builder step: + +``` +api := checkout.Builder(). + Previous(). + WithSecretKey("CHECKOUT_PREVIOUS_SECRET_KEY"). + WithEnvironment(configuration.Sandbox()). + WithEnableTelemetry(false). + Build() +``` + ## Code of Conduct Please refer to [Code of Conduct](CODE_OF_CONDUCT.md) diff --git a/abc/checkout_previous_sdk_builder.go b/abc/checkout_previous_sdk_builder.go index ea54e0f..9817e8f 100644 --- a/abc/checkout_previous_sdk_builder.go +++ b/abc/checkout_previous_sdk_builder.go @@ -10,6 +10,11 @@ type CheckoutPreviousSdkBuilder struct { configuration.StaticKeysBuilder } +func (b *CheckoutPreviousSdkBuilder) WithEnableTelemetry(telemetry bool) *CheckoutPreviousSdkBuilder { + b.EnableTelemetry = &telemetry + return b +} + func (b *CheckoutPreviousSdkBuilder) WithEnvironment(environment configuration.Environment) *CheckoutPreviousSdkBuilder { b.Environment = environment return b @@ -53,7 +58,7 @@ func (b *CheckoutPreviousSdkBuilder) Build() (*Api, error) { sdkCredentials := configuration.NewPreviousKeysSdkCredentials(b.SecretKey, b.PublicKey) - newConfiguration := configuration.NewConfiguration(sdkCredentials, b.Environment, b.HttpClient, b.Logger) + newConfiguration := configuration.NewConfiguration(sdkCredentials, b.EnableTelemetry, b.Environment, b.HttpClient, b.Logger) if b.EnvironmentSubdomain != nil { newConfiguration = configuration.NewConfigurationWithSubdomain(sdkCredentials, b.Environment, b.EnvironmentSubdomain, b.HttpClient, b.Logger) diff --git a/accounts/client_test.go b/accounts/client_test.go index 2a58e16..92d0ab9 100644 --- a/accounts/client_test.go +++ b/accounts/client_test.go @@ -126,11 +126,12 @@ func TestCreateEntity(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.CreateEntity(tc.request)) @@ -249,11 +250,12 @@ func TestGetEntity(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.GetEntity(tc.entityId)) @@ -369,11 +371,12 @@ func TestUpdateEntity(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.UpdateEntity(tc.entityId, tc.request)) @@ -527,11 +530,12 @@ func TestCreatePaymentInstruments(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.CreatePaymentInstruments(tc.entityId, tc.paymentInstrument)) @@ -675,11 +679,12 @@ func TestCreatePaymentInstrument(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.CreatePaymentInstrument(tc.entityId, tc.paymentInstrumentRequest)) @@ -824,11 +829,12 @@ func TestQueryPaymentInstruments(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.QueryPaymentInstruments(tc.entityId, tc.query)) @@ -973,11 +979,12 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.RetrievePaymentInstrumentDetails(tc.entityId, tc.paymentInstrumentId)) @@ -1096,11 +1103,12 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.UpdatePaymentInstrumentDetails(tc.entityId, tc.instrumentId, tc.request)) @@ -1189,11 +1197,12 @@ func TestGetPayoutSchedule(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.RetrievePayoutSchedule(tc.entityId)) @@ -1283,11 +1292,12 @@ func TestUpdatePayoutSchedule(t *testing.T) { filesClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient, filesClient) tc.checker(client.UpdatePayoutSchedule(tc.entityId, tc.currency, tc.request)) diff --git a/apm/ideal/client_test.go b/apm/ideal/client_test.go index 6e13712..fa62eaa 100644 --- a/apm/ideal/client_test.go +++ b/apm/ideal/client_test.go @@ -65,11 +65,12 @@ func TestGetInfo(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetInfo()) diff --git a/apm/klarna/client_test.go b/apm/klarna/client_test.go index dff4622..352e3c6 100644 --- a/apm/klarna/client_test.go +++ b/apm/klarna/client_test.go @@ -96,11 +96,12 @@ func TestCreateSession(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateCreditSession(tc.request)) @@ -197,11 +198,12 @@ func TestGetCreditSession(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCreditSession(tc.sessionId)) @@ -291,11 +293,12 @@ func TestCapturePayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CapturePayment(tc.paymentId, tc.request)) @@ -382,11 +385,12 @@ func TestVoidPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.VoidPayment(tc.paymentId, tc.request)) diff --git a/apm/sepa/client_test.go b/apm/sepa/client_test.go index e95f701..8cb65cc 100644 --- a/apm/sepa/client_test.go +++ b/apm/sepa/client_test.go @@ -85,11 +85,12 @@ func TestGetMandate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetMandate(tc.mandateId)) @@ -147,11 +148,12 @@ func TestCancelMandate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CancelMandate(tc.mandateId)) diff --git a/balances/client_test.go b/balances/client_test.go index 291717b..6868f7e 100644 --- a/balances/client_test.go +++ b/balances/client_test.go @@ -85,11 +85,12 @@ func TestRetrieveEntityBalances(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RetrieveEntityBalances(tc.entityId, tc.query)) diff --git a/client/client.go b/client/client.go index d5ef491..c16ade2 100644 --- a/client/client.go +++ b/client/client.go @@ -2,9 +2,13 @@ package client import ( "bytes" + "encoding/json" "io" "io/ioutil" "net/http" + "time" + + "github.com/google/uuid" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -21,21 +25,26 @@ type HttpClient interface { } type ApiClient struct { - HttpClient http.Client - BaseUri string - Log configuration.StdLogger + HttpClient http.Client + BaseUri string + EnableTelemetry bool + RequestMetricsQueue common.TelemetryQueue + Log configuration.StdLogger } const ( - CkoRequestId = "cko-request-id" - CkoVersion = "cko-version" + CkoRequestId = "cko-request-id" + CkoVersion = "cko-version" + CkoTelemetryHeader = "cko-sdk-telemetry" ) func NewApiClient(configuration *configuration.Configuration, baseUri string) *ApiClient { return &ApiClient{ - HttpClient: configuration.HttpClient, - BaseUri: baseUri, - Log: configuration.Logger, + HttpClient: configuration.HttpClient, + BaseUri: baseUri, + EnableTelemetry: configuration.EnableTelemetry, + RequestMetricsQueue: *common.NewTelemetryQueue(), + Log: configuration.Logger, } } @@ -82,12 +91,9 @@ func (a *ApiClient) invoke( } a.Log.Printf("%s: %s", method, path) - resp, err := a.HttpClient.Do(req) - if err != nil { - return err - } - return a.handleResponse(resp, responseMapping) + return a.doRequest(req, responseMapping) + } func (a *ApiClient) submit( @@ -109,12 +115,7 @@ func (a *ApiClient) submit( } a.Log.Printf("post: %s", path) - resp, err := a.HttpClient.Do(req) - if err != nil { - return err - } - - return a.handleResponse(resp, responseMapping) + return a.doRequest(req, responseMapping) } func (a *ApiClient) buildRequest( @@ -193,3 +194,37 @@ func (a *ApiClient) readBody(response *http.Response) ([]byte, error) { return body, err } + +func (a *ApiClient) doRequest(req *http.Request, responseMapping interface{}) error { + if a.EnableTelemetry { + currentRequestId := uuid.New().String() + var lastRequestMetric common.RequestMetrics + lastRequestMetric, ok := a.RequestMetricsQueue.Dequeue() + if ok { + lastRequestMetric.RequestId = currentRequestId + lastRequestMetricStr, err := json.Marshal(lastRequestMetric) + if err != nil { + return err + } + req.Header.Set(CkoTelemetryHeader, string(lastRequestMetricStr)) + } + start := time.Now() + resp, err := a.HttpClient.Do(req) + elapsed := time.Since(start) + if err != nil { + return err + } + + lastRequestMetric.PrevRequestDuration = int(elapsed.Milliseconds()) + lastRequestMetric.PrevRequestId = currentRequestId + a.RequestMetricsQueue.Enqueue(lastRequestMetric) + return a.handleResponse(resp, responseMapping) + } else { + resp, err := a.HttpClient.Do(req) + if err != nil { + return err + } + + return a.handleResponse(resp, responseMapping) + } +} diff --git a/common/request_metrics.go b/common/request_metrics.go new file mode 100644 index 0000000..302cae6 --- /dev/null +++ b/common/request_metrics.go @@ -0,0 +1,44 @@ +package common + +import "sync" + +const MaxCountInTelemetryQueue = 10 + +type RequestMetrics struct { + PrevRequestId string + RequestId string + PrevRequestDuration int +} + +type TelemetryQueue struct { + queue []RequestMetrics + mutex sync.Mutex +} + +func NewTelemetryQueue() *TelemetryQueue { + return &TelemetryQueue{ + queue: make([]RequestMetrics, 0), + } +} + +func (tq *TelemetryQueue) Enqueue(metrics RequestMetrics) { + tq.mutex.Lock() + defer tq.mutex.Unlock() + + if len(tq.queue) < MaxCountInTelemetryQueue { + tq.queue = append(tq.queue, metrics) + } +} + +func (tq *TelemetryQueue) Dequeue() (RequestMetrics, bool) { + tq.mutex.Lock() + defer tq.mutex.Unlock() + + if len(tq.queue) == 0 { + return RequestMetrics{}, false + } + + metrics := tq.queue[0] + tq.queue = tq.queue[1:] + return metrics, true +} diff --git a/common/request_metrics_test.go b/common/request_metrics_test.go new file mode 100644 index 0000000..f5c04c8 --- /dev/null +++ b/common/request_metrics_test.go @@ -0,0 +1,53 @@ +package common + +import ( + "strconv" + "sync" + "testing" +) + +const maxCountInTelemetryQueue = 10 + +func TestTelemetryQueue_Concurrency(t *testing.T) { + tq := NewTelemetryQueue() + + var wg sync.WaitGroup + numWorkers := 20 + numEnqueues := 5 + + enqueueWorker := func(id int) { + defer wg.Done() + for i := 0; i < numEnqueues; i++ { + metrics := RequestMetrics{ + PrevRequestId: "", + RequestId: strconv.Itoa(id) + "_" + strconv.Itoa(i), + PrevRequestDuration: i, + } + tq.Enqueue(metrics) + } + } + + dequeueWorker := func() { + defer wg.Done() + for i := 0; i < numEnqueues; i++ { + _, _ = tq.Dequeue() + } + } + + for i := 0; i < numWorkers; i++ { + wg.Add(1) + go enqueueWorker(i) + } + + for i := 0; i < numWorkers; i++ { + wg.Add(1) + go dequeueWorker() + } + + // Wait for all workers to finish + wg.Wait() + + if len(tq.queue) > maxCountInTelemetryQueue { + t.Errorf("Expected queue to have max %d items, but found %d items", maxCountInTelemetryQueue, len(tq.queue)) + } +} diff --git a/configuration/configuration.go b/configuration/configuration.go index ee4aa78..07f2aef 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -8,6 +8,7 @@ import ( type Configuration struct { Credentials SdkCredentials + EnableTelemetry bool Environment Environment EnvironmentSubdomain *EnvironmentSubdomain HttpClient http.Client @@ -16,6 +17,7 @@ type Configuration struct { func NewConfiguration( credentials SdkCredentials, + enableTelemertry *bool, environment Environment, client *http.Client, logger StdLogger, @@ -32,14 +34,21 @@ func NewConfiguration( logger = DefaultLogger() } + telemetry := true + if enableTelemertry != nil { + telemetry = *enableTelemertry + } + return &Configuration{ - Credentials: credentials, - Environment: environment, - HttpClient: *client, - Logger: logger, + Credentials: credentials, + EnableTelemetry: telemetry, + Environment: environment, + HttpClient: *client, + Logger: logger, } } + func NewConfigurationWithSubdomain( credentials SdkCredentials, environment Environment, diff --git a/configuration/sdk_builder.go b/configuration/sdk_builder.go index d29fdfc..27c3fd6 100644 --- a/configuration/sdk_builder.go +++ b/configuration/sdk_builder.go @@ -3,6 +3,7 @@ package configuration import "net/http" type SdkBuilder struct { + EnableTelemetry *bool Environment Environment EnvironmentSubdomain *EnvironmentSubdomain HttpClient *http.Client diff --git a/customers/client_test.go b/customers/client_test.go index ca9d558..43b792b 100644 --- a/customers/client_test.go +++ b/customers/client_test.go @@ -117,11 +117,12 @@ func TestCreate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Create(tc.request)) @@ -219,11 +220,12 @@ func TestGet(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Get(tc.customerId)) @@ -353,11 +355,12 @@ func TestUpdate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPatch(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Update(tc.customerId, tc.request)) @@ -445,11 +448,12 @@ func TestDelete(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiDelete(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Delete(tc.customerId)) diff --git a/disputes/client_test.go b/disputes/client_test.go index 4c9fc5c..4252977 100644 --- a/disputes/client_test.go +++ b/disputes/client_test.go @@ -144,11 +144,12 @@ func TestQuery(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Query(tc.query)) @@ -252,11 +253,12 @@ func TestGetDisputeDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetDisputeDetails(tc.disputeId)) @@ -343,11 +345,12 @@ func TestAccept(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Accept(tc.disputeId)) @@ -439,11 +442,12 @@ func TestPutEvidence(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.PutEvidence(tc.disputeId, tc.request)) @@ -535,11 +539,12 @@ func TestGetEvidence(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetEvidence(tc.disputeId)) @@ -626,11 +631,12 @@ func TestSubmitEvidence(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.SubmitEvidence(tc.disputeId)) @@ -729,11 +735,12 @@ func TestGetCompiledSubmittedEvidence(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCompiledSubmittedEvidence(tc.disputeId)) @@ -832,11 +839,12 @@ func TestGetDisputeSchemeFiles(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetDisputeSchemeFiles(tc.disputeId)) diff --git a/events/abc/client_test.go b/events/abc/client_test.go index de15a07..6b5d704 100644 --- a/events/abc/client_test.go +++ b/events/abc/client_test.go @@ -121,11 +121,12 @@ func TestRetrieveAllEventTypes(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetrieveAllEventTypesQuery(tc.query)) @@ -263,11 +264,12 @@ func TestRetrieveEvents(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetrieveEventsQuery(tc.query)) @@ -367,11 +369,12 @@ func TestRetrieveEvent(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetrieveEvent(tc.eventId)) @@ -472,11 +475,12 @@ func TestRetrieveEventNotification(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetrieveEventNotification(tc.eventId, tc.notificationId)) @@ -593,11 +597,12 @@ func TestRetryWebhook(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetryWebhook(tc.eventId, tc.webhookId)) @@ -689,11 +694,12 @@ func TestRetryAllWebhooks(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetryAllWebhooks(tc.eventId)) diff --git a/financial/client_test.go b/financial/client_test.go index eb03c50..5cc27d7 100644 --- a/financial/client_test.go +++ b/financial/client_test.go @@ -129,11 +129,12 @@ func TestGetFinancialActions(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetFinancialActions(tc.query)) diff --git a/forex/client_test.go b/forex/client_test.go index 04fe5c7..11f461e 100644 --- a/forex/client_test.go +++ b/forex/client_test.go @@ -102,11 +102,12 @@ func TestRequestQuote(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestQuote(tc.request)) @@ -227,11 +228,12 @@ func TestGetRates(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetRates(tc.query)) diff --git a/instruments/abc/client_test.go b/instruments/abc/client_test.go index 40b08ef..3e7bcdd 100644 --- a/instruments/abc/client_test.go +++ b/instruments/abc/client_test.go @@ -126,11 +126,12 @@ func TestCreate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Create(tc.request)) @@ -229,11 +230,12 @@ func TestGet(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Get(tc.instrumentId)) @@ -363,11 +365,12 @@ func TestUpdate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPatch(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Update(tc.instrumentId, tc.request)) @@ -454,11 +457,12 @@ func TestDelete(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiDelete(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Delete(tc.instrumentId)) diff --git a/instruments/nas/client_test.go b/instruments/nas/client_test.go index a515526..32e2807 100644 --- a/instruments/nas/client_test.go +++ b/instruments/nas/client_test.go @@ -215,11 +215,12 @@ func TestCreate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Create(tc.request)) @@ -357,11 +358,12 @@ func TestGet(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Get(tc.instrumentId)) @@ -507,11 +509,12 @@ func TestClientGetBankAccountFieldFormatting(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetBankAccountFieldFormatting(tc.country, tc.currency, tc.query)) @@ -641,11 +644,12 @@ func TestUpdate(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPatch(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Update(tc.instrumentId, tc.request)) @@ -732,11 +736,12 @@ func TestDelete(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiDelete(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Delete(tc.instrumentId)) diff --git a/issuing/client_issuing_test.go b/issuing/client_issuing_test.go index ab99ff8..6fed1a2 100644 --- a/issuing/client_issuing_test.go +++ b/issuing/client_issuing_test.go @@ -192,11 +192,12 @@ func TestCreateCardholder(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateCardholder(tc.request)) @@ -302,11 +303,12 @@ func TestGetCardholder(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardholder(tc.cardholderId)) @@ -381,11 +383,12 @@ func TestGetCardholderCards(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardholderCards(tc.cardholderId)) @@ -431,11 +434,12 @@ func TestCreateCard(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateCard(tc.request)) @@ -480,11 +484,12 @@ func TestGetCardDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardDetails(tc.cardId)) @@ -532,11 +537,12 @@ func TestEnrollThreeDS(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.EnrollThreeDS(tc.cardId, tc.request)) @@ -584,11 +590,12 @@ func TestUpdateThreeDS(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.UpdateThreeDS(tc.cardId, tc.request)) @@ -633,11 +640,12 @@ func TestGetCardThreeDSDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardThreeDSDetails(tc.cardId)) @@ -682,11 +690,12 @@ func TestActivateCard(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.ActivateCard(tc.cardId)) @@ -733,11 +742,12 @@ func TestGetCardCredentials(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardCredentials(tc.cardId, tc.query)) @@ -785,11 +795,12 @@ func TestRevokeCard(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RevokeCard(tc.cardId, tc.request)) @@ -834,11 +845,12 @@ func TestSuspendCard(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.SuspendCard(tc.cardId)) @@ -884,11 +896,12 @@ func TestCreateControl(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateControl(tc.request)) @@ -934,11 +947,12 @@ func TestGetCardControls(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardControls(tc.query)) @@ -983,11 +997,12 @@ func TestGetCardControlDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetCardControlDetails(tc.controlId)) @@ -1035,11 +1050,12 @@ func TestUpdateCardControl(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiUpdate(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.UpdateCardControl(tc.controlId, tc.request)) @@ -1084,11 +1100,12 @@ func TestRemoveCardControl(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiDelete(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RemoveCardControl(tc.controlId)) @@ -1134,11 +1151,12 @@ func TestSimulateAuthorization(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.SimulateAuthorization(tc.request)) @@ -1230,11 +1248,12 @@ func TestSimulateIncrement(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.SimulateIncrement(tc.transactionId, tc.request)) @@ -1324,11 +1343,12 @@ func TestSimulateClearing(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.SimulateClearing(tc.transactionId, tc.request)) @@ -1420,11 +1440,12 @@ func TestSimulateReversal(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.SimulateReversal(tc.transactionId, tc.request)) diff --git a/metadata/client_test.go b/metadata/client_test.go index a204fa9..9004a3e 100644 --- a/metadata/client_test.go +++ b/metadata/client_test.go @@ -108,11 +108,12 @@ func TestRequestQuote(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestCardMetadata(tc.request)) diff --git a/nas/checkout_default_sdk_builder.go b/nas/checkout_default_sdk_builder.go index 1075424..4a504fa 100644 --- a/nas/checkout_default_sdk_builder.go +++ b/nas/checkout_default_sdk_builder.go @@ -10,6 +10,11 @@ type CheckoutDefaultSdkBuilder struct { configuration.StaticKeysBuilder } +func (b *CheckoutDefaultSdkBuilder) WithEnableTelemetry(telemetry bool) *CheckoutDefaultSdkBuilder { + b.EnableTelemetry = &telemetry + return b +} + func (b *CheckoutDefaultSdkBuilder) WithEnvironment(environment configuration.Environment) *CheckoutDefaultSdkBuilder { b.Environment = environment return b @@ -53,7 +58,7 @@ func (b *CheckoutDefaultSdkBuilder) Build() (*Api, error) { sdkCredentials := configuration.NewDefaultKeysSdkCredentials(b.SecretKey, b.PublicKey) - newConfiguration := configuration.NewConfiguration(sdkCredentials, b.Environment, b.HttpClient, b.Logger) + newConfiguration := configuration.NewConfiguration(sdkCredentials, b.EnableTelemetry, b.Environment, b.HttpClient, b.Logger) if b.EnvironmentSubdomain != nil { newConfiguration = configuration.NewConfigurationWithSubdomain(sdkCredentials, b.Environment, b.EnvironmentSubdomain, b.HttpClient, b.Logger) diff --git a/nas/checkout_oauth_sdk_builder.go b/nas/checkout_oauth_sdk_builder.go index c427ccc..fa26244 100644 --- a/nas/checkout_oauth_sdk_builder.go +++ b/nas/checkout_oauth_sdk_builder.go @@ -31,6 +31,11 @@ func (b *CheckoutOAuthSdkBuilder) WithScopes(scopes []string) *CheckoutOAuthSdkB return b } +func (b *CheckoutOAuthSdkBuilder) WithEnableTelemetry(telemetry bool) *CheckoutOAuthSdkBuilder { + b.EnableTelemetry = &telemetry + return b +} + func (b *CheckoutOAuthSdkBuilder) WithEnvironment(environment configuration.Environment) *CheckoutOAuthSdkBuilder { b.Environment = environment return b @@ -70,7 +75,7 @@ func (b *CheckoutOAuthSdkBuilder) Build() (*Api, error) { return nil, err } - newConfiguration := configuration.NewConfiguration(sdkCredentials, b.Environment, b.HttpClient, b.Logger) + newConfiguration := configuration.NewConfiguration(sdkCredentials, b.EnableTelemetry, b.Environment, b.HttpClient, b.Logger) if b.EnvironmentSubdomain != nil { newConfiguration = configuration.NewConfigurationWithSubdomain(sdkCredentials, b.Environment, b.EnvironmentSubdomain, b.HttpClient, b.Logger) diff --git a/payments/abc/client_test.go b/payments/abc/client_test.go index c02b7e8..90f0466 100644 --- a/payments/abc/client_test.go +++ b/payments/abc/client_test.go @@ -140,11 +140,12 @@ func TestRequestPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPayment(tc.request, tc.idempotencyKey)) @@ -265,11 +266,12 @@ func TestRequestPaymentList(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPaymentList(tc.queryRequest)) @@ -384,11 +386,12 @@ func TestRequestPayout(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPayout(tc.request, tc.idempotencyKey)) @@ -488,11 +491,12 @@ func TestGetPaymentDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetPaymentDetails(tc.paymentId)) @@ -598,11 +602,12 @@ func TestGetPaymentActions(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetPaymentActions(tc.paymentId)) @@ -754,11 +759,12 @@ func TestCapturePayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CapturePayment(tc.paymentId, tc.request, tc.idempotencyKey)) @@ -907,11 +913,12 @@ func TestRefundPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RefundPayment(tc.paymentId, &tc.request, tc.idempotencyKey)) @@ -1059,11 +1066,12 @@ func TestVoidPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.VoidPayment(tc.paymentId, &tc.request, tc.idempotencyKey)) diff --git a/payments/contexts/client_test.go b/payments/contexts/client_test.go index 4f7ad66..6bca511 100644 --- a/payments/contexts/client_test.go +++ b/payments/contexts/client_test.go @@ -114,11 +114,12 @@ func TestCreateAPaymentContext(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPaymentContexts(tc.request)) @@ -222,11 +223,12 @@ func TestGetAPaymentContext(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetPaymentContextDetails(tc.paymentContextId)) diff --git a/payments/hosted/client_test.go b/payments/hosted/client_test.go index 5f3c76a..0b34786 100644 --- a/payments/hosted/client_test.go +++ b/payments/hosted/client_test.go @@ -105,11 +105,12 @@ func TestCreateHostedPaymentsPageSession(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateHostedPaymentsPageSession(tc.request)) @@ -211,11 +212,12 @@ func TestGetHostedPaymentsPageDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetHostedPaymentsPageDetails(tc.hostedPaymentId)) diff --git a/payments/links/client_test.go b/payments/links/client_test.go index ba76ccd..aef4e3b 100644 --- a/payments/links/client_test.go +++ b/payments/links/client_test.go @@ -105,11 +105,12 @@ func TestCreatePaymentLink(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreatePaymentLink(tc.request)) @@ -211,11 +212,12 @@ func TestGetPaymentLink(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetPaymentLink(tc.paymentLinkId)) diff --git a/payments/nas/client_test.go b/payments/nas/client_test.go index 82e275a..5d9edf1 100644 --- a/payments/nas/client_test.go +++ b/payments/nas/client_test.go @@ -141,11 +141,12 @@ func TestRequestPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPayment(tc.request, tc.idempotencyKey)) @@ -267,11 +268,12 @@ func TestRequestPaymentList(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPaymentList(tc.queryRequest)) @@ -377,11 +379,12 @@ func TestRequestPayout(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPayout(tc.request, tc.idempotencyKey)) @@ -481,11 +484,12 @@ func TestGetPaymentDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetPaymentDetails(tc.paymentId)) @@ -591,11 +595,12 @@ func TestGetPaymentActions(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetPaymentActions(tc.paymentId)) @@ -790,11 +795,12 @@ func TestIncrementAuthorization(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.IncrementAuthorization(tc.paymentId, tc.request, tc.idempotencyKey)) @@ -946,11 +952,12 @@ func TestCapturePayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CapturePayment(tc.paymentId, tc.request, tc.idempotencyKey)) @@ -1099,11 +1106,12 @@ func TestRefundPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RefundPayment(tc.paymentId, &tc.request, tc.idempotencyKey)) @@ -1251,11 +1259,12 @@ func TestVoidPayment(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.VoidPayment(tc.paymentId, &tc.request, tc.idempotencyKey)) diff --git a/payments/sessions/client_test.go b/payments/sessions/client_test.go index 8a70637..b360cd4 100644 --- a/payments/sessions/client_test.go +++ b/payments/sessions/client_test.go @@ -116,11 +116,12 @@ func TestCreateAPaymentSessions(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestPaymentSessions(tc.request)) diff --git a/reconciliation/client_test.go b/reconciliation/client_test.go index dcfd241..0da3fcc 100644 --- a/reconciliation/client_test.go +++ b/reconciliation/client_test.go @@ -92,11 +92,12 @@ func TestQueryPaymentsReport(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.QueryPaymentsReport(tc.query)) @@ -197,11 +198,12 @@ func TestGetSinglePaymentReport(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetSinglePaymentReport(tc.paymentId)) @@ -290,11 +292,12 @@ func TestQueryStatementsReport(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.QueryStatementsReport(tc.query)) @@ -369,11 +372,12 @@ func TestRetrieveCVSPaymentsReport(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RetrieveCVSPaymentsReport(tc.query)) @@ -465,11 +469,12 @@ func TestRetrieveCVSSingleStatementReport(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RetrieveCVSSingleStatementReport(tc.statementId)) @@ -544,11 +549,12 @@ func TestRetrieveCVSStatementsReport(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RetrieveCVSStatementsReport(tc.query)) diff --git a/sessions/client_test.go b/sessions/client_test.go index b2a7657..9c1565d 100644 --- a/sessions/client_test.go +++ b/sessions/client_test.go @@ -117,11 +117,12 @@ func TestRequestSession(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestSession(tc.request)) @@ -219,11 +220,12 @@ func TestGetSessionDetails(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetSessionDetails(tc.sessionId, "")) @@ -321,11 +323,12 @@ func TestUpdateSession(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.UpdateSession(tc.sessionId, tc.request, "")) @@ -412,11 +415,12 @@ func TestCompleteSession(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CompleteSession(tc.sessionId, "")) @@ -510,11 +514,12 @@ func TestUpdate3dsMethodCompletion(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Update3dsMethodCompletion(tc.sessionId, tc.request, "")) @@ -567,10 +572,11 @@ func TestCustomSdkAuthorization(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.customSdkAuthorization(tc.sessionSecret)) diff --git a/sources/client_test.go b/sources/client_test.go index e928d14..cd860ea 100644 --- a/sources/client_test.go +++ b/sources/client_test.go @@ -120,11 +120,12 @@ func TestCreateSepaSource(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateSepaSource(tc.request)) diff --git a/test/payment_context_test.go b/test/payment_context_test.go index 14e0817..491cf31 100644 --- a/test/payment_context_test.go +++ b/test/payment_context_test.go @@ -1,14 +1,12 @@ package test import ( - "net/http" "os" "testing" "github.com/stretchr/testify/assert" "github.com/checkout/checkout-sdk-go/common" - "github.com/checkout/checkout-sdk-go/errors" "github.com/checkout/checkout-sdk-go/payments" "github.com/checkout/checkout-sdk-go/payments/contexts" sources "github.com/checkout/checkout-sdk-go/payments/nas/sources/contexts" @@ -98,11 +96,14 @@ func TestRequestPaymentContextKlarna(t *testing.T) { name: "test Klarna source for request payment contexts", request: paymentContextsKlarnaRequest, checker: func(response *contexts.PaymentContextsRequestResponse, err error) { - assert.NotNil(t, err) - assert.Nil(t, response) - ckoErr := err.(errors.CheckoutAPIError) - assert.Equal(t, http.StatusUnprocessableEntity, ckoErr.StatusCode) - assert.Equal(t, "apm_service_unavailable", ckoErr.Data.ErrorCodes[0]) + assert.Nil(t, err) + assert.NotNil(t, response) + assert.Equal(t, 201, response.HttpMetadata.StatusCode) + assert.NotNil(t, response.PartnerMetadata.ClientToken) + assert.NotNil(t, response.PartnerMetadata.SessionId) + if response.Links != nil { + assert.NotNil(t, response.Links) + } }, }, } diff --git a/test/telemetry_test.go b/test/telemetry_test.go new file mode 100644 index 0000000..cfa2b83 --- /dev/null +++ b/test/telemetry_test.go @@ -0,0 +1,177 @@ +package test + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "os" + "testing" + "time" + + "github.com/checkout/checkout-sdk-go" + "github.com/checkout/checkout-sdk-go/abc" + "github.com/checkout/checkout-sdk-go/configuration" + "github.com/stretchr/testify/assert" +) + +// mockHTTPClient is a helper struct to create a mock HTTP server and capture incoming requests. +type mockHTTPClient struct { + server *httptest.Server + requestsReceived []*http.Request +} + +// newMockHTTPClient initializes a new mockHTTPClient with a TLS test server, optionally introducing a delay. +func newMockHTTPClient(delay time.Duration) *mockHTTPClient { + mock := &mockHTTPClient{ + requestsReceived: []*http.Request{}, + } + + // Create a new TLS test server with a handler that records incoming requests and introduces a delay. + mock.server = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Simulate server processing delay. + time.Sleep(delay) + // Clone and store the request for inspection. + mock.requestsReceived = append(mock.requestsReceived, r.Clone(context.Background())) + // Respond with a 200 OK status. + w.WriteHeader(http.StatusOK) + })) + return mock +} + +// Client returns an HTTP client configured to communicate with the mock server. +func (m *mockHTTPClient) Client() *http.Client { + return m.server.Client() +} + +// Close shuts down the mock server. +func (m *mockHTTPClient) Close() { + m.server.Close() +} + +// CountRequestsWithHeader counts the number of recorded requests that include a specific header. +func (m *mockHTTPClient) CountRequestsWithHeader(header string) int { + count := 0 + headerKey := http.CanonicalHeaderKey(header) // Normalize header name. + for _, req := range m.requestsReceived { + if _, ok := req.Header[headerKey]; ok { + count++ + } + } + return count +} + +// createMockEnvironment creates a mock environment using the mock server's URL. +func createMockEnvironment(mockServerURL string) *configuration.CheckoutEnv { + return configuration.NewEnvironment( + mockServerURL, // baseUri + mockServerURL, // authorizationUri + mockServerURL, // filesUri + mockServerURL, // transfersUri + mockServerURL, // balancesUri + true, // isSandbox + ) +} + +// createCheckoutApi initializes the Checkout API client with the given parameters. +func createCheckoutApi(mock *mockHTTPClient, enableTelemetry bool) (*abc.Api, error) { + // Retrieve public and secret keys from environment variables. + publicKey := os.Getenv("CHECKOUT_PREVIOUS_PUBLIC_KEY") + secretKey := os.Getenv("CHECKOUT_PREVIOUS_SECRET_KEY") + + // Ensure that the keys are set. + if publicKey == "" || secretKey == "" { + return nil, fmt.Errorf("public and secret keys must be set in environment variables") + } + + // Build the Checkout API client with the mock environment and client. + builder := checkout.Builder(). + Previous(). + WithPublicKey(publicKey). + WithSecretKey(secretKey). + WithEnvironment(createMockEnvironment(mock.server.URL)). + WithHttpClient(mock.Client()) + + // Enable or disable telemetry based on the parameter. + if !enableTelemetry { + builder = builder.WithEnableTelemetry(false) + } + + return builder.Build() +} + +// TestShouldSendTelemetryByDefault verifies that telemetry headers are sent by default. +func TestShouldSendTelemetryByDefault(t *testing.T) { + mock := newMockHTTPClient(0) // No delay. + defer mock.Close() + + // Initialize the Checkout API client with telemetry enabled (default). + checkoutApi, err := createCheckoutApi(mock, true) + assert.NoError(t, err) + assert.NotNil(t, checkoutApi) + + // Make multiple API calls to generate telemetry data. + for i := 0; i < 3; i++ { + _, err := checkoutApi.Events.RetrieveAllEventTypes() + assert.NoError(t, err) + } + + // Telemetry headers are included starting from the second request. + expectedTelemetryHeaderCount := 2 // Telemetry is sent in the 2nd and 3rd requests. + telemetryHeaderCount := mock.CountRequestsWithHeader("cko-sdk-telemetry") + assert.Equal(t, expectedTelemetryHeaderCount, telemetryHeaderCount, "Expected exactly %d requests to contain the telemetry header", expectedTelemetryHeaderCount) +} + +// TestShouldNotSendTelemetryWhenOptedOut verifies that telemetry headers are not sent when telemetry is disabled. +func TestShouldNotSendTelemetryWhenOptedOut(t *testing.T) { + mock := newMockHTTPClient(0) // No delay. + defer mock.Close() + + // Initialize the Checkout API client with telemetry disabled. + checkoutApi, err := createCheckoutApi(mock, false) + assert.NoError(t, err) + assert.NotNil(t, checkoutApi) + + // Make multiple API calls. + for i := 0; i < 3; i++ { + _, err := checkoutApi.Events.RetrieveAllEventTypes() + assert.NoError(t, err) + } + + // Verify that no telemetry headers were sent. + telemetryHeaderCount := mock.CountRequestsWithHeader("cko-sdk-telemetry") + assert.Equal(t, 0, telemetryHeaderCount, "Expected no requests to contain the telemetry header") +} + +// TestTelemetryQueueAndBottleneck simulates rapid requests to test telemetry queuing and bottleneck handling. +func TestTelemetryQueueAndBottleneck(t *testing.T) { + // Introduce a delay to simulate server bottleneck. + delay := 100 * time.Millisecond + mock := newMockHTTPClient(delay) + defer mock.Close() + + // Initialize the Checkout API client with telemetry enabled. + checkoutApi, err := createCheckoutApi(mock, true) + assert.NoError(t, err) + assert.NotNil(t, checkoutApi) + + // Number of requests to simulate. + numRequests := 10 + + // Make multiple API calls rapidly to generate telemetry data. + for i := 0; i < numRequests; i++ { + _, err := checkoutApi.Events.RetrieveAllEventTypes() + assert.NoError(t, err) + } + + // Wait for all requests to be processed. + time.Sleep(time.Duration(numRequests)*delay + 1*time.Second) + + // Count the number of requests that included the telemetry header. + telemetryHeaderCount := mock.CountRequestsWithHeader("cko-sdk-telemetry") + + // Since telemetry starts being sent from the second request, we expect (numRequests - 1) telemetry headers. + expectedTelemetryHeaderCount := numRequests - 1 + + assert.Equal(t, expectedTelemetryHeaderCount, telemetryHeaderCount, "Expected %d requests to contain the telemetry header", expectedTelemetryHeaderCount) +} diff --git a/tokens/client_test.go b/tokens/client_test.go index 7c0d8c4..f7faac2 100644 --- a/tokens/client_test.go +++ b/tokens/client_test.go @@ -129,11 +129,12 @@ func TestRequestCardToken(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RequestCardToken(tc.request)) diff --git a/transfers/client_test.go b/transfers/client_test.go index 5e0aca0..a1b2a50 100644 --- a/transfers/client_test.go +++ b/transfers/client_test.go @@ -108,11 +108,12 @@ func TestInitiateTransferOfFounds(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.InitiateTransferOfFounds(tc.request, nil)) @@ -224,11 +225,12 @@ func TestRetrieveTransfer(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RetrieveTransfer(tc.transferId)) diff --git a/webhooks/abc/client_test.go b/webhooks/abc/client_test.go index ce48021..1c019f4 100644 --- a/webhooks/abc/client_test.go +++ b/webhooks/abc/client_test.go @@ -121,11 +121,12 @@ func TestClientRetrieveWebhooks(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetrieveWebhooks()) @@ -267,11 +268,12 @@ func TestClientRegisterWebhook(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RegisterWebhook(tc.request)) @@ -387,11 +389,12 @@ func TestClientRetrieveWebhook(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RetrieveWebhook(tc.webhookId)) @@ -581,11 +584,12 @@ func TestClientUpdateWebhook(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiUpdate(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.UpdateWebhook(tc.webhookId, tc.webhookRequest)) @@ -775,11 +779,12 @@ func TestClientPartiallyUpdateWebhook(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPatch(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.PartiallyUpdateWebhook(tc.webhookId, tc.webhookRequest)) @@ -874,11 +879,12 @@ func TestClientRemoveWebhook(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiDelete(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) eventsClient := NewClient(configuration, apiClient) tc.checker(eventsClient.RemoveWebhook(tc.webhookId)) diff --git a/workflows/client_test.go b/workflows/client_test.go index 94806e6..1901394 100644 --- a/workflows/client_test.go +++ b/workflows/client_test.go @@ -111,11 +111,12 @@ func TestCreateWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.CreateWorkflow(tc.request)) @@ -188,11 +189,12 @@ func TestGetWorkflows(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetWorkflows()) @@ -292,11 +294,12 @@ func TestGetWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetWorkflow(tc.workflowId)) @@ -395,11 +398,12 @@ func TestUpdateWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPatch(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.UpdateWorkflow(tc.workflowId, tc.request)) @@ -486,11 +490,12 @@ func TestRemoveWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiDelete(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.RemoveWorkflow(tc.workflowId)) @@ -607,11 +612,12 @@ func TestUpdateWorkflowAction(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.UpdateWorkflowAction(tc.workflowId, tc.actionId, tc.request)) @@ -728,11 +734,12 @@ func TestUpdateWorkflowCondition(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPut(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.UpdateWorkflowCondition(tc.workflowId, tc.conditionId, tc.request)) @@ -843,11 +850,12 @@ func TestTestWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.TestWorkflow(tc.workflowId, tc.request)) @@ -922,11 +930,12 @@ func TestGetEventTypes(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetEventTypes()) @@ -1026,11 +1035,12 @@ func TestGetEvent(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetEvent(tc.eventId)) @@ -1128,11 +1138,12 @@ func TestGetSubjectEvents(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetSubjectEvents(tc.subjectId)) @@ -1219,11 +1230,12 @@ func TestReflowByEvent(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.ReflowByEvent(tc.eventId)) @@ -1310,11 +1322,12 @@ func TestReflowBySubject(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.ReflowBySubject(tc.subjectId)) @@ -1427,11 +1440,12 @@ func TestReflowByEventAndWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.ReflowByEventAndWorkflow(tc.eventId, tc.workflowId)) @@ -1544,11 +1558,12 @@ func TestReflowBySubjectAndWorkflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.ReflowBySubjectAndWorkflow(tc.subjectId, tc.workflowId)) @@ -1669,11 +1684,12 @@ func TestReflow(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiPost(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.Reflow(tc.request)) @@ -1801,11 +1817,12 @@ func TestGetActionInvocations(t *testing.T) { apiClient := new(mocks.ApiClientMock) credentials := new(mocks.CredentialsMock) environment := new(mocks.EnvironmentMock) + enableTelemertry := true tc.getAuthorization(&credentials.Mock) tc.apiGet(&apiClient.Mock) - configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + configuration := configuration.NewConfiguration(credentials, &enableTelemertry, environment, &http.Client{}, nil) client := NewClient(configuration, apiClient) tc.checker(client.GetActionInvocations(tc.eventId, tc.actionId))