Skip to content

Commit

Permalink
[ISSUE apache#1030] avoid to append unexpected separator to the last …
Browse files Browse the repository at this point in the history
…message key
  • Loading branch information
gaofeihang committed Apr 27, 2023
1 parent 7ae788d commit 000869c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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)
}
}

0 comments on commit 000869c

Please sign in to comment.