042a1d4773
* introduced central package registry by package init function * dynamic registration of routes, model, migrations and initializers. * setting a docker compose project name to prevent shutdown of other containers with the same (composer)name * ai documentation * app template * Create tests for ALL API entpoints in ALL packages Based on current data. Ensure that all API endpoints used in frontend are tested. These tests are crucial for the next refactoring tasks. * adopting agent instructions for a more consistent coding style * added desired module layout and debugging information * Fix All Failing tests All failing tests are fixed now that makes the refactoring more easy since all tests must pass * restored routes for maintenance * added common translations * added new tests for API Endpoint * Merge branch 'separate_business_logic' * added lern and skill improvement cost editing * Set Docker image tag when building to prevent rebuild when nothing has changed * add and remove PP for Weaponskill fixed * add and remove PP for same named skills fixed * add new task
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package gsmaster
|
|
|
|
import (
|
|
"bamort/database"
|
|
"bamort/bmrt/models"
|
|
"os"
|
|
|
|
"gorm.io/driver/mysql"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var migrationDone bool
|
|
var isTestDb bool
|
|
|
|
// SetupTestDB creates an in-memory SQLite database for testing
|
|
func setupTestDB(opts ...bool) {
|
|
isTestDb = true
|
|
if len(opts) > 0 {
|
|
isTestDb = opts[0]
|
|
}
|
|
if database.DB == nil {
|
|
var db *gorm.DB
|
|
var err error
|
|
if isTestDb {
|
|
//*
|
|
db, err = gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
|
if err != nil {
|
|
panic("failed to connect to the test database")
|
|
}
|
|
//*/
|
|
} else {
|
|
//* //testing with persistent MariaDB
|
|
dsn := os.Getenv("TEST_DB_DSN")
|
|
if dsn == "" {
|
|
dsn = "bamort:password@tcp(localhost:3306)/bamort_test?charset=utf8mb4&parseTime=True&loc=Local"
|
|
}
|
|
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
|
if err != nil {
|
|
panic("failed to connect to the test database")
|
|
}
|
|
//*/
|
|
migrationDone = true
|
|
}
|
|
database.DB = db
|
|
}
|
|
if !migrationDone {
|
|
err := models.MigrateStructure()
|
|
if err != nil {
|
|
panic("failed to MigrateStructure")
|
|
}
|
|
migrationDone = true
|
|
}
|
|
}
|