Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: message properties should contain reqType instead of messageID [PIPE-1557] #35

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
mapKeyRequestType = "requestType"
mapKeyRoutingKey = "routingKey"
mapKeyWorkspaceID = "workspaceID"
mapKeySourceID = "sourceID"
Expand All @@ -36,7 +36,7 @@ type Message struct {
}

type MessageProperties struct {
MessageID string `json:"messageID" validate:"required"`
RequestType string `json:"requestType,omitempty"` // optional, make it required in the next version
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],
RequestType: properties[mapKeyRequestType],
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,
mapKeyRequestType: properties.RequestType,
mapKeyRoutingKey: properties.RoutingKey,
mapKeyWorkspaceID: properties.WorkspaceID,
mapKeyUserID: properties.UserID,
Expand Down
24 changes: 12 additions & 12 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",
"requestType": "requestType",
"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",
RequestType: "requestType",
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",
"requestType": "requestType",
"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",
RequestType: "requestType",
RoutingKey: "routingKey",
WorkspaceID: "workspaceID",
UserID: "userID",
Expand All @@ -113,7 +113,7 @@ func TestMessage(t *testing.T) {
input := `
{
"properties": {
"messageID": "messageID",
"requestType": "requestType",
"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",
RequestType: "requestType",
RoutingKey: "routingKey",
WorkspaceID: "workspaceID",
UserID: "userID",
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestMessage(t *testing.T) {
input := `
{
"properties": {
"messageID": "messageID",
"requestType": "requestType",
"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",
RequestType: "requestType",
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",
RequestType: "requestType",
RoutingKey: "routingKey",
WorkspaceID: "workspaceID",
SourceID: "sourceID",
Expand All @@ -266,9 +266,9 @@ func TestMessage(t *testing.T) {

msg := stream.Message{
Properties: stream.MessageProperties{
MessageID: "",
RequestType: "requestType",
RoutingKey: "routingKey",
WorkspaceID: "workspaceID",
WorkspaceID: "",
SourceID: "sourceID",
RequestIP: "10.29.13.20",
ReceivedAt: time.Date(2024, 8, 1, 0o2, 30, 50, 200, time.UTC),
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.WorkspaceID' Error:Field validation for 'WorkspaceID' failed on the 'required' tag")
})
}
Loading