mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
pass boolean clear argument to DBInit()
This commit is contained in:
parent
515ef2de15
commit
7631e2a9b5
14 changed files with 21 additions and 21 deletions
|
@ -38,7 +38,7 @@ import (
|
|||
var DBpool *gorm.DB // database used by backend
|
||||
|
||||
// InitDB Initialize connection to the database
|
||||
func InitDB(cfg *config.Config, dbClear string) error {
|
||||
func InitDB(cfg *config.Config, clear bool) error {
|
||||
name, err := cfg.String("db.name")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -76,7 +76,7 @@ func InitDB(cfg *config.Config, dbClear string) error {
|
|||
DBpool = db
|
||||
|
||||
// drop tables if parameter set
|
||||
if dbClear == "true" {
|
||||
if clear {
|
||||
DropTables()
|
||||
log.Println("Database tables dropped")
|
||||
}
|
||||
|
|
|
@ -50,41 +50,41 @@ func TestInitDB(t *testing.T) {
|
|||
|
||||
ownconfig := config.NewConfig([]config.Provider{defaults, env})
|
||||
|
||||
err = InitDB(ownconfig, "true")
|
||||
err = InitDB(ownconfig, true)
|
||||
assert.Error(t, err)
|
||||
dbname, err := configuration.GlobalConfig.String("db.name")
|
||||
assert.NoError(t, err)
|
||||
static["db.name"] = dbname
|
||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||
err = InitDB(ownconfig, "true")
|
||||
err = InitDB(ownconfig, true)
|
||||
assert.Error(t, err)
|
||||
|
||||
dbhost, err := configuration.GlobalConfig.String("db.host")
|
||||
assert.NoError(t, err)
|
||||
static["db.host"] = dbhost
|
||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||
err = InitDB(ownconfig, "true")
|
||||
err = InitDB(ownconfig, true)
|
||||
assert.Error(t, err)
|
||||
|
||||
dbuser, err := configuration.GlobalConfig.String("db.user")
|
||||
assert.NoError(t, err)
|
||||
static["db.user"] = dbuser
|
||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||
err = InitDB(ownconfig, "true")
|
||||
err = InitDB(ownconfig, true)
|
||||
assert.Error(t, err)
|
||||
|
||||
dbpass, err := configuration.GlobalConfig.String("db.pass")
|
||||
assert.NoError(t, err)
|
||||
static["db.pass"] = dbpass
|
||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||
err = InitDB(ownconfig, "true")
|
||||
err = InitDB(ownconfig, true)
|
||||
assert.Error(t, err)
|
||||
|
||||
dbssl, err := configuration.GlobalConfig.String("db.ssl")
|
||||
assert.NoError(t, err)
|
||||
static["db.ssl"] = dbssl
|
||||
ownconfig = config.NewConfig([]config.Provider{defaults, env})
|
||||
err = InitDB(ownconfig, "true")
|
||||
err = InitDB(ownconfig, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify that you can connect to the database
|
||||
|
|
|
@ -147,7 +147,7 @@ func TestMain(m *testing.M) {
|
|||
panic(m)
|
||||
}
|
||||
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ func TestHealthz(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
// connect DB
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
assert.NoError(t, err)
|
||||
defer database.DBpool.Close()
|
||||
|
||||
|
@ -60,7 +60,7 @@ func TestHealthz(t *testing.T) {
|
|||
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// reconnect DB
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
assert.NoError(t, err)
|
||||
defer database.DBpool.Close()
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ func TestMain(m *testing.M) {
|
|||
panic(m)
|
||||
}
|
||||
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
|
|||
panic(m)
|
||||
}
|
||||
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestMain(m *testing.M) {
|
|||
panic(m)
|
||||
}
|
||||
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ func TestMain(m *testing.M) {
|
|||
panic(m)
|
||||
}
|
||||
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ func TestMain(m *testing.M) {
|
|||
panic(m)
|
||||
}
|
||||
|
||||
err = database.InitDB(configuration.GlobalConfig, "true")
|
||||
err = database.InitDB(configuration.GlobalConfig, true)
|
||||
if err != nil {
|
||||
panic(m)
|
||||
}
|
||||
|
|
2
start.go
2
start.go
|
@ -101,7 +101,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Init database
|
||||
err = database.InitDB(configuration.GlobalConfig, dbClear)
|
||||
err = database.InitDB(configuration.GlobalConfig, dbClear == "true")
|
||||
if err != nil {
|
||||
log.Fatalf("Error during initialization of database: %s, aborting.", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue