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.
|
||||
func AddTestData(basePath string, router *gin.Engine) (*bytes.Buffer, error) {
|
||||
func AddTestData(basePath string, router *gin.Engine, amqphost string) (*bytes.Buffer, error) {
|
||||
|
||||
database.MigrateModels()
|
||||
// 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 {
|
||||
return resp, fmt.Errorf("error adding IC A")
|
||||
}
|
||||
code, resp, err = helper.TestEndpoint(router, token, basePath+"/ic", "POST", helper.KeyModels{"ic": helper.ICB})
|
||||
if code != http.StatusOK {
|
||||
return resp, fmt.Errorf("error adding IC B")
|
||||
if amqphost != "" {
|
||||
code, resp, err = helper.TestEndpoint(router, token, basePath+"/ic", "POST", helper.KeyModels{"ic": helper.ICB})
|
||||
if code != http.StatusOK {
|
||||
return resp, fmt.Errorf("error adding IC B")
|
||||
}
|
||||
}
|
||||
|
||||
// add scenarios
|
||||
|
@ -147,7 +149,7 @@ func AddTestData(basePath string, router *gin.Engine) (*bytes.Buffer, error) {
|
|||
configB := helper.ConfigB
|
||||
configA.ScenarioID = 1
|
||||
configB.ScenarioID = 1
|
||||
configA.ICID = 2
|
||||
configA.ICID = 1
|
||||
configB.ICID = 1
|
||||
code, resp, err = helper.TestEndpoint(router, token, basePath+"/configs", "POST", helper.KeyModels{"config": configA})
|
||||
if code != http.StatusOK {
|
||||
|
|
|
@ -33,6 +33,7 @@ import (
|
|||
)
|
||||
|
||||
var router *gin.Engine
|
||||
var amqpURI string
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
err := configuration.InitConfig()
|
||||
|
@ -69,6 +70,6 @@ func TestRegisterEndpoints(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)
|
||||
}
|
||||
|
|
6
start.go
6
start.go
|
@ -33,13 +33,13 @@ import (
|
|||
"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" {
|
||||
// test mode: drop all tables and add test data to DB
|
||||
database.DropTables()
|
||||
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 {
|
||||
fmt.Println("error: testdata could not be added to DB:", err.Error(), "Response body: ", resp)
|
||||
return err
|
||||
|
@ -95,7 +95,7 @@ func main() {
|
|||
apidocs.SwaggerInfo.BasePath = basePath
|
||||
|
||||
// add data to DB (if any)
|
||||
err = addData(r, mode, basePath)
|
||||
err = addData(r, mode, basePath, amqphost)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue