/
msg_test.go
44 lines (35 loc) · 894 Bytes
/
msg_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
package pubsub
import (
"bytes"
rand "github.com/trpedersen/rand"
"testing"
)
func randMsg() Msg {
topic := rand.RandStr(100, "alphanum")
bodyStr := rand.RandStr(1000, "alphanum")
body := []byte(bodyStr)
msg := NewMsg(topic, body)
return msg
}
func TestMsgCreate(t *testing.T) {
topic := rand.RandStr(100, "alphanum")
bodyStr := rand.RandStr(1000, "alphanum")
body := []byte(bodyStr)
msg := NewMsg(topic, body)
if msg.Topic() != topic {
t.Errorf("expected %s, got %s", topic, msg.Topic())
}
if !bytes.Equal(body, msg.Body()) {
t.Errorf("expected %s, got %s", body, msg.Body())
}
}
func TestMsgClone(t *testing.T) {
msg := randMsg()
clone := msg.Clone()
if msg.Topic() != clone.Topic() {
t.Errorf("expected %s, got %s", msg.Topic(), clone.Topic())
}
if !bytes.Equal(msg.Body(), clone.Body()) {
t.Errorf("expected %s, got %s", msg.Body(), clone.Body())
}
}