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) {
|
func TestSignupCouponCodes(t *testing.T) {
|
||||||
|
|
||||||
testplanet.Run(t, testplanet.Config{SatelliteCount: 1}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
testplanet.Run(t, testplanet.Config{SatelliteCount: 1}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||||
sat := planet.Satellites[0]
|
sat := planet.Satellites[0]
|
||||||
db := sat.DB
|
db := sat.DB
|
||||||
|
@ -62,7 +62,6 @@ func (coupons *coupons) GetByUserID(ctx context.Context, userID uuid.UUID) (_ *p
|
|||||||
defer mon.Task()(&ctx, userID)(&err)
|
defer mon.Task()(&ctx, userID)(&err)
|
||||||
|
|
||||||
customerID, err := coupons.service.db.Customers().GetCustomerID(ctx, userID)
|
customerID, err := coupons.service.db.Customers().GetCustomerID(ctx, userID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Error.Wrap(err)
|
return nil, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,6 @@ func TestCustomersRepositoryList(t *testing.T) {
|
|||||||
|
|
||||||
for i, cus := range page.Customers {
|
for i, cus := range page.Customers {
|
||||||
assert.Equal(t, "customerID"+strconv.Itoa(2-i), cus.ID)
|
assert.Equal(t, "customerID"+strconv.Itoa(2-i), cus.ID)
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,6 @@ type Service struct {
|
|||||||
|
|
||||||
// NewService creates a Service instance.
|
// 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) {
|
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(
|
coinPaymentsClient := coinpayments.NewClient(
|
||||||
coinpayments.Credentials{
|
coinpayments.Credentials{
|
||||||
PublicKey: config.CoinpaymentsPublicKey,
|
PublicKey: config.CoinpaymentsPublicKey,
|
||||||
|
@ -251,7 +251,7 @@ func TestService_InvoiceItemsFromProjectRecord(t *testing.T) {
|
|||||||
SegmentsQuantity int64
|
SegmentsQuantity int64
|
||||||
}
|
}
|
||||||
|
|
||||||
var testCases = []TestCase{
|
testCases := []TestCase{
|
||||||
{}, // all zeros
|
{}, // all zeros
|
||||||
{
|
{
|
||||||
Storage: 10000000000, // Byte-Hours
|
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) {
|
func (m *mockCustomers) Get(id string, params *stripe.CustomerParams) (*stripe.Customer, error) {
|
||||||
if err := m.repopulate(); err != nil {
|
if err := m.repopulate(); err != nil {
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,6 +330,9 @@ func (c *listContainer) GetListMeta() *stripe.ListMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPaymentMethods) List(listParams *stripe.PaymentMethodListParams) *paymentmethod.Iter {
|
func (m *mockPaymentMethods) List(listParams *stripe.PaymentMethodListParams) *paymentmethod.Iter {
|
||||||
|
mocks.Lock()
|
||||||
|
defer mocks.Unlock()
|
||||||
|
|
||||||
listMeta := &stripe.ListMeta{
|
listMeta := &stripe.ListMeta{
|
||||||
HasMore: false,
|
HasMore: false,
|
||||||
TotalCount: uint32(len(m.attached)),
|
TotalCount: uint32(len(m.attached)),
|
||||||
@ -338,9 +340,6 @@ func (m *mockPaymentMethods) List(listParams *stripe.PaymentMethodListParams) *p
|
|||||||
lc := newListContainer(listMeta)
|
lc := newListContainer(listMeta)
|
||||||
|
|
||||||
query := stripe.Query(func(*stripe.Params, *form.Values) ([]interface{}, stripe.ListContainer, error) {
|
query := stripe.Query(func(*stripe.Params, *form.Values) ([]interface{}, stripe.ListContainer, error) {
|
||||||
mocks.Lock()
|
|
||||||
defer mocks.Unlock()
|
|
||||||
|
|
||||||
list, ok := m.attached[*listParams.Customer]
|
list, ok := m.attached[*listParams.Customer]
|
||||||
if !ok {
|
if !ok {
|
||||||
list = []*stripe.PaymentMethod{}
|
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) {
|
func (m *mockPaymentMethods) New(params *stripe.PaymentMethodParams) (*stripe.PaymentMethod, error) {
|
||||||
|
|
||||||
randID := testrand.BucketName()
|
randID := testrand.BucketName()
|
||||||
newMethod := &stripe.PaymentMethod{
|
newMethod := &stripe.PaymentMethod{
|
||||||
ID: fmt.Sprintf("pm_card_%s", randID),
|
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) {
|
func (m *mockPaymentMethods) Attach(id string, params *stripe.PaymentMethodAttachParams) (*stripe.PaymentMethod, error) {
|
||||||
var method *stripe.PaymentMethod
|
|
||||||
|
|
||||||
mocks.Lock()
|
mocks.Lock()
|
||||||
defer mocks.Unlock()
|
defer mocks.Unlock()
|
||||||
|
|
||||||
|
var method *stripe.PaymentMethod
|
||||||
for _, candidate := range m.unattached {
|
for _, candidate := range m.unattached {
|
||||||
if candidate.ID == id {
|
if candidate.ID == id {
|
||||||
method = candidate
|
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) {
|
func (m *mockPaymentMethods) Detach(id string, params *stripe.PaymentMethodDetachParams) (*stripe.PaymentMethod, error) {
|
||||||
var unattached *stripe.PaymentMethod
|
|
||||||
|
|
||||||
mocks.Lock()
|
mocks.Lock()
|
||||||
defer mocks.Unlock()
|
defer mocks.Unlock()
|
||||||
|
|
||||||
|
var unattached *stripe.PaymentMethod
|
||||||
for user, userMethods := range m.attached {
|
for user, userMethods := range m.attached {
|
||||||
var remaining []*stripe.PaymentMethod
|
var remaining []*stripe.PaymentMethod
|
||||||
for _, method := range userMethods {
|
for _, method := range userMethods {
|
||||||
|
@ -71,7 +71,7 @@ type TransactionsPage struct {
|
|||||||
|
|
||||||
// IDList returns transaction id list of page's transactions.
|
// IDList returns transaction id list of page's transactions.
|
||||||
func (page *TransactionsPage) IDList() TransactionAndUserList {
|
func (page *TransactionsPage) IDList() TransactionAndUserList {
|
||||||
var ids = make(TransactionAndUserList)
|
ids := make(TransactionAndUserList)
|
||||||
for _, tx := range page.Transactions {
|
for _, tx := range page.Transactions {
|
||||||
ids[tx.ID] = tx.AccountID
|
ids[tx.ID] = tx.AccountID
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user