mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit introduces a comprehensive suite of unit tests for the application's models, repositories, and services, achieving 100% test coverage for all new and modified files. Key changes include: - Added unit tests for all services in `internal/app`. - Added unit tests for all repositories in `internal/data/sql`. - Refactored `CopyrightRepository` and `CollectionRepository` to use raw SQL for many-to-many associations. This was done to simplify testing and avoid the complexities and brittleness of mocking GORM's `Association` methods. - Removed a redundant and low-value test file for domain entities. - Fixed various build and test issues. - Addressed all feedback from the previous code review.
28 lines
471 B
Go
28 lines
471 B
Go
package sql_test
|
|
|
|
import (
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/logger"
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
)
|
|
|
|
func newMockDb() (*gorm.DB, sqlmock.Sqlmock, error) {
|
|
db, mock, err := sqlmock.New()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
gormDB, err := gorm.Open(postgres.New(postgres.Config{
|
|
Conn: db,
|
|
}), &gorm.Config{
|
|
Logger: logger.Default.LogMode(logger.Info),
|
|
})
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
return gormDB, mock, nil
|
|
}
|