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

[ISSUE #1030] Avoid to append unexpected separator to message key #1031

Merged
merged 1 commit into from
Apr 27, 2023
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: 1 addition & 7 deletions primitive/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,7 @@ func (m *Message) WithTag(tags string) *Message {
}

func (m *Message) WithKeys(keys []string) *Message {
var sb strings.Builder
for _, k := range keys {
sb.WriteString(k)
sb.WriteString(PropertyKeySeparator)
}

m.WithProperty(PropertyKeys, sb.String())
m.WithProperty(PropertyKeys, strings.Join(keys, PropertyKeySeparator))
return m
}

Expand Down
10 changes: 10 additions & 0 deletions primitive/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ func TestMessageID(t *testing.T) {
}
t.Log(msgID)
}

func TestMessageKey(t *testing.T) {
msg := &Message{}
expected := "testKey"
msg.WithKeys([]string{expected})
actual := msg.GetKeys()
if actual != expected {
t.Fatalf("get message key error: expected is '%s', actual is '%s'", expected, actual)
}
}