-
Notifications
You must be signed in to change notification settings - Fork 7
/
message_test.go
59 lines (46 loc) · 1.18 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package streams_test
import (
"context"
"testing"
"github.com/msales/streams/v6"
"github.com/stretchr/testify/assert"
)
func TestMessage_Empty(t *testing.T) {
tests := []struct {
key interface{}
value interface{}
empty bool
}{
{"test", "test", false},
{nil, "test", false},
{"test", nil, false},
{nil, nil, true},
}
for _, tt := range tests {
msg := streams.NewMessage(tt.key, tt.value)
assert.Equal(t, tt.empty, msg.Empty())
}
}
func TestNewMessage(t *testing.T) {
msg := streams.NewMessage("test", "test")
assert.Equal(t, context.Background(), msg.Ctx)
assert.Equal(t, "test", msg.Key)
assert.Equal(t, "test", msg.Value)
}
type ctxKey string
func TestNewMessageWithContext(t *testing.T) {
ctx := context.WithValue(context.Background(), ctxKey("1"), "2")
msg := streams.NewMessageWithContext(ctx, "test", "test")
assert.Equal(t, ctx, msg.Ctx)
assert.Equal(t, "test", msg.Key)
assert.Equal(t, "test", msg.Value)
}
func TestMessage_Metadata(t *testing.T) {
s := new(MockSource)
m := new(MockMetadata)
msg := streams.NewMessage("test", "test")
msg = msg.WithMetadata(s, m)
src, meta := msg.Metadata()
assert.Equal(t, s, src)
assert.Equal(t, m, meta)
}