I use gin framework and ORM framework gorm to develop web application.The DB is Mysql.
Every unit test will produce dirty data. So I use AfterCreate hook to record table name and the id when create an object.Then delete dirty data by traversing the list of record.
I need to add hook function to every model like:
func (f User) AfterCreate(tx *gorm.DB) (err error) {
DBTestAddRecord([2]interface{}{f.ID, &User{}})
return
}
It can work but very annoying. Is there any other solution?