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

42 lines
758 B
Go
Raw Normal View History

2023-07-26 03:29:12 +00:00
package test
import (
2023-07-28 05:01:54 +00:00
"npm/internal/config"
2023-07-26 03:29:12 +00:00
"npm/internal/database"
2023-07-28 05:01:54 +00:00
"strings"
"testing"
2023-07-26 03:29:12 +00: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 05:01:54 +00: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)
}