-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtestutils.go
69 lines (58 loc) · 1.36 KB
/
testutils.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
60
61
62
63
64
65
66
67
68
69
package rosbag
import (
"testing"
"github.com/stretchr/testify/assert"
)
func bagfile(t *testing.T, connections []*Connection, messages []*Message) []byte {
buf := newBufWriteSeeker()
writer, err := NewWriter(buf)
assert.Nil(t, err)
for _, connection := range connections {
assert.Nil(t, writer.WriteConnection(connection))
}
for _, message := range messages {
assert.Nil(t, writer.WriteMessage(message))
}
assert.Nil(t, writer.Close())
return buf.Bytes()
}
type connectionOptions struct {
latching *bool
callerID *string
}
type connectionOption func(*connectionOptions)
func withLatching(v bool) connectionOption {
return func(o *connectionOptions) {
o.latching = &v
}
}
func withCallerID(id string) connectionOption {
return func(o *connectionOptions) {
o.callerID = &id
}
}
func connection(id uint32, topic string, options ...connectionOption) *Connection {
opts := connectionOptions{}
for _, opt := range options {
opt(&opts)
}
return &Connection{
Conn: id,
Topic: topic,
Data: ConnectionHeader{
Topic: topic,
Type: "123",
MD5Sum: "abc",
MessageDefinition: []byte{0x01, 0x02, 0x03},
CallerID: opts.callerID,
Latching: opts.latching,
},
}
}
func message(conn uint32, time uint64, data []byte) *Message {
return &Message{
Conn: conn,
Time: time,
Data: data,
}
}