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,12 +75,13 @@ func InitConfig() *config.Config {
|
||||||
log.Fatal("failed to parse config")
|
log.Fatal("failed to parse config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m, _ := c.String("mode"); m != "test" {
|
||||||
settings, _ := c.Settings()
|
settings, _ := c.Settings()
|
||||||
|
|
||||||
log.Print("All settings:")
|
log.Print("All settings:")
|
||||||
for key, val := range settings {
|
for key, val := range settings {
|
||||||
log.Printf(" %s = %s \n", key, val)
|
log.Printf(" %s = %s \n", key, val)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save pointer to global variable
|
// Save pointer to global variable
|
||||||
Config = c
|
Config = c
|
||||||
|
|
|
@ -37,9 +37,7 @@ func InitDB(cfg *config.Config) *gorm.DB {
|
||||||
if mode == "test" || init {
|
if mode == "test" || init {
|
||||||
DropTables(db)
|
DropTables(db)
|
||||||
log.Println("Database tables dropped")
|
log.Println("Database tables dropped")
|
||||||
}
|
|
||||||
|
|
||||||
if init {
|
|
||||||
DBAddTestData(db)
|
DBAddTestData(db)
|
||||||
log.Println("Database initialized with test data")
|
log.Println("Database initialized with test data")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
db = InitDB(DB_NAME, true)
|
c := config.InitConfig()
|
||||||
|
db = InitDB(c)
|
||||||
|
|
||||||
// Verify that you can connect to the database
|
// Verify that you can connect to the database
|
||||||
err := db.DB().Ping()
|
err := db.DB().Ping()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"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) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"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/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/dashboard"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
||||||
|
@ -159,8 +160,8 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -2,7 +2,7 @@ package healthz
|
||||||
|
|
||||||
import (
|
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/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/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
//"net/http"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +19,8 @@ var db *gorm.DB
|
||||||
|
|
||||||
func TestHealthz(t *testing.T) {
|
func TestHealthz(t *testing.T) {
|
||||||
// connect DB
|
// connect DB
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
c := config.InitConfig()
|
||||||
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
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)
|
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// reconnect DB
|
// reconnect DB
|
||||||
db = database.InitDB(database.DB_NAME, false)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
// test healthz endpoint for connected DB and unconnected AMQP client
|
// 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)
|
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)
|
// 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)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test healthz endpoint for connected DB and AMQP client
|
// test healthz endpoint for connected DB and AMQP client
|
||||||
|
|
|
@ -3,6 +3,7 @@ package scenario
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"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/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/jinzhu/gorm/dialects/postgres"
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||||||
|
@ -32,8 +33,8 @@ type UserRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package signal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"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) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package simulationmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"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) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"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/database"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,8 +28,8 @@ type SimulatorRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"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/database"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
@ -30,8 +31,8 @@ type UserRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package widget
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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/database"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
"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) {
|
func TestMain(m *testing.M) {
|
||||||
|
c := config.InitConfig()
|
||||||
db = database.InitDB(database.DB_NAME, true)
|
db = database.InitDB(c)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
router = gin.Default()
|
router = gin.Default()
|
||||||
|
|
13
start.go
13
start.go
|
@ -37,17 +37,16 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting VILLASweb-backend-go")
|
log.Println("Starting VILLASweb-backend-go")
|
||||||
|
|
||||||
c.InitConfig()
|
c := c.InitConfig()
|
||||||
|
db := database.InitDB(c)
|
||||||
db := database.InitDB(c.Config)
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
if m, _ := c.Config.String("mode"); m == "release" {
|
if m, _ := c.String("mode"); m == "release" {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
baseHost, _ := c.Config.String("base.host")
|
baseHost, _ := c.String("base.host")
|
||||||
basePath, _ := c.Config.String("base.path")
|
basePath, _ := c.String("base.path")
|
||||||
docs.SwaggerInfo.Host = baseHost
|
docs.SwaggerInfo.Host = baseHost
|
||||||
docs.SwaggerInfo.BasePath = basePath
|
docs.SwaggerInfo.BasePath = basePath
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ func main() {
|
||||||
|
|
||||||
r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
amqpurl, _ := c.Config.String("amqp.url")
|
amqpurl, _ := c.String("amqp.url")
|
||||||
if amqpurl != "" {
|
if amqpurl != "" {
|
||||||
log.Println("Starting AMQP client")
|
log.Println("Starting AMQP client")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue