mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
fix tests
This commit is contained in:
parent
0119a2947e
commit
d546f7bc91
13 changed files with 45 additions and 36 deletions
|
@ -75,11 +75,12 @@ func InitConfig() *config.Config {
|
|||
log.Fatal("failed to parse config")
|
||||
}
|
||||
|
||||
settings, _ := c.Settings()
|
||||
|
||||
log.Print("All settings:")
|
||||
for key, val := range settings {
|
||||
log.Printf(" %s = %s \n", key, val)
|
||||
if m, _ := c.String("mode"); m != "test" {
|
||||
settings, _ := c.Settings()
|
||||
log.Print("All settings:")
|
||||
for key, val := range settings {
|
||||
log.Printf(" %s = %s \n", key, val)
|
||||
}
|
||||
}
|
||||
|
||||
// Save pointer to global variable
|
||||
|
|
|
@ -37,9 +37,7 @@ func InitDB(cfg *config.Config) *gorm.DB {
|
|||
if mode == "test" || init {
|
||||
DropTables(db)
|
||||
log.Println("Database tables dropped")
|
||||
}
|
||||
|
||||
if init {
|
||||
DBAddTestData(db)
|
||||
log.Println("Database initialized with test data")
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
)
|
||||
|
||||
var db *gorm.DB
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
db = InitDB(DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = InitDB(c)
|
||||
|
||||
// Verify that you can connect to the database
|
||||
err := db.DB().Ping()
|
||||
|
|
|
@ -2,6 +2,7 @@ package dashboard
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||
|
@ -54,8 +55,8 @@ func addScenario(token string) (scenarioID uint) {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
||||
|
@ -159,8 +160,8 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -2,7 +2,7 @@ package healthz
|
|||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/amqp"
|
||||
//"git.rwth-aachen.de/acs/public/villas/web-backend-go/amqp"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
|
||||
//"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -20,7 +19,8 @@ var db *gorm.DB
|
|||
|
||||
func TestHealthz(t *testing.T) {
|
||||
// connect DB
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||
|
@ -47,7 +47,7 @@ func TestHealthz(t *testing.T) {
|
|||
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// reconnect DB
|
||||
db = database.InitDB(database.DB_NAME, false)
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
// test healthz endpoint for connected DB and unconnected AMQP client
|
||||
|
@ -56,7 +56,8 @@ func TestHealthz(t *testing.T) {
|
|||
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
||||
|
||||
// connect AMQP client (make sure that AMQP_URL is set via command line parameter -amqp)
|
||||
err = amqp.ConnectAMQP(database.AMQP_URL)
|
||||
url, _ := c.String("amqp.url")
|
||||
err = amqp.ConnectAMQP(url)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// test healthz endpoint for connected DB and AMQP client
|
||||
|
|
|
@ -3,6 +3,7 @@ package scenario
|
|||
import (
|
||||
"fmt"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/jinzhu/gorm/dialects/postgres"
|
||||
|
@ -32,8 +33,8 @@ type UserRequest struct {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -2,6 +2,7 @@ package signal
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||
|
@ -105,8 +106,8 @@ func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID u
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -2,6 +2,7 @@ package simulationmodel
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||
|
@ -94,8 +95,8 @@ func addScenarioAndSimulator() (scenarioID uint, simulatorID uint) {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||
)
|
||||
|
||||
|
@ -27,8 +28,8 @@ type SimulatorRequest struct {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
)
|
||||
|
||||
var router *gin.Engine
|
||||
|
@ -30,8 +31,8 @@ type UserRequest struct {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
|
@ -2,6 +2,7 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
||||
|
@ -79,8 +80,8 @@ func addScenarioAndDashboard(token string) (scenarioID uint, dashboardID uint) {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
db = database.InitDB(database.DB_NAME, true)
|
||||
c := config.InitConfig()
|
||||
db = database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
router = gin.Default()
|
||||
|
|
13
start.go
13
start.go
|
@ -37,17 +37,16 @@ import (
|
|||
func main() {
|
||||
log.Println("Starting VILLASweb-backend-go")
|
||||
|
||||
c.InitConfig()
|
||||
|
||||
db := database.InitDB(c.Config)
|
||||
c := c.InitConfig()
|
||||
db := database.InitDB(c)
|
||||
defer db.Close()
|
||||
|
||||
if m, _ := c.Config.String("mode"); m == "release" {
|
||||
if m, _ := c.String("mode"); m == "release" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
baseHost, _ := c.Config.String("base.host")
|
||||
basePath, _ := c.Config.String("base.path")
|
||||
baseHost, _ := c.String("base.host")
|
||||
basePath, _ := c.String("base.path")
|
||||
docs.SwaggerInfo.Host = baseHost
|
||||
docs.SwaggerInfo.BasePath = basePath
|
||||
|
||||
|
@ -73,7 +72,7 @@ func main() {
|
|||
|
||||
r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
amqpurl, _ := c.Config.String("amqp.url")
|
||||
amqpurl, _ := c.String("amqp.url")
|
||||
if amqpurl != "" {
|
||||
log.Println("Starting AMQP client")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue