diff --git a/customers_test.go b/customers_test.go index bf5f2bc..f4d9637 100644 --- a/customers_test.go +++ b/customers_test.go @@ -11,8 +11,9 @@ import ( const testEndpoint = "https://api.test.fincode.jp/v1" func TestCustomers(t *testing.T) { + t.Parallel() ctx := context.Background() - c, err := New(Endpoint(testEndpoint)) + c, err := New(Endpoint(testEndpoint), WithHTTPClient(retryableHTTPClient(t))) if err != nil { t.Fatal(err) } diff --git a/go.mod b/go.mod index 8dd5a7d..8237e18 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( go.opentelemetry.io/otel/metric v1.25.0 go.opentelemetry.io/otel/trace v1.25.0 go.uber.org/multierr v1.11.0 + golang.org/x/sync v0.7.0 ) require ( @@ -142,7 +143,6 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/option_test.go b/option_test.go index 19d7a7b..6d37c8a 100644 --- a/option_test.go +++ b/option_test.go @@ -12,17 +12,9 @@ import ( ) func TestWithHTTPClient(t *testing.T) { + t.Parallel() ctx := context.Background() - retryClient := retryablehttp.NewClient() - retryClient.RetryMax = 10 - retryClient.Logger = nil - retryClient.CheckRetry = func(ctx context.Context, res *http.Response, err error) (bool, error) { - if res.StatusCode == 403 { - return true, nil - } - return false, nil - } - c, err := New(Endpoint(testEndpoint), WithHTTPClient(retryClient.StandardClient())) + c, err := New(Endpoint(testEndpoint), WithHTTPClient(retryableHTTPClient(t))) if err != nil { t.Fatal(err) } @@ -65,3 +57,17 @@ func TestWithHTTPClient(t *testing.T) { t.Error(err) } } + +func retryableHTTPClient(t *testing.T) *http.Client { + t.Helper() + retryClient := retryablehttp.NewClient() + retryClient.RetryMax = 10 + retryClient.Logger = nil + retryClient.CheckRetry = func(ctx context.Context, res *http.Response, err error) (bool, error) { + if res.StatusCode == 403 { + return true, nil + } + return false, nil + } + return retryClient.StandardClient() +} diff --git a/payments_test.go b/payments_test.go index 245dbbf..f60bda2 100644 --- a/payments_test.go +++ b/payments_test.go @@ -10,6 +10,7 @@ import ( ) func TestPayments(t *testing.T) { + t.Parallel() ctx := context.Background() ts := NewPaymentServer(t) opts := []runn.Option{ @@ -41,7 +42,7 @@ func TestPayments(t *testing.T) { t.Logf("customer_id: %s", customerID) t.Logf("card_id: %s", cardID) - c, err := New(Endpoint(testEndpoint)) + c, err := New(Endpoint(testEndpoint), WithHTTPClient(retryableHTTPClient(t))) if err != nil { t.Fatal(err) } diff --git a/testutil_test.go b/testutil_test.go index 8696335..32813d6 100644 --- a/testutil_test.go +++ b/testutil_test.go @@ -45,7 +45,7 @@ func NewPaymentServer(t *testing.T) *httptest.Server { t.Helper() ctx := context.Background() faker := gofakeit.NewCrypto() - c, err := New(Endpoint(testEndpoint)) + c, err := New(Endpoint(testEndpoint), WithHTTPClient(retryableHTTPClient(t))) if err != nil { t.Fatal(err) }