-
Notifications
You must be signed in to change notification settings - Fork 5
/
schema_test.go
94 lines (79 loc) · 2.05 KB
/
schema_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package gitdb_test
import (
"fmt"
"testing"
"github.com/gogitdb/gitdb/v2"
)
func TestAutoBlock(t *testing.T) {
cfg := getReadTestConfig(gitdb.RecVersion)
teardown := setup(t, cfg)
defer teardown(t)
m := getTestMessage()
want := "b0"
got := gitdb.AutoBlock(cfg.DBPath, m, gitdb.BlockByCount, 10)
if got != want {
t.Errorf("want: %s, got: %s", want, got)
}
m.MessageId = 11
want = "b1"
got = gitdb.AutoBlock(cfg.DBPath, m, gitdb.BlockByCount, 10)
if got != want {
t.Errorf("want: %s, got: %s", want, got)
}
m.MessageId = 11
want = "b0"
got = gitdb.AutoBlock("/non/existent/path", m, gitdb.BlockByCount, 10)
if got != want {
t.Errorf("want: %s, got: %s", want, got)
}
}
func TestHydrate(t *testing.T) {
teardown := setup(t, getReadTestConfig(gitdb.RecVersion))
defer teardown(t)
result := &Message{}
records, err := testDb.Fetch("Message")
if err != nil {
t.Errorf("testDb.Fetch failed: %s", err)
}
err = records[0].Hydrate(result)
if err != nil {
t.Errorf("record.Hydrate failed: %s", err)
}
}
func TestParseId(t *testing.T) {
testId := "DatasetName/Block/RecordId"
ds, block, recordId, err := gitdb.ParseID(testId)
passed := ds == "DatasetName" && block == "Block" && recordId == "RecordId" && err == nil
if !passed {
t.Errorf("want: DatasetName|Block|RecordId, Got:%s|%s|%s", ds, block, recordId)
}
}
func TestValidate(t *testing.T) {
cases := []struct {
dataset string
block string
record string
indexes map[string]interface{}
pass bool
}{
{"d1", "b0", "r0", nil, true},
{"", "b0", "r0", nil, false},
{"d1", "", "r0", nil, false},
{"d1", "b0", "", nil, false},
{"", "", "", nil, false},
}
for _, tc := range cases {
t.Run(fmt.Sprintf("%s/%s/%s", tc.dataset, tc.block, tc.record), func(t *testing.T) {
err := gitdb.NewSchema(tc.dataset, tc.block, tc.record, tc.indexes).Validate()
if (err == nil) != tc.pass {
t.Errorf("test failed: %s", err)
}
})
}
}
func BenchmarkParseId(b *testing.B) {
b.ReportAllocs()
for i := 0; i <= b.N; i++ {
gitdb.ParseID("DatasetName/Block/RecordId")
}
}