satellite/payments/stripecoinpayments: fix mock data-race
`len(m.attached)` was used without locking. Also, use gofumpt to make whitespace usage more consistent. Change-Id: Ifa9deedc8451f0c54e84d6ac3c2bdc1807688989
This commit is contained in:
parent
78fa0c11a3
commit
d2f4ea1f24
@ -27,7 +27,6 @@ import (
|
||||
)
|
||||
|
||||
func TestSignupCouponCodes(t *testing.T) {
|
||||
|
||||
testplanet.Run(t, testplanet.Config{SatelliteCount: 1}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
sat := planet.Satellites[0]
|
||||
db := sat.DB
|
||||
|
@ -62,7 +62,6 @@ func (coupons *coupons) GetByUserID(ctx context.Context, userID uuid.UUID) (_ *p
|
||||
defer mon.Task()(&ctx, userID)(&err)
|
||||
|
||||
customerID, err := coupons.service.db.Customers().GetCustomerID(ctx, userID)
|
||||
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ func TestCustomersRepositoryList(t *testing.T) {
|
||||
|
||||
for i, cus := range page.Customers {
|
||||
assert.Equal(t, "customerID"+strconv.Itoa(2-i), cus.ID)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ type Service struct {
|
||||
|
||||
// NewService creates a Service instance.
|
||||
func NewService(log *zap.Logger, stripeClient StripeClient, config Config, db DB, projectsDB console.Projects, usageDB accounting.ProjectAccounting, storageTBPrice, egressTBPrice, segmentPrice string, bonusRate int64) (*Service, error) {
|
||||
|
||||
coinPaymentsClient := coinpayments.NewClient(
|
||||
coinpayments.Credentials{
|
||||
PublicKey: config.CoinpaymentsPublicKey,
|
||||
|
@ -251,7 +251,7 @@ func TestService_InvoiceItemsFromProjectRecord(t *testing.T) {
|
||||
SegmentsQuantity int64
|
||||
}
|
||||
|
||||
var testCases = []TestCase{
|
||||
testCases := []TestCase{
|
||||
{}, // all zeros
|
||||
{
|
||||
Storage: 10000000000, // Byte-Hours
|
||||
|
@ -259,7 +259,6 @@ func (m *mockCustomers) New(params *stripe.CustomerParams) (*stripe.Customer, er
|
||||
|
||||
func (m *mockCustomers) Get(id string, params *stripe.CustomerParams) (*stripe.Customer, error) {
|
||||
if err := m.repopulate(); err != nil {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -331,6 +330,9 @@ func (c *listContainer) GetListMeta() *stripe.ListMeta {
|
||||
}
|
||||
|
||||
func (m *mockPaymentMethods) List(listParams *stripe.PaymentMethodListParams) *paymentmethod.Iter {
|
||||
mocks.Lock()
|
||||
defer mocks.Unlock()
|
||||
|
||||
listMeta := &stripe.ListMeta{
|
||||
HasMore: false,
|
||||
TotalCount: uint32(len(m.attached)),
|
||||
@ -338,9 +340,6 @@ func (m *mockPaymentMethods) List(listParams *stripe.PaymentMethodListParams) *p
|
||||
lc := newListContainer(listMeta)
|
||||
|
||||
query := stripe.Query(func(*stripe.Params, *form.Values) ([]interface{}, stripe.ListContainer, error) {
|
||||
mocks.Lock()
|
||||
defer mocks.Unlock()
|
||||
|
||||
list, ok := m.attached[*listParams.Customer]
|
||||
if !ok {
|
||||
list = []*stripe.PaymentMethod{}
|
||||
@ -357,7 +356,6 @@ func (m *mockPaymentMethods) List(listParams *stripe.PaymentMethodListParams) *p
|
||||
}
|
||||
|
||||
func (m *mockPaymentMethods) New(params *stripe.PaymentMethodParams) (*stripe.PaymentMethod, error) {
|
||||
|
||||
randID := testrand.BucketName()
|
||||
newMethod := &stripe.PaymentMethod{
|
||||
ID: fmt.Sprintf("pm_card_%s", randID),
|
||||
@ -380,11 +378,10 @@ func (m *mockPaymentMethods) New(params *stripe.PaymentMethodParams) (*stripe.Pa
|
||||
}
|
||||
|
||||
func (m *mockPaymentMethods) Attach(id string, params *stripe.PaymentMethodAttachParams) (*stripe.PaymentMethod, error) {
|
||||
var method *stripe.PaymentMethod
|
||||
|
||||
mocks.Lock()
|
||||
defer mocks.Unlock()
|
||||
|
||||
var method *stripe.PaymentMethod
|
||||
for _, candidate := range m.unattached {
|
||||
if candidate.ID == id {
|
||||
method = candidate
|
||||
@ -399,11 +396,10 @@ func (m *mockPaymentMethods) Attach(id string, params *stripe.PaymentMethodAttac
|
||||
}
|
||||
|
||||
func (m *mockPaymentMethods) Detach(id string, params *stripe.PaymentMethodDetachParams) (*stripe.PaymentMethod, error) {
|
||||
var unattached *stripe.PaymentMethod
|
||||
|
||||
mocks.Lock()
|
||||
defer mocks.Unlock()
|
||||
|
||||
var unattached *stripe.PaymentMethod
|
||||
for user, userMethods := range m.attached {
|
||||
var remaining []*stripe.PaymentMethod
|
||||
for _, method := range userMethods {
|
||||
|
@ -71,7 +71,7 @@ type TransactionsPage struct {
|
||||
|
||||
// IDList returns transaction id list of page's transactions.
|
||||
func (page *TransactionsPage) IDList() TransactionAndUserList {
|
||||
var ids = make(TransactionAndUserList)
|
||||
ids := make(TransactionAndUserList)
|
||||
for _, tx := range page.Transactions {
|
||||
ids[tx.ID] = tx.AccountID
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user