AMQP: remove UUID from ICstatus, fake headers in IC testing

This commit is contained in:
Sonja Happ 2021-01-18 16:04:37 +01:00
parent f4bcc49fbe
commit 8a5b276b45
2 changed files with 28 additions and 17 deletions

View file

@ -56,7 +56,6 @@ type Action struct {
}
type ICStatus struct {
UUID *string `json:"uuid"`
State *string `json:"state"`
Name *string `json:"name"`
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)
}
//payload.Status.UUID = new(string)
headers := amqp.Table(message.Headers)
*payload.Status.UUID = fmt.Sprintf("%v", headers["uuid"])
if payload.Status != nil {
//log.Println("Processing AMQP message: ", string(message.Body))
// 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)
if err != nil {
@ -280,7 +277,7 @@ func processMessage(message amqp.Delivery) error {
if err == gorm.ErrRecordNotFound {
// create new record
err = createExternalIC(payload)
err = createExternalIC(payload, ICUUID)
} else if err != nil {
// database error
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
}
func createExternalIC(payload ICUpdate) error {
func createExternalIC(payload ICUpdate, ICUUID string) error {
var newICReq AddICRequest
newICReq.InfrastructureComponent.UUID = *payload.Status.UUID
newICReq.InfrastructureComponent.UUID = ICUUID
if payload.Status.Name == nil ||
payload.Status.Category == nil ||
payload.Status.Type == nil {

View file

@ -328,8 +328,6 @@ func TestUpdateICAsAdmin(t *testing.T) {
// fake an IC update (create) message
var update ICUpdate
update.Status = new(ICStatus)
update.Status.UUID = new(string)
*update.Status.UUID = helper.ICB.UUID
update.Status.State = new(string)
*update.Status.State = "idle"
update.Status.Name = new(string)
@ -342,6 +340,10 @@ func TestUpdateICAsAdmin(t *testing.T) {
payload, err := json.Marshal(update)
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{
DeliveryMode: 2,
Timestamp: time.Now(),
@ -349,6 +351,7 @@ func TestUpdateICAsAdmin(t *testing.T) {
ContentEncoding: "utf-8",
Priority: 0,
Body: payload,
Headers: headers,
}
err = CheckConnection()
@ -479,8 +482,6 @@ func TestDeleteICAsAdmin(t *testing.T) {
// fake an IC update (create) message
var update ICUpdate
update.Status = new(ICStatus)
update.Status.UUID = new(string)
*update.Status.UUID = helper.ICB.UUID
update.Status.State = new(string)
*update.Status.State = "idle"
update.Status.Name = new(string)
@ -493,6 +494,10 @@ func TestDeleteICAsAdmin(t *testing.T) {
payload, err := json.Marshal(update)
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{
DeliveryMode: 2,
Timestamp: time.Now(),
@ -500,6 +505,7 @@ func TestDeleteICAsAdmin(t *testing.T) {
ContentEncoding: "utf-8",
Priority: 0,
Body: payload,
Headers: headers,
}
err = CheckConnection()
@ -777,14 +783,16 @@ func TestCreateUpdateViaAMQPRecv(t *testing.T) {
// fake an IC update message
var update ICUpdate
update.Status = new(ICStatus)
update.Status.UUID = new(string)
*update.Status.UUID = helper.ICA.UUID
update.Status.State = new(string)
*update.Status.State = "idle"
payload, err := json.Marshal(update)
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{
DeliveryMode: 2,
Timestamp: time.Now(),
@ -792,10 +800,12 @@ func TestCreateUpdateViaAMQPRecv(t *testing.T) {
ContentEncoding: "utf-8",
Priority: 0,
Body: payload,
Headers: headers,
}
err = CheckConnection()
assert.NoError(t, err)
err = client.channel.Publish(VILLAS_EXCHANGE,
"",
false,
@ -900,8 +910,7 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
// fake an IC update message
var update ICUpdate
update.Status = new(ICStatus)
update.Status.UUID = new(string)
*update.Status.UUID = helper.ICA.UUID
update.Status.State = new(string)
*update.Status.State = "idle"
// complete the (required) data of an IC
@ -925,6 +934,10 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
payload, err := json.Marshal(update)
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{
DeliveryMode: 2,
Timestamp: time.Now(),
@ -932,6 +945,7 @@ func TestDeleteICViaAMQPRecv(t *testing.T) {
ContentEncoding: "utf-8",
Priority: 0,
Body: payload,
Headers: headers,
}
err = CheckConnection()