Files
threshold/internal/oplog/oplog_test/db.go
T
34f530e0df Basic oplog capability (#6)
The ability to write oplog entries using a ticket based system to ensure serialization.   Uses a go-kms-wrapper for encrypting/decrypting entries.

Co-authored-by: Jim Lambert <jlm.lambert@gmail.com>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>
Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2020-04-08 14:55:40 -04:00

49 lines
1.3 KiB
Go

// Package oplog_test provides some gorm helper funcs for testing oplog database integrations
package oplog_test
import "github.com/jinzhu/gorm"
// Init will use gorm migrations to init tables for test models
func Init(db *gorm.DB) {
db.AutoMigrate(&TestUser{})
db.AutoMigrate(&TestCar{})
db.AutoMigrate(&TestRental{})
}
// Reinit will use gorm to drop then init tables for test models
func Reinit(db *gorm.DB) {
db.DropTableIfExists(&TestUser{})
db.DropTableIfExists(&TestCar{})
db.DropTableIfExists(&TestRental{})
Init(db)
}
// ReplayableTestUser is simply that: a user we can replay for tests
// the big diff is that it supports overriding the table name
type ReplayableTestUser struct {
TestUser
Table string `gorm:"-"`
}
// TableName overrides the table name for the test user model
func (u *ReplayableTestUser) TableName() string {
if u.Table != "" {
return u.Table
}
return "oplog_test_user"
}
func (u *ReplayableTestUser) SetTableName(name string) {
if name != "" {
u.Table = name
}
}
func (*TestUser) TableName() string { return "oplog_test_user" }
// TableName overrides the table name for the test car model
func (*TestCar) TableName() string { return "oplog_test_car" }
// TableName overrids the table name for the test rental model
func (*TestRental) TableName() string { return "oplog_test_rental" }