mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Add test ICB (ManagedExternally=true) only if AMQP is active, test mode working again if AMQP broker is not available
This commit is contained in:
parent
1540029aae
commit
fb757b1172
3 changed files with 12 additions and 9 deletions
|
@ -74,7 +74,7 @@ func RegisterEndpoints(router *gin.Engine, api *gin.RouterGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uses API endpoints to add test data to the backend; All endpoints have to be registered before invoking this function.
|
// Uses API endpoints to add test data to the backend; All endpoints have to be registered before invoking this function.
|
||||||
func AddTestData(basePath string, router *gin.Engine) (*bytes.Buffer, error) {
|
func AddTestData(basePath string, router *gin.Engine, amqphost string) (*bytes.Buffer, error) {
|
||||||
|
|
||||||
database.MigrateModels()
|
database.MigrateModels()
|
||||||
// Create entries of each model (data defined in test_data.go)
|
// Create entries of each model (data defined in test_data.go)
|
||||||
|
@ -109,9 +109,11 @@ func AddTestData(basePath string, router *gin.Engine) (*bytes.Buffer, error) {
|
||||||
if code != http.StatusOK {
|
if code != http.StatusOK {
|
||||||
return resp, fmt.Errorf("error adding IC A")
|
return resp, fmt.Errorf("error adding IC A")
|
||||||
}
|
}
|
||||||
code, resp, err = helper.TestEndpoint(router, token, basePath+"/ic", "POST", helper.KeyModels{"ic": helper.ICB})
|
if amqphost != "" {
|
||||||
if code != http.StatusOK {
|
code, resp, err = helper.TestEndpoint(router, token, basePath+"/ic", "POST", helper.KeyModels{"ic": helper.ICB})
|
||||||
return resp, fmt.Errorf("error adding IC B")
|
if code != http.StatusOK {
|
||||||
|
return resp, fmt.Errorf("error adding IC B")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add scenarios
|
// add scenarios
|
||||||
|
@ -147,7 +149,7 @@ func AddTestData(basePath string, router *gin.Engine) (*bytes.Buffer, error) {
|
||||||
configB := helper.ConfigB
|
configB := helper.ConfigB
|
||||||
configA.ScenarioID = 1
|
configA.ScenarioID = 1
|
||||||
configB.ScenarioID = 1
|
configB.ScenarioID = 1
|
||||||
configA.ICID = 2
|
configA.ICID = 1
|
||||||
configB.ICID = 1
|
configB.ICID = 1
|
||||||
code, resp, err = helper.TestEndpoint(router, token, basePath+"/configs", "POST", helper.KeyModels{"config": configA})
|
code, resp, err = helper.TestEndpoint(router, token, basePath+"/configs", "POST", helper.KeyModels{"config": configA})
|
||||||
if code != http.StatusOK {
|
if code != http.StatusOK {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
|
var amqpURI string
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
err := configuration.InitConfig()
|
err := configuration.InitConfig()
|
||||||
|
@ -69,6 +70,6 @@ func TestRegisterEndpoints(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTestData(t *testing.T) {
|
func TestAddTestData(t *testing.T) {
|
||||||
resp, err := AddTestData("/api", router)
|
resp, err := AddTestData("/api", router, amqpURI)
|
||||||
assert.NoError(t, err, "Response body: %v", resp)
|
assert.NoError(t, err, "Response body: %v", resp)
|
||||||
}
|
}
|
||||||
|
|
6
start.go
6
start.go
|
@ -33,13 +33,13 @@ import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addData(router *gin.Engine, mode string, basePath string) error {
|
func addData(router *gin.Engine, mode string, basePath string, amqphost string) error {
|
||||||
|
|
||||||
if mode == "test" {
|
if mode == "test" {
|
||||||
// test mode: drop all tables and add test data to DB
|
// test mode: drop all tables and add test data to DB
|
||||||
database.DropTables()
|
database.DropTables()
|
||||||
log.Println("Database tables dropped, using API to add test data")
|
log.Println("Database tables dropped, using API to add test data")
|
||||||
resp, err := routes.AddTestData(basePath, router)
|
resp, err := routes.AddTestData(basePath, router, amqphost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error: testdata could not be added to DB:", err.Error(), "Response body: ", resp)
|
fmt.Println("error: testdata could not be added to DB:", err.Error(), "Response body: ", resp)
|
||||||
return err
|
return err
|
||||||
|
@ -95,7 +95,7 @@ func main() {
|
||||||
apidocs.SwaggerInfo.BasePath = basePath
|
apidocs.SwaggerInfo.BasePath = basePath
|
||||||
|
|
||||||
// add data to DB (if any)
|
// add data to DB (if any)
|
||||||
err = addData(r, mode, basePath)
|
err = addData(r, mode, basePath, amqphost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue