mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
complete duplication test, code fixes
This commit is contained in:
parent
ae3e0374f1
commit
3e2f2ce8e8
3 changed files with 146 additions and 80 deletions
|
@ -288,7 +288,7 @@ func authenticateExternal(c *gin.Context) (User, error) {
|
||||||
|
|
||||||
if groupedScenario.Duplicate {
|
if groupedScenario.Duplicate {
|
||||||
|
|
||||||
if err := <-duplicateScenarioForUser(so, &myUser.User); err != nil {
|
if err := <-duplicateScenarioForUser(so, &myUser.User, ""); err != nil {
|
||||||
return User{}, err
|
return User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func duplicateScenarioForUser(s database.Scenario, user *database.User) <-chan error {
|
func duplicateScenarioForUser(s database.Scenario, user *database.User, uuidstr string) <-chan error {
|
||||||
errs := make(chan error, 1)
|
errs := make(chan error, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -64,7 +64,7 @@ func duplicateScenarioForUser(s database.Scenario, user *database.User) <-chan e
|
||||||
|
|
||||||
// create new kubernetes simulator OR use existing IC
|
// create new kubernetes simulator OR use existing IC
|
||||||
if ic.Category == "simulator" && ic.Type == "kubernetes" {
|
if ic.Category == "simulator" && ic.Type == "kubernetes" {
|
||||||
duplicateUUID, err := duplicateIC(ic, user.Username)
|
duplicateUUID, err := duplicateIC(ic, user.Username, uuidstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs <- fmt.Errorf("duplication of IC (id=%d) unsuccessful, err: %s", icID, err)
|
errs <- fmt.Errorf("duplication of IC (id=%d) unsuccessful, err: %s", icID, err)
|
||||||
continue
|
continue
|
||||||
|
@ -80,7 +80,6 @@ func duplicateScenarioForUser(s database.Scenario, user *database.User) <-chan e
|
||||||
|
|
||||||
// copy scenario after all new external ICs are in DB
|
// copy scenario after all new external ICs are in DB
|
||||||
icsToWaitFor := len(externalUUIDs)
|
icsToWaitFor := len(externalUUIDs)
|
||||||
//var duplicatedScenario database.Scenario
|
|
||||||
var timeout = 20 // seconds
|
var timeout = 20 // seconds
|
||||||
|
|
||||||
for i := 0; i < timeout; i++ {
|
for i := 0; i < timeout; i++ {
|
||||||
|
@ -248,7 +247,7 @@ func duplicateComponentConfig(m database.ComponentConfiguration, scenarioID uint
|
||||||
|
|
||||||
// save duplicate to DB and create associations with IC and scenario
|
// save duplicate to DB and create associations with IC and scenario
|
||||||
var so database.Scenario
|
var so database.Scenario
|
||||||
err := db.Find(&so, m.ScenarioID).Error
|
err := db.Find(&so, scenarioID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -299,10 +298,10 @@ func duplicateComponentConfig(m database.ComponentConfiguration, scenarioID uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// associate signal with component configuration in correct direction
|
// associate signal with component configuration in correct direction
|
||||||
if s.Direction == "in" {
|
if sigDup.Direction == "in" {
|
||||||
err = db.Model(&dup).Association("InputMapping").Append(&s).Error
|
err = db.Model(&dup).Association("InputMapping").Append(&sigDup).Error
|
||||||
} else {
|
} else {
|
||||||
err = db.Model(&dup).Association("OutputMapping").Append(&s).Error
|
err = db.Model(&dup).Association("OutputMapping").Append(&sigDup).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -451,11 +450,11 @@ type ICUpdateKubernetesJob struct {
|
||||||
Schema json.RawMessage `json:"schema"`
|
Schema json.RawMessage `json:"schema"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func duplicateIC(ic database.InfrastructureComponent, userName string) (string, error) {
|
func duplicateIC(ic database.InfrastructureComponent, userName string, uuidstr string) (string, error) {
|
||||||
|
|
||||||
//WARNING: this function only works with the kubernetes-simple manager of VILLAScontroller
|
//WARNING: this function only works with the kubernetes-simple manager of VILLAScontroller
|
||||||
if ic.Category != "simulator" || ic.Type == "kubernetes" {
|
if ic.Category != "simulator" || ic.Type != "kubernetes" {
|
||||||
return "", nil
|
return "", fmt.Errorf("IC to duplicate is not a kubernetes simulator (%s %s)", ic.Type, ic.Category)
|
||||||
}
|
}
|
||||||
|
|
||||||
newUUID := uuid.New().String()
|
newUUID := uuid.New().String()
|
||||||
|
@ -466,6 +465,10 @@ func duplicateIC(ic database.InfrastructureComponent, userName string) (string,
|
||||||
return newUUID, err
|
return newUUID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if uuidstr != "" {
|
||||||
|
newUUID = "4854af30-325f-44a5-ad59-b67b2597de68"
|
||||||
|
}
|
||||||
|
|
||||||
msg := `{"name": "` + lastUpdate.Properties.Name + ` ` + userName + `",` +
|
msg := `{"name": "` + lastUpdate.Properties.Name + ` ` + userName + `",` +
|
||||||
`"location": "` + lastUpdate.Properties.Location + `",` +
|
`"location": "` + lastUpdate.Properties.Location + `",` +
|
||||||
`"category": "` + lastUpdate.Properties.Category + `",` +
|
`"category": "` + lastUpdate.Properties.Category + `",` +
|
||||||
|
|
|
@ -36,8 +36,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -46,10 +44,13 @@ import (
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
|
|
||||||
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
|
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
|
||||||
"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/file"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/file"
|
||||||
|
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"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/signal"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ func TestMain(m *testing.M) {
|
||||||
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
||||||
infrastructure_component.RegisterICEndpoints(api.Group("/ic"))
|
infrastructure_component.RegisterICEndpoints(api.Group("/ic"))
|
||||||
component_configuration.RegisterComponentConfigurationEndpoints(api.Group("/configs"))
|
component_configuration.RegisterComponentConfigurationEndpoints(api.Group("/configs"))
|
||||||
|
signal.RegisterSignalEndpoints(api.Group("/signals"))
|
||||||
dashboard.RegisterDashboardEndpoints(api.Group("/dashboards"))
|
dashboard.RegisterDashboardEndpoints(api.Group("/dashboards"))
|
||||||
file.RegisterFileEndpoints(api.Group("/files"))
|
file.RegisterFileEndpoints(api.Group("/files"))
|
||||||
widget.RegisterWidgetEndpoints(api.Group("/widgets"))
|
widget.RegisterWidgetEndpoints(api.Group("/widgets"))
|
||||||
|
@ -849,7 +851,6 @@ func TestDeleteUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDuplicateScenarioForUser(t *testing.T) {
|
func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
|
|
||||||
database.DropTables()
|
database.DropTables()
|
||||||
database.MigrateModels()
|
database.MigrateModels()
|
||||||
assert.NoError(t, database.AddTestUsers())
|
assert.NoError(t, database.AddTestUsers())
|
||||||
|
@ -864,7 +865,6 @@ func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
// AMQP Connection startup is tested here
|
// AMQP Connection startup is tested here
|
||||||
// Not repeated in other tests because it is only needed once
|
// Not repeated in other tests because it is only needed once
|
||||||
session = helper.NewAMQPSession("villas-test-session", amqpURI, "villas", infrastructure_component.ProcessMessage)
|
session = helper.NewAMQPSession("villas-test-session", amqpURI, "villas", infrastructure_component.ProcessMessage)
|
||||||
//session = helper.NewAMQPSession("villas-test-session", amqpURI, "villas", infrastructure_component.ProcessMessage)
|
|
||||||
SetAMQPSession(session)
|
SetAMQPSession(session)
|
||||||
infrastructure_component.SetAMQPSession(session)
|
infrastructure_component.SetAMQPSession(session)
|
||||||
|
|
||||||
|
@ -888,14 +888,13 @@ func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
err = addIC(session, token)
|
err = addIC(session, token)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// wait for IC to be created asynchronously
|
|
||||||
time.Sleep(4 * time.Second)
|
|
||||||
|
|
||||||
// add component config
|
// add component config
|
||||||
err = addComponentConfig(scenarioID, token)
|
err = addComponentConfig(scenarioID, token)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// TODO: add signals
|
// add signals
|
||||||
|
err = addSignals(token)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// add dashboards to scenario
|
// add dashboards to scenario
|
||||||
err = addTwoDashboards(scenarioID, token)
|
err = addTwoDashboards(scenarioID, token)
|
||||||
|
@ -906,7 +905,7 @@ func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
assert.Equal(t, 2, len(dashboards))
|
assert.Equal(t, 2, len(dashboards))
|
||||||
|
|
||||||
// add widgets
|
// add widgets
|
||||||
dashboardID_forAddingWidget := uint(0)
|
dashboardID_forAddingWidget := uint(1)
|
||||||
err = addWidget(dashboardID_forAddingWidget, token)
|
err = addWidget(dashboardID_forAddingWidget, token)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -916,10 +915,11 @@ func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// create fake IC duplicate (would normally be created by villas-controller)
|
// create fake IC duplicate (would normally be created by villas-controller)
|
||||||
err = addFakeIC(session, token)
|
uuidDup := "4854af30-325f-44a5-ad59-b67b2597de68"
|
||||||
|
err = addFakeIC(uuidDup, session, token)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if err := <-duplicateScenarioForUser(originalSo, &myUser.User); err != nil {
|
if err := <-duplicateScenarioForUser(originalSo, &myUser.User, uuidDup); err != nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,7 +957,43 @@ func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
assert.NotEqual(t, configs[0].ICID, configs[1].ICID)
|
assert.NotEqual(t, configs[0].ICID, configs[1].ICID)
|
||||||
assert.NotEqual(t, configs[0].ID, configs[1].ID)
|
assert.NotEqual(t, configs[0].ID, configs[1].ID)
|
||||||
|
|
||||||
|
// compare original and duplicated signals
|
||||||
|
var signals []database.Signal
|
||||||
|
err = db.Order("created_at asc").Find(&signals).Error
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 4, len(signals))
|
||||||
|
assert.Equal(t, signals[0].ConfigID, signals[1].ConfigID)
|
||||||
|
assert.Equal(t, signals[2].ConfigID, signals[3].ConfigID)
|
||||||
|
|
||||||
|
assert.Equal(t, signals[0].Name, signals[2].Name)
|
||||||
|
assert.Equal(t, signals[0].Unit, signals[2].Unit)
|
||||||
|
assert.Equal(t, signals[0].ScalingFactor, signals[2].ScalingFactor)
|
||||||
|
assert.Equal(t, signals[0].Direction, signals[2].Direction)
|
||||||
|
assert.Equal(t, signals[0].Index, signals[2].Index)
|
||||||
|
assert.NotEqual(t, signals[0].ConfigID, signals[2].ConfigID)
|
||||||
|
assert.NotEqual(t, signals[0].ID, signals[2].ID)
|
||||||
|
|
||||||
|
assert.Equal(t, signals[1].Name, signals[3].Name)
|
||||||
|
assert.Equal(t, signals[1].Unit, signals[3].Unit)
|
||||||
|
assert.Equal(t, signals[1].ScalingFactor, signals[3].ScalingFactor)
|
||||||
|
assert.Equal(t, signals[1].Direction, signals[3].Direction)
|
||||||
|
assert.Equal(t, signals[1].Index, signals[3].Index)
|
||||||
|
assert.NotEqual(t, signals[1].ConfigID, signals[3].ConfigID)
|
||||||
|
assert.NotEqual(t, signals[1].ID, signals[3].ID)
|
||||||
|
|
||||||
// compare original and duplicated infrastructure component
|
// compare original and duplicated infrastructure component
|
||||||
|
var ics []database.InfrastructureComponent
|
||||||
|
err = db.Find(&ics).Error
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 2, len(ics))
|
||||||
|
assert.Equal(t, ics[0].Name, ics[1].Name)
|
||||||
|
assert.Equal(t, ics[0].Category, ics[1].Category)
|
||||||
|
assert.Equal(t, ics[0].Type, ics[1].Type)
|
||||||
|
assert.Equal(t, ics[0].CreateParameterSchema, ics[1].CreateParameterSchema)
|
||||||
|
assert.Equal(t, ics[0].StartParameterSchema, ics[1].StartParameterSchema)
|
||||||
|
assert.Equal(t, ics[0].Manager, ics[1].Manager)
|
||||||
|
assert.NotEqual(t, ics[0].UUID, ics[1].UUID)
|
||||||
|
assert.NotEqual(t, ics[0].ID, ics[1].ID)
|
||||||
|
|
||||||
// compare original and duplicated dashboards
|
// compare original and duplicated dashboards
|
||||||
err = db.Order("created_at asc").Find(&dashboards).Error
|
err = db.Order("created_at asc").Find(&dashboards).Error
|
||||||
|
@ -982,20 +1018,18 @@ func TestDuplicateScenarioForUser(t *testing.T) {
|
||||||
assert.Equal(t, 2, len(widgets))
|
assert.Equal(t, 2, len(widgets))
|
||||||
assert.Equal(t, widgets[0].Name, widgets[1].Name)
|
assert.Equal(t, widgets[0].Name, widgets[1].Name)
|
||||||
assert.Equal(t, widgets[0].CustomProperties, widgets[1].CustomProperties)
|
assert.Equal(t, widgets[0].CustomProperties, widgets[1].CustomProperties)
|
||||||
assert.Equal(t, widgets[0].SignalIDs, widgets[1].SignalIDs)
|
|
||||||
assert.Equal(t, widgets[0].MinHeight, widgets[1].MinHeight)
|
assert.Equal(t, widgets[0].MinHeight, widgets[1].MinHeight)
|
||||||
assert.Equal(t, widgets[0].MinWidth, widgets[1].MinWidth)
|
assert.Equal(t, widgets[0].MinWidth, widgets[1].MinWidth)
|
||||||
assert.NotEqual(t, widgets[0].DashboardID, widgets[1].DashboardID)
|
assert.NotEqual(t, widgets[0].DashboardID, widgets[1].DashboardID)
|
||||||
assert.NotEqual(t, widgets[0].ID, widgets[1].ID)
|
assert.NotEqual(t, widgets[0].ID, widgets[1].ID)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addScenario(token string) (scenarioID uint) {
|
||||||
type ScenarioRequest struct {
|
type ScenarioRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addScenario(token string) (scenarioID uint) {
|
|
||||||
newScenario := ScenarioRequest{
|
newScenario := ScenarioRequest{
|
||||||
Name: "Scenario1",
|
Name: "Scenario1",
|
||||||
StartParameters: postgres.Jsonb{json.RawMessage(`{"parameter1" : "testValue1A", "parameter2" : "testValue2A", "parameter3" : 42}`)},
|
StartParameters: postgres.Jsonb{json.RawMessage(`{"parameter1" : "testValue1A", "parameter2" : "testValue2A", "parameter3" : 42}`)},
|
||||||
|
@ -1069,6 +1103,7 @@ func addFile(scenarioID uint, token string) (uint, error) {
|
||||||
return uint(newFileID), nil
|
return uint(newFileID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addTwoDashboards(scenarioID uint, token string) error {
|
||||||
type DashboardRequest struct {
|
type DashboardRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Grid int `json:"grid,omitempty"`
|
Grid int `json:"grid,omitempty"`
|
||||||
|
@ -1076,7 +1111,6 @@ type DashboardRequest struct {
|
||||||
ScenarioID uint `json:"scenarioID,omitempty"`
|
ScenarioID uint `json:"scenarioID,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTwoDashboards(scenarioID uint, token string) error {
|
|
||||||
newDashboardA := DashboardRequest{
|
newDashboardA := DashboardRequest{
|
||||||
Name: "Dashboard_A",
|
Name: "Dashboard_A",
|
||||||
Grid: 15,
|
Grid: 15,
|
||||||
|
@ -1103,6 +1137,7 @@ func addTwoDashboards(scenarioID uint, token string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addWidget(dashboardID uint, token string) error {
|
||||||
type WidgetRequest struct {
|
type WidgetRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
|
@ -1119,7 +1154,6 @@ type WidgetRequest struct {
|
||||||
SignalIDs []int64 `json:"signalIDs,omitempty"`
|
SignalIDs []int64 `json:"signalIDs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addWidget(dashboardID uint, token string) error {
|
|
||||||
newWidget := WidgetRequest{
|
newWidget := WidgetRequest{
|
||||||
Name: "My label",
|
Name: "My label",
|
||||||
Type: "Label",
|
Type: "Label",
|
||||||
|
@ -1143,6 +1177,12 @@ func addWidget(dashboardID uint, token string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newTrue() *bool {
|
||||||
|
b := true
|
||||||
|
return &b
|
||||||
|
}
|
||||||
|
|
||||||
|
func addIC(session *helper.AMQPsession, token string) error {
|
||||||
type ICRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
WebsocketURL string `json:"websocketurl,omitempty"`
|
WebsocketURL string `json:"websocketurl,omitempty"`
|
||||||
|
@ -1159,12 +1199,6 @@ type ICRequest struct {
|
||||||
Manager string `json:"manager,omitempty"`
|
Manager string `json:"manager,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTrue() *bool {
|
|
||||||
b := true
|
|
||||||
return &b
|
|
||||||
}
|
|
||||||
|
|
||||||
func addIC(session *helper.AMQPsession, token string) error {
|
|
||||||
// create IC
|
// create IC
|
||||||
var newIC = ICRequest{
|
var newIC = ICRequest{
|
||||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||||
|
@ -1203,8 +1237,6 @@ func addIC(session *helper.AMQPsession, token string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//time.Sleep(3 * time.Second)
|
|
||||||
|
|
||||||
err = session.CheckConnection()
|
err = session.CheckConnection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1238,8 +1270,7 @@ func addComponentConfig(scenarioID uint, token string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func addFakeIC(session *helper.AMQPsession, token string) error {
|
func addFakeIC(uuid string, session *helper.AMQPsession, token string) error {
|
||||||
|
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
var originalIC database.InfrastructureComponent
|
var originalIC database.InfrastructureComponent
|
||||||
err := db.Find(&originalIC, 1).Error
|
err := db.Find(&originalIC, 1).Error
|
||||||
|
@ -1247,11 +1278,6 @@ func addFakeIC(session *helper.AMQPsession, token string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//session = helper.NewAMQPSession("villas-test-session", amqpURI, "villas", infrastructure_component.ProcessMessage)
|
|
||||||
log.Println(session)
|
|
||||||
|
|
||||||
//time.Sleep(3 * time.Second)
|
|
||||||
|
|
||||||
err = session.CheckConnection()
|
err = session.CheckConnection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1262,16 +1288,53 @@ func addFakeIC(session *helper.AMQPsession, token string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
update.Properties.UUID = "4854af30-325f-44a5-ad59-b67b2597de68"
|
update.Properties.UUID = uuid
|
||||||
|
|
||||||
payload, err := json.Marshal(update)
|
payload, err := json.Marshal(update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(session)
|
|
||||||
|
|
||||||
err = session.Send(payload, originalIC.Manager)
|
err = session.Send(payload, originalIC.Manager)
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addSignals(token string) error {
|
||||||
|
type SignalRequest struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Unit string `json:"unit,omitempty"`
|
||||||
|
Index uint `json:"index,omitempty"`
|
||||||
|
Direction string `json:"direction,omitempty"`
|
||||||
|
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
||||||
|
ConfigID uint `json:"configID,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var newSignalOut = SignalRequest{
|
||||||
|
Name: "outSignal_A",
|
||||||
|
Unit: "V",
|
||||||
|
Direction: "out",
|
||||||
|
Index: 1,
|
||||||
|
ConfigID: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
var newSignalIn = SignalRequest{
|
||||||
|
Name: "inSignal_A",
|
||||||
|
Unit: "V",
|
||||||
|
Direction: "in",
|
||||||
|
Index: 2,
|
||||||
|
ConfigID: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err := helper.TestEndpoint(router, token,
|
||||||
|
"/api/v2/signals", "POST", helper.KeyModels{"signal": newSignalOut})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err = helper.TestEndpoint(router, token,
|
||||||
|
"/api/v2/signals", "POST", helper.KeyModels{"signal": newSignalIn})
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue