nginx-proxy-manager-zh/backend/internal/test/suite.go

43 lines
759 B
Go
Raw Permalink Normal View History

2023-07-25 23:29:12 -04:00
package test
import (
2023-07-28 01:01:54 -04:00
"strings"
"testing"
2023-07-25 23:29:12 -04:00
2024-09-08 18:42:30 -04:00
"npm/internal/config"
"npm/internal/database"
2023-07-25 23:29:12 -04:00
"github.com/DATA-DOG/go-sqlmock"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func Setup() (sqlmock.Sqlmock, error) {
db, mock, err := sqlmock.New()
if err != nil {
return nil, err
}
dialector := postgres.New(postgres.Config{
Conn: db,
DriverName: "postgres",
})
gormDB, err := gorm.Open(dialector, &gorm.Config{})
database.SetDB(gormDB)
return mock, err
}
2023-07-28 01:01:54 -04:00
func InitConfig(t *testing.T, envs ...string) {
if len(envs) > 0 {
for _, env := range envs {
parts := strings.Split(env, "=")
if len(parts) == 2 {
t.Setenv(parts[0], parts[1])
}
}
}
version := "999.999.999"
commit := "abcd123"
config.Init(&version, &commit)
}