Documentation
¶
Overview ¶
Package dbtest 给要 MySQL、Redis 的测试用:连接串、跳过或强制的规则、包之间的互斥、每个测试独立的账户和 key 前缀。
连接串从 QUOTAFORGE_TEST_MYSQL_MIGRATE_DSN(能建表)和 QUOTAFORGE_TEST_MYSQL_DSN(只能增删改查)读, Redis 的地址从 QUOTAFORGE_TEST_REDIS_ADDR 读。没设时跳过;QUOTAFORGE_TEST_REQUIRE_DB=1(CI)时缺了就判失败。
几个测试包同时用同一个 Redis:每个测试只用自己的 key 前缀(RedisPrefix),不清空整个库。
go test ./... 会让多个包同时跑,而它们共用一个测试库,迁移测试还要删表重建。所以每个用库的测试包 在 TestMain 里调用 Main:拿到 MySQL 的命名锁才开始跑,各包依次使用这个库。
Index ¶
- func Account(t testing.TB, s *ledger.Store, limit int64) string
- func Admin(t testing.TB) *sql.DB
- func App(t testing.TB) *sql.DB
- func AppDSN(t testing.TB) string
- func Budget(t testing.TB, db *sql.DB, account string) (limit, reserved, consumed int64)
- func BudgetWaiters(t testing.TB, app *sql.DB) int
- func LockBudget(t testing.TB, db *sql.DB, accountID int64) (release func())
- func Main(m *testing.M)
- func MigrateDSN(t testing.TB) string
- func Now(t testing.TB, db *sql.DB) time.Time
- func RedisPrefix() string
- func RedisURL(t testing.TB) string
- func Store(t testing.TB) *ledger.Store
- func Verify(t testing.TB, s *ledger.Store)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BudgetWaiters ¶
BudgetWaiters 是 app(App 的连接)这个账号在本库里正在执行、语句以 UPDATE budgets 开头的线程数。 测试账号没有 PROCESS 权限,读不了锁等待表,但 processlist 里看得到自己账号的全部线程。
func LockBudget ¶
LockBudget 在另一个事务里锁住账户的额度行,返回放锁的函数(测试结束时也会放)。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.