-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_test.go
More file actions
38 lines (31 loc) · 857 Bytes
/
message_test.go
File metadata and controls
38 lines (31 loc) · 857 Bytes
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
package flow
import (
"bytes"
"testing"
)
func TestMessageEncoding(t *testing.T) {
codec := DefaultCodec{}
msg := Message{
Stream: "message stream",
PartitionKey: []byte("partition key"),
Data: []byte("message data"),
}
data := codec.EncodeMessage(msg)
unmarshalled, err := codec.DecodeMessage(msg.Stream, data)
switch {
case err != nil:
t.Fatalf("unexpected error: %v", err)
case !equalMessage(msg, unmarshalled):
t.Fatalf("unexpected unmarshalled message: %+v", unmarshalled)
}
// decode from invalid data
_, err = codec.DecodeMessage(msg.Stream, []byte("invalid data"))
if err == nil {
t.Fatal("error expected, got none")
}
}
func equalMessage(left, right Message) bool {
return left.Stream == right.Stream &&
bytes.Equal(left.PartitionKey, right.PartitionKey) &&
bytes.Equal(left.Data, right.Data)
}