Add more unit tests

This commit is contained in:
Jamie Curnow
2023-07-28 15:01:54 +10:00
parent 7f9a1f5a98
commit e5ade3b4ea
11 changed files with 162 additions and 83 deletions

View File

@ -1,7 +1,10 @@
package test
import (
"npm/internal/config"
"npm/internal/database"
"strings"
"testing"
"github.com/DATA-DOG/go-sqlmock"
"gorm.io/driver/postgres"
@ -21,3 +24,18 @@ func Setup() (sqlmock.Sqlmock, error) {
database.SetDB(gormDB)
return mock, err
}
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)
}