Skip to content

Commit

Permalink
chore: convert msg properties to string
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir20 committed Dec 13, 2024
1 parent 674e15c commit c9aed73
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/stream/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type MessageProperties struct {
EncryptionKeyID string `json:"encryptionKeyID,omitempty"` // optional
}

func (m MessageProperties) String() string {
return fmt.Sprintf("RequestType: %s, RoutingKey: %s, WorkspaceID: %s, SourceID: %s, ReceivedAt: %s, RequestIP: %s, DestinationID: %s, UserID: %s, SourceJobRunID: %s, SourceTaskRunID: %s, TraceID: %s, SourceType: %s, WebhookFailureReason: %s, Stage: %s, Compression: %s, Encryption: %s, EncryptionKeyID: %s",
m.RequestType, m.RoutingKey, m.WorkspaceID, m.SourceID, m.ReceivedAt, m.RequestIP, m.DestinationID, m.UserID, m.SourceJobRunID, m.SourceTaskRunID, m.TraceID, m.SourceType, m.WebhookFailureReason, m.Stage, m.Compression, m.Encryption, m.EncryptionKeyID)
}

// FromMapProperties converts a property map to MessageProperties.
func FromMapProperties(properties map[string]string) (MessageProperties, error) {
receivedAt, err := time.Parse(time.RFC3339Nano, properties[mapKeyReceivedAt])
Expand Down
26 changes: 26 additions & 0 deletions go/stream/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,30 @@ func TestMessage(t *testing.T) {
err := validator(&msg)
require.EqualError(t, err, "Key: 'Message.Properties.WorkspaceID' Error:Field validation for 'WorkspaceID' failed on the 'required' tag")
})

t.Run("string conversion", func(t *testing.T) {
properties := stream.MessageProperties{
RequestType: "requestType",
RoutingKey: "routingKey",
WorkspaceID: "workspaceID",
SourceID: "sourceID",
ReceivedAt: time.Date(2024, 8, 1, 2, 30, 50, 200, time.UTC),
RequestIP: "10.29.13.20",
DestinationID: "destinationID",
UserID: "userID",
SourceJobRunID: "sourceJobRunID",
SourceTaskRunID: "sourceTaskRunID",
TraceID: "traceID",
SourceType: "sourceType",
WebhookFailureReason: "webhookFailureReason",
Stage: stream.StageWebhook,
Compression: "some-serialized-compression-settings",
Encryption: "some-serialized-encryption-settings",
EncryptionKeyID: "encryptionKeyID",
}

expectedString := "RequestType: requestType, RoutingKey: routingKey, WorkspaceID: workspaceID, SourceID: sourceID, ReceivedAt: 2024-08-01 02:30:50.0000002 +0000 UTC, RequestIP: 10.29.13.20, DestinationID: destinationID, UserID: userID, SourceJobRunID: sourceJobRunID, SourceTaskRunID: sourceTaskRunID, TraceID: traceID, SourceType: sourceType, WebhookFailureReason: webhookFailureReason, Stage: webhook, Compression: some-serialized-compression-settings, Encryption: some-serialized-encryption-settings, EncryptionKeyID: encryptionKeyID"

require.Equal(t, expectedString, properties.String())
})
}

0 comments on commit c9aed73

Please sign in to comment.