-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrace_test.go
31 lines (28 loc) · 997 Bytes
/
trace_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTrace(t *testing.T) {
tr := NewTrace()
chunk, off := tr.NextChunk()
assert.Len(t, chunk, 0, "Without writes NextChunk should return a zero-length object")
assert.Equal(t, 0, off, "The first offset should be zero")
tr.CommitChunk()
testVal1 := []byte("Test1")
testVal2 := []byte("Test2")
tr.Write(testVal1)
chunk, off = tr.NextChunk()
tr.Write(testVal2)
assert.Equal(t, testVal1, chunk, "NextChunk should return write call value")
assert.Equal(t, off, 0, "Offset should still be zero")
tr.CommitChunk()
chunk, off = tr.NextChunk()
assert.Equal(t, testVal2, chunk, "NextChunk should return write call value")
assert.Equal(t, off, len(testVal1), "Offset should be the first chunk")
tr.AbortChunk()
chunk, off = tr.NextChunk()
assert.Equal(t, testVal2, chunk, "NextChunk should return write call value")
assert.Equal(t, off, len(testVal1), "Offset should be the first chunk")
tr.CommitChunk()
}