From 14b788522df41e5cdbb56233bdb91eccd593efba Mon Sep 17 00:00:00 2001 From: BonapartePC Date: Tue, 24 Sep 2024 16:34:00 +0530 Subject: [PATCH] fix: message properties should contain reqType instead of messageID --- go/stream/message.go | 8 ++++---- go/stream/message_test.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go/stream/message.go b/go/stream/message.go index 4b938fd..0ff9905 100644 --- a/go/stream/message.go +++ b/go/stream/message.go @@ -11,7 +11,7 @@ import ( const ( StageWebhook = "webhook" - mapKeyMessageID = "messageID" + mapKeyReqType = "reqType" mapKeyRoutingKey = "routingKey" mapKeyWorkspaceID = "workspaceID" mapKeySourceID = "sourceID" @@ -36,7 +36,7 @@ type Message struct { } type MessageProperties struct { - MessageID string `json:"messageID" validate:"required"` + ReqType string `json:"reqType" validate:"required"` RoutingKey string `json:"routingKey" validate:"required"` WorkspaceID string `json:"workspaceID" validate:"required"` SourceID string `json:"sourceID" validate:"required"` @@ -64,7 +64,7 @@ func FromMapProperties(properties map[string]string) (MessageProperties, error) } return MessageProperties{ - MessageID: properties[mapKeyMessageID], + ReqType: properties[mapKeyReqType], RoutingKey: properties[mapKeyRoutingKey], WorkspaceID: properties[mapKeyWorkspaceID], RequestIP: properties[mapKeyRequestIP], @@ -87,7 +87,7 @@ func FromMapProperties(properties map[string]string) (MessageProperties, error) // ToMapProperties converts a Message to map properties. func ToMapProperties(properties MessageProperties) map[string]string { m := map[string]string{ - mapKeyMessageID: properties.MessageID, + mapKeyReqType: properties.ReqType, mapKeyRoutingKey: properties.RoutingKey, mapKeyWorkspaceID: properties.WorkspaceID, mapKeyUserID: properties.UserID, diff --git a/go/stream/message_test.go b/go/stream/message_test.go index 29805e6..353c439 100644 --- a/go/stream/message_test.go +++ b/go/stream/message_test.go @@ -13,7 +13,7 @@ import ( func TestMessage(t *testing.T) { t.Run("properties to/from: pulsar", func(t *testing.T) { input := map[string]string{ - "messageID": "messageID", + "reqType": "reqType", "routingKey": "routingKey", "workspaceID": "workspaceID", "userID": "userID", @@ -33,7 +33,7 @@ func TestMessage(t *testing.T) { require.NoError(t, err) require.Equal(t, stream.MessageProperties{ - MessageID: "messageID", + ReqType: "reqType", RoutingKey: "routingKey", WorkspaceID: "workspaceID", UserID: "userID", @@ -63,7 +63,7 @@ func TestMessage(t *testing.T) { t.Run("properties to/from: pulsar with webhook stage", func(t *testing.T) { input := map[string]string{ - "messageID": "messageID", + "reqType": "reqType", "routingKey": "routingKey", "workspaceID": "workspaceID", "userID": "userID", @@ -86,7 +86,7 @@ func TestMessage(t *testing.T) { require.NoError(t, err) require.Equal(t, stream.MessageProperties{ - MessageID: "messageID", + ReqType: "reqType", RoutingKey: "routingKey", WorkspaceID: "workspaceID", UserID: "userID", @@ -113,7 +113,7 @@ func TestMessage(t *testing.T) { input := ` { "properties": { - "messageID": "messageID", + "reqType": "reqType", "routingKey": "routingKey", "workspaceID": "workspaceID", "userID": "userID", @@ -142,7 +142,7 @@ func TestMessage(t *testing.T) { require.NoError(t, err) require.Equal(t, stream.Message{ Properties: stream.MessageProperties{ - MessageID: "messageID", + ReqType: "reqType", RoutingKey: "routingKey", WorkspaceID: "workspaceID", UserID: "userID", @@ -175,7 +175,7 @@ func TestMessage(t *testing.T) { input := ` { "properties": { - "messageID": "messageID", + "reqType": "reqType", "routingKey": "routingKey", "workspaceID": "workspaceID", "userID": "userID", @@ -207,7 +207,7 @@ func TestMessage(t *testing.T) { require.NoError(t, err) require.Equal(t, stream.Message{ Properties: stream.MessageProperties{ - MessageID: "messageID", + ReqType: "reqType", RoutingKey: "routingKey", WorkspaceID: "workspaceID", UserID: "userID", @@ -243,7 +243,7 @@ func TestMessage(t *testing.T) { msg := stream.Message{ Properties: stream.MessageProperties{ - MessageID: "messageID", + ReqType: "reqType", RoutingKey: "routingKey", WorkspaceID: "workspaceID", SourceID: "sourceID", @@ -266,7 +266,7 @@ func TestMessage(t *testing.T) { msg := stream.Message{ Properties: stream.MessageProperties{ - MessageID: "", + ReqType: "", RoutingKey: "routingKey", WorkspaceID: "workspaceID", SourceID: "sourceID", @@ -277,6 +277,6 @@ func TestMessage(t *testing.T) { } err := validator(&msg) - require.EqualError(t, err, "Key: 'Message.Properties.MessageID' Error:Field validation for 'MessageID' failed on the 'required' tag") + require.EqualError(t, err, "Key: 'Message.Properties.ReqType' Error:Field validation for 'ReqType' failed on the 'required' tag") }) }