-
Notifications
You must be signed in to change notification settings - Fork 7
/
buf_write_seeker_test.go
52 lines (47 loc) · 1.36 KB
/
buf_write_seeker_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
package rosbag
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBufWriteSeeker(t *testing.T) {
t.Run("writes without error", func(t *testing.T) {
buf := newBufWriteSeeker()
_, err := buf.Write([]byte{0x01, 0x02, 0x03})
assert.Nil(t, err)
assert.Equal(t, []byte{0x01, 0x02, 0x03}, buf.Bytes())
})
t.Run("seeks since start without error", func(t *testing.T) {
buf := newBufWriteSeeker()
_, err := buf.Write([]byte{0x01, 0x02, 0x03})
assert.Nil(t, err)
_, err = buf.Seek(1, io.SeekStart)
assert.Nil(t, err)
_, err = buf.Write([]byte{0x05})
assert.Nil(t, err)
assert.Equal(t, []byte{0x01, 0x05, 0x03}, buf.Bytes())
})
t.Run("seeks from end", func(t *testing.T) {
buf := newBufWriteSeeker()
_, err := buf.Write([]byte{0x01, 0x02, 0x03})
assert.Nil(t, err)
_, err = buf.Seek(-2, io.SeekEnd)
assert.Nil(t, err)
_, err = buf.Write([]byte{0x05})
assert.Nil(t, err)
assert.Equal(t, []byte{0x01, 0x05, 0x03}, buf.Bytes())
})
t.Run("seeks from current location", func(t *testing.T) {
buf := newBufWriteSeeker()
_, err := buf.Write([]byte{0x01, 0x02, 0x03})
assert.Nil(t, err)
//
_, err = buf.Seek(-2, io.SeekEnd)
assert.Nil(t, err)
_, err = buf.Seek(1, io.SeekCurrent)
assert.Nil(t, err)
_, err = buf.Write([]byte{0x05})
assert.Nil(t, err)
assert.Equal(t, []byte{0x01, 0x02, 0x05}, buf.Bytes())
})
}