Here I have been trying to find out to mock the sqlboiler(an ORM generator) queries but could not find the way.
Can anyone work around mocking the sqlboiler queries?
Example:
func (m *Message) updateDevice(parentID int, data map[string]interface{}) (rows int64, err error) {
rows, err = automodel.Devices(qm.Where(automodel.DeviceColumns.ParentID+"=?", parentID)).UpdateAll(context.Background(), db.GetMaster(), data)
if err != nil {
return 0, err
}
return rows, err
}
func GetDeviceByID(ID int) (res *automodel.Device, err error) {
res, err = automodel.Devices(qm.Where("id=?", ID)).One(context.Background(), db.GetSlave())
if err != nil {
return nil, err
}
return res, nil
}
FYI: automodel is the package where all generated models are present(like device.go
for device table). We cannot changes these as these are generated by sqlboiler command and need to generate again if new tables are added or schema change happens to a table.
How do I mock the sqlboiler queries in the above two methods while writing unit tests?