-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_test.go
55 lines (45 loc) · 1.21 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
package orbit_test
import (
"testing"
"github.com/bmizerany/assert"
target "github.com/roganartu/orbitus"
)
func TestGetMessage(t *testing.T) {
loop := target.New(buffer_size, nil, nil, nil, nil, nil)
// Check out of bounds index wrapping
msg := loop.GetMessage(1)
msg.SetMarshalled([]byte(test + string(1)))
msg = loop.GetMessage(1 + buffer_size)
assert.Equal(t, msg.GetMarshalled(), []byte(test+string(1)))
}
func TestSetMessage(t *testing.T) {
loop := target.New(buffer_size, nil, nil, nil, nil, nil)
// Check out of bounds index wrapping
msg := loop.GetMessage(1)
msg.SetMarshalled([]byte(test))
loop.SetMessage(1+buffer_size, msg)
msg = loop.GetMessage(1)
assert.Equal(t, msg.GetMarshalled(), []byte(test))
}
func TestMessageID(t *testing.T) {
msg := target.Message{}
msg.SetID(uint64(100))
assert.Equal(t, msg.GetID(), uint64(100))
}
func TestMessageUnmarshalled(t *testing.T) {
tmp := struct {
Title string
}{
"testing",
}
msg := target.Message{}
msg.Init()
msg.SetUnmarshalled(tmp)
assert.Equal(t, msg.GetUnmarshalled(), tmp)
}
func BenchmarkGetMessage(b *testing.B) {
loop := target.New(buffer_size, nil, nil, nil, nil, nil)
for i := 0; i < b.N; i++ {
loop.GetMessage(uint64(i))
}
}