mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
AMQP: remove UUID from ICstatus, fake headers in IC testing
This commit is contained in:
parent
f4bcc49fbe
commit
8a5b276b45
2 changed files with 28 additions and 17 deletions
|
@ -56,7 +56,6 @@ type Action struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICStatus struct {
|
type ICStatus struct {
|
||||||
UUID *string `json:"uuid"`
|
|
||||||
State *string `json:"state"`
|
State *string `json:"state"`
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Category *string `json:"category"`
|
Category *string `json:"category"`
|
||||||
|
@ -262,14 +261,12 @@ func processMessage(message amqp.Delivery) error {
|
||||||
return fmt.Errorf("AMQP: Could not unmarshal message to JSON: %v err: %v", string(message.Body), err)
|
return fmt.Errorf("AMQP: Could not unmarshal message to JSON: %v err: %v", string(message.Body), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//payload.Status.UUID = new(string)
|
|
||||||
headers := amqp.Table(message.Headers)
|
|
||||||
*payload.Status.UUID = fmt.Sprintf("%v", headers["uuid"])
|
|
||||||
|
|
||||||
if payload.Status != nil {
|
if payload.Status != nil {
|
||||||
//log.Println("Processing AMQP message: ", string(message.Body))
|
//log.Println("Processing AMQP message: ", string(message.Body))
|
||||||
// if a message contains a "state" field, it is an update for an IC
|
// if a message contains a "state" field, it is an update for an IC
|
||||||
ICUUID := *payload.Status.UUID
|
|
||||||
|
headers := amqp.Table(message.Headers)
|
||||||
|
ICUUID := fmt.Sprintf("%v", headers["uuid"])
|
||||||
_, err = uuid.Parse(ICUUID)
|
_, err = uuid.Parse(ICUUID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -280,7 +277,7 @@ func processMessage(message amqp.Delivery) error {
|
||||||
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
// create new record
|
// create new record
|
||||||
err = createExternalIC(payload)
|
err = createExternalIC(payload, ICUUID)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
// database error
|
// database error
|
||||||
err = fmt.Errorf("AMQP: Database error for IC %v DB error message: %v", ICUUID, err)
|
err = fmt.Errorf("AMQP: Database error for IC %v DB error message: %v", ICUUID, err)
|
||||||
|
@ -292,10 +289,10 @@ func processMessage(message amqp.Delivery) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createExternalIC(payload ICUpdate) error {
|
func createExternalIC(payload ICUpdate, ICUUID string) error {
|
||||||
|
|
||||||
var newICReq AddICRequest
|
var newICReq AddICRequest
|
||||||
newICReq.InfrastructureComponent.UUID = *payload.Status.UUID
|
newICReq.InfrastructureComponent.UUID = ICUUID
|
||||||
if payload.Status.Name == nil ||
|
if payload.Status.Name == nil ||
|
||||||
payload.Status.Category == nil ||
|
payload.Status.Category == nil ||
|
||||||
payload.Status.Type == nil {
|
payload.Status.Type == nil {
|
||||||
|
|
|
@ -328,8 +328,6 @@ func TestUpdateICAsAdmin(t *testing.T) {
|
||||||
// fake an IC update (create) message
|
// fake an IC update (create) message
|
||||||
var update ICUpdate
|
var update ICUpdate
|
||||||
update.Status = new(ICStatus)
|
update.Status = new(ICStatus)
|
||||||
update.Status.UUID = new(string)
|
|
||||||
*update.Status.UUID = helper.ICB.UUID
|
|
||||||
update.Status.State = new(string)
|
update.Status.State = new(string)
|
||||||
*update.Status.State = "idle"
|
*update.Status.State = "idle"
|
||||||
update.Status.Name = new(string)
|
update.Status.Name = new(string)
|
||||||
|
@ -342,6 +340,10 @@ func TestUpdateICAsAdmin(t *testing.T) {
|
||||||
payload, err := json.Marshal(update)
|
payload, err := json.Marshal(update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var headers map[string]interface{}
|
||||||
|
headers = make(map[string]interface{}) // empty map
|
||||||
|
headers["uuid"] = helper.ICB.UUID // set uuid
|
||||||
|
|
||||||
msg := amqp.Publishing{
|
msg := amqp.Publishing{
|
||||||
DeliveryMode: 2,
|
DeliveryMode: 2,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
@ -349,6 +351,7 @@ func TestUpdateICAsAdmin(t *testing.T) {
|
||||||
ContentEncoding: "utf-8",
|
ContentEncoding: "utf-8",
|
||||||
Priority: 0,
|
Priority: 0,
|
||||||
Body: payload,
|
Body: payload,
|
||||||
|
Headers: headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CheckConnection()
|
err = CheckConnection()
|
||||||
|
@ -479,8 +482,6 @@ func TestDeleteICAsAdmin(t *testing.T) {
|
||||||
// fake an IC update (create) message
|
// fake an IC update (create) message
|
||||||
var update ICUpdate
|
var update ICUpdate
|
||||||
update.Status = new(ICStatus)
|
update.Status = new(ICStatus)
|
||||||
update.Status.UUID = new(string)
|
|
||||||
*update.Status.UUID = helper.ICB.UUID
|
|
||||||
update.Status.State = new(string)
|
update.Status.State = new(string)
|
||||||
*update.Status.State = "idle"
|
*update.Status.State = "idle"
|
||||||
update.Status.Name = new(string)
|
update.Status.Name = new(string)
|
||||||
|
@ -493,6 +494,10 @@ func TestDeleteICAsAdmin(t *testing.T) {
|
||||||
payload, err := json.Marshal(update)
|
payload, err := json.Marshal(update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var headers map[string]interface{}
|
||||||
|
headers = make(map[string]interface{}) // empty map
|
||||||
|
headers["uuid"] = helper.ICB.UUID // set uuid
|
||||||
|
|
||||||
msg := amqp.Publishing{
|
msg := amqp.Publishing{
|
||||||
DeliveryMode: 2,
|
DeliveryMode: 2,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
@ -500,6 +505,7 @@ func TestDeleteICAsAdmin(t *testing.T) {
|
||||||
ContentEncoding: "utf-8",
|
ContentEncoding: "utf-8",
|
||||||
Priority: 0,
|
Priority: 0,
|
||||||
Body: payload,
|
Body: payload,
|
||||||
|
Headers: headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CheckConnection()
|
err = CheckConnection()
|
||||||
|
@ -777,14 +783,16 @@ func TestCreateUpdateViaAMQPRecv(t *testing.T) {
|
||||||
// fake an IC update message
|
// fake an IC update message
|
||||||
var update ICUpdate
|
var update ICUpdate
|
||||||
update.Status = new(ICStatus)
|
update.Status = new(ICStatus)
|
||||||
update.Status.UUID = new(string)
|
|
||||||
*update.Status.UUID = helper.ICA.UUID
|
|
||||||
update.Status.State = new(string)
|
update.Status.State = new(string)
|
||||||
*update.Status.State = "idle"
|
*update.Status.State = "idle"
|
||||||
|
|
||||||
payload, err := json.Marshal(update)
|
payload, err := json.Marshal(update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var headers map[string]interface{}
|
||||||
|
headers = make(map[string]interface{}) // empty map
|
||||||
|
headers["uuid"] = helper.ICB.UUID // set uuid
|
||||||
|
|
||||||
msg := amqp.Publishing{
|
msg := amqp.Publishing{
|
||||||
DeliveryMode: 2,
|
DeliveryMode: 2,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
@ -792,10 +800,12 @@ func TestCreateUpdateViaAMQPRecv(t *testing.T) {
|
||||||
ContentEncoding: "utf-8",
|
ContentEncoding: "utf-8",
|
||||||
Priority: 0,
|
Priority: 0,
|
||||||
Body: payload,
|
Body: payload,
|
||||||
|
Headers: headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CheckConnection()
|
err = CheckConnection()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = client.channel.Publish(VILLAS_EXCHANGE,
|
err = client.channel.Publish(VILLAS_EXCHANGE,
|
||||||
"",
|
"",
|
||||||
false,
|
false,
|
||||||
|
@ -900,8 +910,7 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
|
||||||
// fake an IC update message
|
// fake an IC update message
|
||||||
var update ICUpdate
|
var update ICUpdate
|
||||||
update.Status = new(ICStatus)
|
update.Status = new(ICStatus)
|
||||||
update.Status.UUID = new(string)
|
|
||||||
*update.Status.UUID = helper.ICA.UUID
|
|
||||||
update.Status.State = new(string)
|
update.Status.State = new(string)
|
||||||
*update.Status.State = "idle"
|
*update.Status.State = "idle"
|
||||||
// complete the (required) data of an IC
|
// complete the (required) data of an IC
|
||||||
|
@ -925,6 +934,10 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
|
||||||
payload, err := json.Marshal(update)
|
payload, err := json.Marshal(update)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var headers map[string]interface{}
|
||||||
|
headers = make(map[string]interface{}) // empty map
|
||||||
|
headers["uuid"] = helper.ICB.UUID // set uuid
|
||||||
|
|
||||||
msg := amqp.Publishing{
|
msg := amqp.Publishing{
|
||||||
DeliveryMode: 2,
|
DeliveryMode: 2,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
@ -932,6 +945,7 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
|
||||||
ContentEncoding: "utf-8",
|
ContentEncoding: "utf-8",
|
||||||
Priority: 0,
|
Priority: 0,
|
||||||
Body: payload,
|
Body: payload,
|
||||||
|
Headers: headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CheckConnection()
|
err = CheckConnection()
|
||||||
|
|
Loading…
Add table
Reference in a new issue