-
Notifications
You must be signed in to change notification settings - Fork 5
/
write_test.go
102 lines (84 loc) · 1.92 KB
/
write_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
95
96
97
98
99
100
101
102
package gitdb_test
import (
"testing"
"github.com/gogitdb/gitdb/v2"
)
func TestInsert(t *testing.T) {
teardown := setup(t, nil)
defer teardown(t)
m := getTestMessage()
err := insert(m, false)
if err != nil {
t.Errorf(err.Error())
}
}
func TestInsertMany(t *testing.T) {
teardown := setup(t, nil)
defer teardown(t)
defer testDb.Close()
msgs := []gitdb.Model{}
for i := 0; i < 10; i++ {
m := getTestMessage()
msgs = append(msgs, m)
}
err := testDb.InsertMany(msgs)
if err != nil {
t.Errorf(err.Error())
}
}
func BenchmarkInsert(b *testing.B) {
teardown := setup(b, nil)
defer teardown(b)
b.ReportAllocs()
var m gitdb.Model
for i := 0; i <= b.N; i++ {
m = getTestMessage()
err := insert(m, true)
if err != nil {
b.Errorf(err.Error())
}
}
}
func TestDelete(t *testing.T) {
teardown := setup(t, nil)
defer teardown(t)
m := getTestMessageWithId(0)
if err := insert(m, flagFakeRemote); err != nil {
t.Errorf("Error: %s", err.Error())
}
if err := testDb.Delete(gitdb.ID(m)); err != nil {
t.Errorf("Error: %s", err.Error())
}
}
func TestDeleteOrFail(t *testing.T) {
teardown := setup(t, nil)
defer teardown(t)
m := getTestMessageWithId(0)
if err := insert(m, flagFakeRemote); err != nil {
t.Errorf("Error: %s", err.Error())
}
if err := testDb.DeleteOrFail("non_existent_id"); err == nil {
t.Errorf("Error: %s", err.Error())
}
if err := testDb.DeleteOrFail("Message/b0/1"); err == nil {
t.Errorf("Error: %s", err.Error())
}
}
func TestLockUnlock(t *testing.T) {
teardown := setup(t, nil)
defer teardown(t)
m := getTestMessage()
if err := testDb.Lock(m); err != nil {
t.Errorf("testDb.Lock returned - %s", err)
}
if err := testDb.Unlock(m); err != nil {
t.Errorf("testDb.Unlock returned - %s", err)
}
}
func TestGetLockFileNames(t *testing.T) {
m := getTestMessage()
locks := m.GetLockFileNames()
if len(locks) != 1 {
t.Errorf("testMessage return %d lock files", len(locks))
}
}