diff --git a/routes/register.go b/routes/register.go index 4cc5983..d801de5 100644 --- a/routes/register.go +++ b/routes/register.go @@ -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 { diff --git a/routes/register_test.go b/routes/register_test.go index 7523b17..85418c3 100644 --- a/routes/register_test.go +++ b/routes/register_test.go @@ -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) } diff --git a/start.go b/start.go index e222f90..57c3fc7 100644 --- a/start.go +++ b/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) }