Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteCreatedEntities ¶
DeleteCreatedEntities records all created entities on the gorm.DB connection and returns a function which can be called on defer to delete created entities in reverse order on function exit.
In addition to that, the WIT cache is cleared as well in order to respect any deletions made to the db.
Usage:
func TestDatabaseActions(t *testing.T) {
// setup database connection db := .... // setup auto clean up of created entities defer DeleteCreatedEntities(db)() repo := NewRepo(db) repo.Create(X) repo.Create(X) repo.Create(X) }
Output:
2017/01/31 12:08:08 Deleting from x 6d143405-1232-40de-bc73-835b543cd972 2017/01/31 12:08:08 Deleting from x 0685068d-4934-4d9a-bac2-91eebbca9575 2017/01/31 12:08:08 Deleting from x 2d20944e-7952-40c1-bd15-f3fa1a70026d
Types ¶
type DBTestSuite ¶
type DBTestSuite struct { suite.Suite Configuration *config.Data DB *gorm.DB Ctx context.Context // contains filtered or unexported fields }
DBTestSuite is a base for tests using a gorm db
func NewDBTestSuite ¶
func NewDBTestSuite(configFilePath string) DBTestSuite
NewDBTestSuite instanciate a new DBTestSuite
func (*DBTestSuite) DisableGormCallbacks ¶
func (s *DBTestSuite) DisableGormCallbacks() func()
DisableGormCallbacks will turn off gorm's automatic setting of `created_at` and `updated_at` columns. Call this function and make sure to `defer` the returned function.
resetFn := DisableGormCallbacks() defer resetFn()
func (*DBTestSuite) SetupSuite ¶
func (s *DBTestSuite) SetupSuite()
SetupSuite implements suite.SetupAllSuite
func (*DBTestSuite) SetupTest ¶
func (s *DBTestSuite) SetupTest()
SetupTest implements suite.SetupTest
func (*DBTestSuite) TearDownSuite ¶
func (s *DBTestSuite) TearDownSuite()
TearDownSuite implements suite.TearDownAllSuite
func (*DBTestSuite) TearDownTest ¶
func (s *DBTestSuite) TearDownTest()
TearDownTest implements suite.TearDownTest