Use glang to develop web application. How to clear dirty data in the database due to unit testing

126 views Asked by At

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?

0

There are 0 answers