@@ -11,169 +11,175 @@ import (
11
11
"github.com/git-bug/git-bug/entities/bug"
12
12
"github.com/git-bug/git-bug/entities/identity"
13
13
"github.com/git-bug/git-bug/entity"
14
+ "github.com/git-bug/git-bug/internal/test"
14
15
"github.com/git-bug/git-bug/query"
15
16
"github.com/git-bug/git-bug/repository"
16
17
)
17
18
18
19
func TestCache (t * testing.T ) {
19
- repo := repository .CreateGoGitTestRepo (t , false )
20
-
21
- indexCount := func (t * testing.T , name string ) uint64 {
22
- t .Helper ()
23
-
24
- idx , err := repo .GetIndex (name )
25
- require .NoError (t , err )
26
- count , err := idx .DocCount ()
27
- require .NoError (t , err )
28
-
29
- return count
30
- }
20
+ f := test .NewFlaky (t , & test.FlakyOptions {
21
+ MaxAttempts : 5 ,
22
+ })
31
23
32
- cache , err := NewRepoCacheNoEvents (repo )
33
- require .NoError (t , err )
24
+ f .Run (func (t testing.TB ) {
25
+ repo := repository .CreateGoGitTestRepo (t , false )
26
+ indexCount := func (t testing.TB , name string ) uint64 {
27
+ t .Helper ()
34
28
35
- // Create, set and get user identity
36
- iden1 ,
err := cache .
Identities ().
New (
"René Descartes" ,
"[email protected] " )
37
- require .NoError (t , err )
38
- err = cache .SetUserIdentity (iden1 )
39
- require .NoError (t , err )
40
- userIden , err := cache .GetUserIdentity ()
41
- require .NoError (t , err )
42
- require .Equal (t , iden1 .Id (), userIden .Id ())
29
+ idx , err := repo .GetIndex (name )
30
+ require .NoError (t , err )
31
+ count , err := idx .DocCount ()
32
+ require .NoError (t , err )
43
33
44
- // it's possible to create two identical identities
45
- iden2 ,
err := cache .
Identities ().
New (
"René Descartes" ,
"[email protected] " )
46
- require .NoError (t , err )
34
+ return count
35
+ }
47
36
48
- // Two identical identities yield a different id
49
- require .NotEqual (t , iden1 . Id (), iden2 . Id () )
37
+ cache , err := NewRepoCacheNoEvents ( repo )
38
+ require .NoError (t , err )
50
39
51
- // There is now two identities in the cache
52
- require .Len (t , cache .Identities ().AllIds (), 2 )
53
- require .Len (t , cache .identities .excerpts , 2 )
54
- require .Len (t , cache .identities .cached , 2 )
55
- require .Equal (t , uint64 (2 ), indexCount (t , identity .Namespace ))
56
- require .Equal (t , uint64 (0 ), indexCount (t , bug .Namespace ))
40
+ // Create, set and get user identity
41
+ iden1 ,
err := cache .
Identities ().
New (
"René Descartes" ,
"[email protected] " )
42
+ require .NoError (t , err )
43
+ err = cache .SetUserIdentity (iden1 )
44
+ require .NoError (t , err )
45
+ userIden , err := cache .GetUserIdentity ()
46
+ require .NoError (t , err )
47
+ require .Equal (t , iden1 .Id (), userIden .Id ())
57
48
58
- // Create a bug
59
- bug1 , _ , err := cache .Bugs ().New ("title " , "message " )
60
- require .NoError (t , err )
49
+ // it's possible to create two identical identities
50
+ iden2 , err := cache .
Identities ().
New (
"René Descartes " ,
"[email protected] " )
51
+ require .NoError (t , err )
61
52
62
- // It's possible to create two identical bugs
63
- bug2 , _ , err := cache .Bugs ().New ("title" , "marker" )
64
- require .NoError (t , err )
53
+ // Two identical identities yield a different id
54
+ require .NotEqual (t , iden1 .Id (), iden2 .Id ())
65
55
66
- // two identical bugs yield a different id
67
- require .NotEqual (t , bug1 .Id (), bug2 .Id ())
56
+ // There is now two identities in the cache
57
+ require .Len (t , cache .Identities ().AllIds (), 2 )
58
+ require .Len (t , cache .identities .excerpts , 2 )
59
+ require .Len (t , cache .identities .cached , 2 )
60
+ require .Equal (t , uint64 (2 ), indexCount (t , identity .Namespace ))
61
+ require .Equal (t , uint64 (0 ), indexCount (t , bug .Namespace ))
68
62
69
- // There is now two bugs in the cache
70
- require .Len (t , cache .Bugs ().AllIds (), 2 )
71
- require .Len (t , cache .bugs .excerpts , 2 )
72
- require .Len (t , cache .bugs .cached , 2 )
73
- require .Equal (t , uint64 (2 ), indexCount (t , identity .Namespace ))
74
- require .Equal (t , uint64 (2 ), indexCount (t , bug .Namespace ))
63
+ // Create a bug
64
+ bug1 , _ , err := cache .Bugs ().New ("title" , "message" )
65
+ require .NoError (t , err )
75
66
76
- // Resolving
77
- _ , err = cache .Identities ().Resolve (iden1 .Id ())
78
- require .NoError (t , err )
79
- _ , err = cache .Identities ().ResolveExcerpt (iden1 .Id ())
80
- require .NoError (t , err )
81
- _ , err = cache .Identities ().ResolvePrefix (iden1 .Id ().String ()[:10 ])
82
- require .NoError (t , err )
67
+ // It's possible to create two identical bugs
68
+ bug2 , _ , err := cache .Bugs ().New ("title" , "marker" )
69
+ require .NoError (t , err )
83
70
84
- _ , err = cache .Bugs ().Resolve (bug1 .Id ())
85
- require .NoError (t , err )
86
- _ , err = cache .Bugs ().ResolveExcerpt (bug1 .Id ())
87
- require .NoError (t , err )
88
- _ , err = cache .Bugs ().ResolvePrefix (bug1 .Id ().String ()[:10 ])
89
- require .NoError (t , err )
71
+ // two identical bugs yield a different id
72
+ require .NotEqual (t , bug1 .Id (), bug2 .Id ())
90
73
91
- // Querying
92
- q , err := query . Parse ( "status:open author:descartes sort:edit-asc" )
93
- require .NoError (t , err )
94
- res , err := cache .Bugs (). Query ( q )
95
- require .NoError (t , err )
96
- require .Len (t , res , 2 )
74
+ // There is now two bugs in the cache
75
+ require . Len ( t , cache . Bugs (). AllIds (), 2 )
76
+ require .Len (t , cache . bugs . excerpts , 2 )
77
+ require . Len ( t , cache .bugs . cached , 2 )
78
+ require .Equal (t , uint64 ( 2 ), indexCount ( t , identity . Namespace ) )
79
+ require .Equal (t , uint64 ( 2 ), indexCount ( t , bug . Namespace ) )
97
80
98
- q , err = query .Parse ("status:open marker" ) // full-text search
99
- require .NoError (t , err )
100
- res , err = cache .Bugs ().Query (q )
101
- require .NoError (t , err )
102
- require .Len (t , res , 1 )
81
+ // Resolving
82
+ _ , err = cache .Identities ().Resolve (iden1 .Id ())
83
+ require .NoError (t , err )
84
+ _ , err = cache .Identities ().ResolveExcerpt (iden1 .Id ())
85
+ require .NoError (t , err )
86
+ _ , err = cache .Identities ().ResolvePrefix (iden1 .Id ().String ()[:10 ])
87
+ require .NoError (t , err )
103
88
104
- // Close
105
- require .NoError (t , cache . Close () )
106
- require . Empty ( t , cache .bugs . cached )
107
- require .Empty (t , cache . bugs . excerpts )
108
- require . Empty ( t , cache .identities . cached )
109
- require .Empty (t , cache . identities . excerpts )
89
+ _ , err = cache . Bugs (). Resolve ( bug1 . Id ())
90
+ require .NoError (t , err )
91
+ _ , err = cache .Bugs (). ResolveExcerpt ( bug1 . Id () )
92
+ require .NoError (t , err )
93
+ _ , err = cache .Bugs (). ResolvePrefix ( bug1 . Id (). String ()[: 10 ] )
94
+ require .NoError (t , err )
110
95
111
- // Reload, only excerpt are loaded, but as we need to load the identities used in the bugs
112
- // to check the signatures, we also load the identity used above
113
- cache , err = NewRepoCacheNoEvents (repo )
114
- require .NoError (t , err )
96
+ // Querying
97
+ q , err := query .Parse ("status:open author:descartes sort:edit-asc" )
98
+ require .NoError (t , err )
99
+ res , err := cache .Bugs ().Query (q )
100
+ require .NoError (t , err )
101
+ require .Len (t , res , 2 )
115
102
116
- require .Len (t , cache .bugs .cached , 0 )
117
- require .Len (t , cache .bugs .excerpts , 2 )
118
- require .Len (t , cache .identities .cached , 0 )
119
- require .Len (t , cache .identities .excerpts , 2 )
120
- require .Equal (t , uint64 (2 ), indexCount (t , identity .Namespace ))
121
- require .Equal (t , uint64 (2 ), indexCount (t , bug .Namespace ))
103
+ q , err = query .Parse ("status:open marker" ) // full-text search
104
+ require .NoError (t , err )
105
+ res , err = cache .Bugs ().Query (q )
106
+ require .NoError (t , err )
107
+ require .Len (t , res , 1 )
122
108
123
- // Resolving load from the disk
124
- _ , err = cache .Identities ().Resolve (iden1 .Id ())
125
- require .NoError (t , err )
126
- _ , err = cache .Identities ().ResolveExcerpt (iden1 .Id ())
127
- require .NoError (t , err )
128
- _ , err = cache .Identities ().ResolvePrefix (iden1 .Id ().String ()[:10 ])
129
- require .NoError (t , err )
109
+ // Close
110
+ require .NoError (t , cache .Close ())
111
+ require .Empty (t , cache .bugs .cached )
112
+ require .Empty (t , cache .bugs .excerpts )
113
+ require .Empty (t , cache .identities .cached )
114
+ require .Empty (t , cache .identities .excerpts )
115
+
116
+ // Reload, only excerpt are loaded, but as we need to load the identities used in the bugs
117
+ // to check the signatures, we also load the identity used above
118
+ cache , err = NewRepoCacheNoEvents (repo )
119
+ require .NoError (t , err )
130
120
131
- _ , err = cache .Bugs (). Resolve ( bug1 . Id () )
132
- require .NoError (t , err )
133
- _ , err = cache .Bugs (). ResolveExcerpt ( bug1 . Id () )
134
- require .NoError (t , err )
135
- _ , err = cache . Bugs (). ResolvePrefix ( bug1 . Id (). String ()[: 10 ] )
136
- require .NoError (t , err )
121
+ require . Len ( t , cache .bugs . cached , 0 )
122
+ require .Len (t , cache . bugs . excerpts , 2 )
123
+ require . Len ( t , cache .identities . cached , 0 )
124
+ require .Len (t , cache . identities . excerpts , 2 )
125
+ require . Equal ( t , uint64 ( 2 ), indexCount ( t , identity . Namespace ) )
126
+ require .Equal (t , uint64 ( 2 ), indexCount ( t , bug . Namespace ) )
137
127
138
- require .Len (t , cache .bugs .cached , 1 )
139
- require .Len (t , cache .bugs .excerpts , 2 )
140
- require .Len (t , cache .identities .cached , 1 )
141
- require .Len (t , cache .identities .excerpts , 2 )
142
- require .Equal (t , uint64 (2 ), indexCount (t , identity .Namespace ))
143
- require .Equal (t , uint64 (2 ), indexCount (t , bug .Namespace ))
128
+ // Resolving load from the disk
129
+ _ , err = cache .Identities ().Resolve (iden1 .Id ())
130
+ require .NoError (t , err )
131
+ _ , err = cache .Identities ().ResolveExcerpt (iden1 .Id ())
132
+ require .NoError (t , err )
133
+ _ , err = cache .Identities ().ResolvePrefix (iden1 .Id ().String ()[:10 ])
134
+ require .NoError (t , err )
144
135
145
- // Remove + RemoveAll
146
- err = cache .Identities ().Remove (iden1 .Id ().String ()[:10 ])
147
- require .NoError (t , err )
148
- err = cache .Bugs ().Remove (bug1 .Id ().String ()[:10 ])
149
- require .NoError (t , err )
150
- require .Len (t , cache .bugs .cached , 0 )
151
- require .Len (t , cache .bugs .excerpts , 1 )
152
- require .Len (t , cache .identities .cached , 0 )
153
- require .Len (t , cache .identities .excerpts , 1 )
154
- require .Equal (t , uint64 (1 ), indexCount (t , identity .Namespace ))
155
- require .Equal (t , uint64 (1 ), indexCount (t , bug .Namespace ))
136
+ _ , err = cache .Bugs ().Resolve (bug1 .Id ())
137
+ require .NoError (t , err )
138
+ _ , err = cache .Bugs ().ResolveExcerpt (bug1 .Id ())
139
+ require .NoError (t , err )
140
+ _ , err = cache .Bugs ().ResolvePrefix (bug1 .Id ().String ()[:10 ])
141
+ require .NoError (t , err )
156
142
157
- _ ,
err = cache .
Identities ().
New (
"René Descartes" ,
"[email protected] " )
158
- require .NoError (t , err )
159
- _ , _ , err = cache .Bugs ().NewRaw (iden2 , time .Now ().Unix (), "title" , "message" , nil , nil )
160
- require .NoError (t , err )
143
+ require .Len (t , cache .bugs .cached , 1 )
144
+ require .Len (t , cache .bugs .excerpts , 2 )
145
+ require .Len (t , cache .identities .cached , 1 )
146
+ require .Len (t , cache .identities .excerpts , 2 )
147
+ require .Equal (t , uint64 (2 ), indexCount (t , identity .Namespace ))
148
+ require .Equal (t , uint64 (2 ), indexCount (t , bug .Namespace ))
161
149
162
- err = cache .RemoveAll ()
163
- require .NoError (t , err )
164
- require .Len (t , cache .bugs .cached , 0 )
165
- require .Len (t , cache .bugs .excerpts , 0 )
166
- require .Len (t , cache .identities .cached , 0 )
167
- require .Len (t , cache .identities .excerpts , 0 )
168
- require .Equal (t , uint64 (0 ), indexCount (t , identity .Namespace ))
169
- require .Equal (t , uint64 (0 ), indexCount (t , bug .Namespace ))
150
+ // Remove + RemoveAll
151
+ err = cache .Identities ().Remove (iden1 .Id ().String ()[:10 ])
152
+ require .NoError (t , err )
153
+ err = cache .Bugs ().Remove (bug1 .Id ().String ()[:10 ])
154
+ require .NoError (t , err )
155
+ require .Len (t , cache .bugs .cached , 0 )
156
+ require .Len (t , cache .bugs .excerpts , 1 )
157
+ require .Len (t , cache .identities .cached , 0 )
158
+ require .Len (t , cache .identities .excerpts , 1 )
159
+ require .Equal (t , uint64 (1 ), indexCount (t , identity .Namespace ))
160
+ require .Equal (t , uint64 (1 ), indexCount (t , bug .Namespace ))
161
+
162
+ _ ,
err = cache .
Identities ().
New (
"René Descartes" ,
"[email protected] " )
163
+ require .NoError (t , err )
164
+ _ , _ , err = cache .Bugs ().NewRaw (iden2 , time .Now ().Unix (), "title" , "message" , nil , nil )
165
+ require .NoError (t , err )
170
166
171
- // Close
172
- require .NoError (t , cache .Close ())
173
- require .Empty (t , cache .bugs .cached )
174
- require .Empty (t , cache .bugs .excerpts )
175
- require .Empty (t , cache .identities .cached )
176
- require .Empty (t , cache .identities .excerpts )
167
+ err = cache .RemoveAll ()
168
+ require .NoError (t , err )
169
+ require .Len (t , cache .bugs .cached , 0 )
170
+ require .Len (t , cache .bugs .excerpts , 0 )
171
+ require .Len (t , cache .identities .cached , 0 )
172
+ require .Len (t , cache .identities .excerpts , 0 )
173
+ require .Equal (t , uint64 (0 ), indexCount (t , identity .Namespace ))
174
+ require .Equal (t , uint64 (0 ), indexCount (t , bug .Namespace ))
175
+
176
+ // Close
177
+ require .NoError (t , cache .Close ())
178
+ require .Empty (t , cache .bugs .cached )
179
+ require .Empty (t , cache .bugs .excerpts )
180
+ require .Empty (t , cache .identities .cached )
181
+ require .Empty (t , cache .identities .excerpts )
182
+ })
177
183
}
178
184
179
185
func TestCachePushPull (t * testing.T ) {
0 commit comments