Documentation
¶
Overview ¶
Package ledgotest is the conformance suite every ledgo.Store must pass.
Run it from a backend's tests with:
suite.Run(t, &ledgotest.Suite{Store: store})
Index ¶
- func EndTx(tx *sql.Tx) func(commit bool) error
- type Suite
- func (s *Suite) SetupSuite()
- func (s *Suite) TestBalancedTransfer()
- func (s *Suite) TestConcurrentOverspend()
- func (s *Suite) TestConcurrentSameKey()
- func (s *Suite) TestConcurrentTransfers()
- func (s *Suite) TestCreateAccount()
- func (s *Suite) TestCreditsMustNotExceedDebits()
- func (s *Suite) TestCurrencyMismatch()
- func (s *Suite) TestDebitsMustNotExceedCredits()
- func (s *Suite) TestFXConversion()
- func (s *Suite) TestIdempotency()
- func (s *Suite) TestUnknownAccount()
- type TxSuite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Suite ¶
Suite runs against Store. Accounts and idempotency keys are unique per run, so Store does not need to be empty.
func (*Suite) SetupSuite ¶
func (s *Suite) SetupSuite()
SetupSuite wraps Store in a Ledger and registers BTC, which ISO 4217 lacks. Embedding suites that override it must call it.
func (*Suite) TestBalancedTransfer ¶
func (s *Suite) TestBalancedTransfer()
TestBalancedTransfer checks that balances add up across transactions.
func (*Suite) TestConcurrentOverspend ¶
func (s *Suite) TestConcurrentOverspend()
TestConcurrentOverspend makes 200 concurrent attempts to spend 0.01 from a balance of 1.00: exactly 100 must succeed.
func (*Suite) TestConcurrentSameKey ¶
func (s *Suite) TestConcurrentSameKey()
TestConcurrentSameKey checks that concurrent commits of one key apply once.
func (*Suite) TestConcurrentTransfers ¶
func (s *Suite) TestConcurrentTransfers()
TestConcurrentTransfers moves money in both directions around rings of limited accounts, in two currencies, from many goroutines. Commits lock accounts in opposite orders, so a missing lock order shows up as a deadlock error. Then it checks that debits equal credits per currency.
func (*Suite) TestCreateAccount ¶
func (s *Suite) TestCreateAccount()
TestCreateAccount checks that creating an account again is a no-op, and that different settings under the same ID are rejected.
func (*Suite) TestCreditsMustNotExceedDebits ¶
func (s *Suite) TestCreditsMustNotExceedDebits()
TestCreditsMustNotExceedDebits checks that a prefund account, which holds a debit balance, cannot be overdrawn.
func (*Suite) TestCurrencyMismatch ¶
func (s *Suite) TestCurrencyMismatch()
TestCurrencyMismatch checks that an entry must match its account's currency.
func (*Suite) TestDebitsMustNotExceedCredits ¶
func (s *Suite) TestDebitsMustNotExceedCredits()
TestDebitsMustNotExceedCredits checks that a customer account, which holds a credit balance, cannot be overdrawn.
func (*Suite) TestFXConversion ¶
func (s *Suite) TestFXConversion()
TestFXConversion checks that a conversion balances per currency through the FX accounts.
func (*Suite) TestIdempotency ¶
func (s *Suite) TestIdempotency()
TestIdempotency checks that a retry is a no-op and a reused key with different content is rejected.
func (*Suite) TestUnknownAccount ¶
func (s *Suite) TestUnknownAccount()
TestUnknownAccount checks that commits and balances need a created account.
type TxSuite ¶ added in v0.0.2
type TxSuite struct {
suite.Suite
// Store reads balances outside the caller's transactions.
Store ledgo.Store
// Begin starts a caller transaction. It returns a Store that writes into
// it, and end, which commits the transaction or rolls it back.
Begin func() (store ledgo.Store, end func(commit bool) error, err error)
// contains filtered or unexported fields
}
TxSuite runs against a Store bound to a caller's transaction, such as postgres.InTx. Run it next to Suite with:
suite.Run(t, &ledgotest.TxSuite{Store: store, Begin: begin})
func (*TxSuite) SetupSuite ¶ added in v0.0.2
func (s *TxSuite) SetupSuite()
SetupSuite registers ETH, which has 18 decimal places. Embedding suites that override it must call it.
func (*TxSuite) TestCommitsWithCallerTransaction ¶ added in v0.0.2
func (s *TxSuite) TestCommitsWithCallerTransaction()
TestCommitsWithCallerTransaction checks that postings commit with the caller's transaction.
func (*TxSuite) TestExactAmounts ¶ added in v0.0.2
func (s *TxSuite) TestExactAmounts()
TestExactAmounts checks that an amount with 20 integer digits and 18 decimal places stays exact, through a cached balance and a summed one. Begin can make the caller's session hostile, for example with a ',' decimal separator.
func (*TxSuite) TestRollsBackWithCallerTransaction ¶ added in v0.0.2
func (s *TxSuite) TestRollsBackWithCallerTransaction()
TestRollsBackWithCallerTransaction checks that postings roll back with the caller's transaction.