forked from avinassh/go-caskdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_test.go
59 lines (56 loc) · 1.42 KB
/
format_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
58
59
package caskdb
import (
"testing"
)
func Test_encodeHeader(t *testing.T) {
tests := []struct {
timestamp uint32
keySize uint32
valueSize uint32
}{
{10, 10, 10},
{0, 0, 0},
{10000, 10000, 10000},
}
for _, tt := range tests {
data := encodeHeader(tt.timestamp, tt.keySize, tt.valueSize)
timestamp, keySize, valueSize := decodeHeader(data)
if timestamp != tt.timestamp {
t.Errorf("encodeHeader() timestamp = %v, want %v", timestamp, tt.timestamp)
}
if keySize != tt.keySize {
t.Errorf("encodeHeader() keySize = %v, want %v", keySize, tt.keySize)
}
if valueSize != tt.valueSize {
t.Errorf("encodeHeader() valueSize = %v, want %v", valueSize, tt.valueSize)
}
}
}
func Test_encodeKV(t *testing.T) {
tests := []struct {
timestamp uint32
key string
value string
size int
}{
{10, "hello", "world", headerSize + 10},
{0, "", "", headerSize},
{100, "🔑", "", headerSize + 4},
}
for _, tt := range tests {
size, data := encodeKV(tt.timestamp, tt.key, tt.value)
timestamp, key, value := decodeKV(data)
if timestamp != tt.timestamp {
t.Errorf("encodeKV() timestamp = %v, want %v", timestamp, tt.timestamp)
}
if key != tt.key {
t.Errorf("encodeKV() key = %v, want %v", key, tt.key)
}
if value != tt.value {
t.Errorf("encodeKV() value = %v, want %v", value, tt.value)
}
if size != tt.size {
t.Errorf("encodeKV() size = %v, want %v", size, tt.size)
}
}
}