-
Notifications
You must be signed in to change notification settings - Fork 0
/
header_test.go
57 lines (48 loc) · 1.02 KB
/
header_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
56
57
package wal
import (
"bytes"
"testing"
"github.com/matryer/is"
)
func TestHeaderMarshal(t *testing.T) {
is := is.New(t)
header := header{
Version: 1,
Page: 1024,
Block: 256,
Size: 1024 * 1024,
}
raw, err := header.marshal()
is.NoErr(err)
is.Equal(len(raw), headerLength)
}
func TestHeaderMarshalInvalid(t *testing.T) {
is := is.New(t)
header := header{
Version: 1,
Page: 1024,
Block: 250,
Size: 1024 * 1024,
}
_, err := header.marshal()
is.True(err != nil)
}
func TestHeaderUnmarshal(t *testing.T) {
is := is.New(t)
verVal := 1
pageVal := int64(1024)
blockVal := int64(256)
sizeVal := int64(1024 * 1024)
buff := bytes.Buffer{}
buff.WriteByte(byte(verVal))
buff.Write(encodeInt64(pageVal))
buff.Write(encodeInt64(blockVal))
buff.Write(encodeInt64(sizeVal))
header := header{}
err := header.unmarshal(buff.Bytes())
is.NoErr(err)
is.Equal(header.Version, formatVersion(verVal))
is.Equal(header.Page, pageVal)
is.Equal(header.Block, blockVal)
is.Equal(header.Size, sizeVal)
}