Skip to content

Commit

Permalink
fix: message properties should contain reqType instead of messageID
Browse files Browse the repository at this point in the history
  • Loading branch information
BonapartePC committed Sep 24, 2024
1 parent c636ee2 commit 14b7885
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions go/stream/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
const (
StageWebhook = "webhook"

mapKeyMessageID = "messageID"
mapKeyReqType = "reqType"
mapKeyRoutingKey = "routingKey"
mapKeyWorkspaceID = "workspaceID"
mapKeySourceID = "sourceID"
Expand All @@ -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"`
Expand Down Expand Up @@ -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],
Expand All @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions go/stream/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -113,7 +113,7 @@ func TestMessage(t *testing.T) {
input := `
{
"properties": {
"messageID": "messageID",
"reqType": "reqType",
"routingKey": "routingKey",
"workspaceID": "workspaceID",
"userID": "userID",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestMessage(t *testing.T) {
input := `
{
"properties": {
"messageID": "messageID",
"reqType": "reqType",
"routingKey": "routingKey",
"workspaceID": "workspaceID",
"userID": "userID",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -266,7 +266,7 @@ func TestMessage(t *testing.T) {

msg := stream.Message{
Properties: stream.MessageProperties{
MessageID: "",
ReqType: "",
RoutingKey: "routingKey",
WorkspaceID: "workspaceID",
SourceID: "sourceID",
Expand All @@ -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")
})
}

0 comments on commit 14b7885

Please sign in to comment.