-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtyped_test.go
64 lines (54 loc) · 1.39 KB
/
typed_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
60
61
62
63
64
package klevdb
import (
"testing"
"github.com/stretchr/testify/require"
)
type tobj struct {
V string `json:"v"`
}
func TestKV(t *testing.T) {
dir := t.TempDir()
l, err := OpenT[tobj, tobj](dir, Options{}, JsonCodec[tobj]{}, JsonCodec[tobj]{})
require.NoError(t, err)
_, err = l.Publish([]TMessage[tobj, tobj]{
{
Key: tobj{"hello"},
Value: tobj{"world"},
},
{
Key: tobj{"hello"},
KeyEmpty: true,
Value: tobj{"world"},
},
{
Key: tobj{"hello"},
Value: tobj{"world"},
ValueEmpty: true,
},
{
Key: tobj{"hello"},
KeyEmpty: true,
Value: tobj{"world"},
ValueEmpty: true,
},
})
require.NoError(t, err)
_, msgs, err := l.Consume(OffsetOldest, 4)
require.NoError(t, err)
require.Equal(t, tobj{"hello"}, msgs[0].Key)
require.False(t, msgs[0].KeyEmpty)
require.Equal(t, tobj{"world"}, msgs[0].Value)
require.False(t, msgs[0].ValueEmpty)
require.Equal(t, tobj{""}, msgs[1].Key)
require.True(t, msgs[1].KeyEmpty)
require.Equal(t, tobj{"world"}, msgs[1].Value)
require.False(t, msgs[1].ValueEmpty)
require.Equal(t, tobj{"hello"}, msgs[2].Key)
require.False(t, msgs[2].KeyEmpty)
require.Equal(t, tobj{""}, msgs[2].Value)
require.True(t, msgs[2].ValueEmpty)
require.Equal(t, tobj{""}, msgs[3].Key)
require.True(t, msgs[3].KeyEmpty)
require.Equal(t, tobj{""}, msgs[3].Value)
require.True(t, msgs[3].ValueEmpty)
}