move scripts, allow testing both dbs with one cmd

This commit is contained in:
tsmethurst 2021-09-10 15:59:12 +02:00
commit 5510a39cf3
13 changed files with 263 additions and 99 deletions

View file

@ -21,6 +21,7 @@ package testrig
import (
"context"
"os"
"strconv"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -58,6 +59,12 @@ var testModels []interface{} = []interface{}{
//
// If the environment variable GTS_DB_ADDRESS is set, it will take that
// value as the database address instead.
//
// If the environment variable GTS_DB_TYPE is set, it will take that
// value as the database type instead.
//
// If the environment variable GTS_DB_PORT is set, it will take that
// value as the port instead.
func NewTestDB() db.DB {
config := NewTestConfig()
alternateAddress := os.Getenv("GTS_DB_ADDRESS")
@ -65,6 +72,20 @@ func NewTestDB() db.DB {
config.DBConfig.Address = alternateAddress
}
alternateDBType := os.Getenv("GTS_DB_TYPE")
if alternateDBType != "" {
config.DBConfig.Type = alternateDBType
}
alternateDBPort := os.Getenv("GTS_DB_PORT")
if alternateDBPort != "" {
port, err := strconv.ParseInt(alternateDBPort, 10, 64)
if err != nil {
panic(err)
}
config.DBConfig.Port = int(port)
}
testDB, err := bundb.NewBunDBService(context.Background(), config, NewTestLog())
if err != nil {
logrus.Panic(err)