I have this code in my application, I use goroutine because that queries are very slow. The code works correctly but I've been trying to test that function with sqlmock and that been having a lot of false positives and a lot of dificulties, what can I do to test those queries using sqlmock? (Obs: I've used postgres)
func(r repository) Queries(ctx context.Context) (*models.MyModel, error) {
var users int64
var services int64
var sells int64
queryReponses := make(chan *gorm.DB, 3)
go func(){
queryResponses <- r.db.Raw("SELECT COUNT(*) FROM deposits").Find(&users)
}()
go func(){
queryResponses <- r.db.Raw("SELECT COUNT(*) FROM services").Find(&users)
}()
go func(){
queryResponses <- r.db.Raw("SELECT COUNT(*) FROM sells").Find(&users)
}()
for i := 0; i < 3; i += 1 {
queryResponse := <-queryReponses
if queryResponse.Error != nil {
return &models.MyModel{}, fmt.Errorf(queryResponse.Error)
}
}
return &models.MyModel{
Users: users,
Services: services,
Sells: sells,
}
}