-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmocks.go
315 lines (257 loc) · 8.28 KB
/
mocks.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//go:build integration || unit || testworld
package documents
import (
"context"
"time"
coredocumentpb "github.com/centrifuge/centrifuge-protobufs/gen/go/coredocument"
p2ppb "github.com/centrifuge/centrifuge-protobufs/gen/go/p2p"
"github.com/centrifuge/go-centrifuge/errors"
"github.com/centrifuge/go-centrifuge/identity"
"github.com/centrifuge/go-centrifuge/storage"
"github.com/stretchr/testify/mock"
)
// GetTestCoreDocWithReset must only be used by tests for manipulations. It gets the embedded coredoc protobuf.
// All calls to this function will cause a regeneration of salts next time for precise-proof trees.
func (cd *CoreDocument) GetTestCoreDocWithReset() *coredocumentpb.CoreDocument {
cd.Modified = true
return &cd.Document
}
type MockModel struct {
Document
mock.Mock
}
func (m *MockModel) Scheme() string {
args := m.Called()
return args.String(0)
}
func (m *MockModel) GetData() interface{} {
args := m.Called()
return args.Get(0)
}
func (m *MockModel) PreviousVersion() []byte {
args := m.Called()
return args.Get(0).([]byte)
}
func (m *MockModel) CurrentVersion() []byte {
args := m.Called()
return args.Get(0).([]byte)
}
func (m *MockModel) CurrentVersionPreimage() []byte {
args := m.Called()
id, _ := args.Get(0).([]byte)
return id
}
func (m *MockModel) PackCoreDocument() (coredocumentpb.CoreDocument, error) {
args := m.Called()
dm, _ := args.Get(0).(coredocumentpb.CoreDocument)
return dm, args.Error(1)
}
func (m *MockModel) UnpackCoreDocument(cd coredocumentpb.CoreDocument) error {
args := m.Called(cd)
return args.Error(0)
}
func (m *MockModel) JSON() ([]byte, error) {
args := m.Called()
data, _ := args.Get(0).([]byte)
return data, args.Error(1)
}
func (m *MockModel) RemoveCollaborators(dids []identity.DID) error {
args := m.Called(dids)
return args.Error(0)
}
func (m *MockModel) AddRole(roleKey string, dids []identity.DID) (*coredocumentpb.Role, error) {
args := m.Called(roleKey, dids)
r, _ := args.Get(0).(*coredocumentpb.Role)
return r, args.Error(1)
}
func (m *MockModel) GetRole(roleID []byte) (*coredocumentpb.Role, error) {
args := m.Called(roleID)
r, _ := args.Get(0).(*coredocumentpb.Role)
return r, args.Error(1)
}
func (m *MockModel) UpdateRole(roleID []byte, dids []identity.DID) (*coredocumentpb.Role, error) {
args := m.Called(roleID, dids)
r, _ := args.Get(0).(*coredocumentpb.Role)
return r, args.Error(1)
}
func (m *MockModel) AddTransitionRuleForAttribute(roleID []byte, key AttrKey) (*coredocumentpb.TransitionRule, error) {
args := m.Called(roleID, key)
r, _ := args.Get(0).(*coredocumentpb.TransitionRule)
return r, args.Error(1)
}
func (m *MockModel) AddComputeFieldsRule(wasm []byte, fields []string, targetField string) (*coredocumentpb.TransitionRule, error) {
args := m.Called(wasm, fields, targetField)
r, _ := args.Get(0).(*coredocumentpb.TransitionRule)
return r, args.Error(1)
}
func (m *MockModel) GetTransitionRule(ruleID []byte) (*coredocumentpb.TransitionRule, error) {
args := m.Called(ruleID)
r, _ := args.Get(0).(*coredocumentpb.TransitionRule)
return r, args.Error(1)
}
func (m *MockModel) DeleteTransitionRule(ruleID []byte) error {
args := m.Called(ruleID)
return args.Error(0)
}
type MockService struct {
Service
mock.Mock
}
func (m *MockService) GetVersion(ctx context.Context, documentID []byte, version []byte) (Document, error) {
args := m.Called(documentID, version)
doc, _ := args.Get(0).(Document)
return doc, args.Error(1)
}
func (m *MockService) GetCurrentVersion(ctx context.Context, docID []byte) (Document, error) {
args := m.Called(ctx, docID)
doc, _ := args.Get(0).(Document)
return doc, args.Error(1)
}
func (m *MockService) Derive(ctx context.Context, payload UpdatePayload) (Document, error) {
args := m.Called(ctx, payload)
doc, _ := args.Get(0).(Document)
return doc, args.Error(1)
}
func (m *MockService) Validate(ctx context.Context, model Document, old Document) error {
args := m.Called(ctx, model, old)
return args.Error(0)
}
func (m *MockService) New(scheme string) (Document, error) {
args := m.Called(scheme)
doc, _ := args.Get(0).(Document)
return doc, args.Error(1)
}
func (m *MockModel) ID() []byte {
args := m.Called()
id, _ := args.Get(0).([]byte)
return id
}
func (m *MockModel) NFTs() []*coredocumentpb.NFT {
args := m.Called()
dr, _ := args.Get(0).([]*coredocumentpb.NFT)
return dr
}
func (m *MockModel) Author() (identity.DID, error) {
args := m.Called()
id, _ := args.Get(0).(identity.DID)
return id, args.Error(1)
}
func (m *MockModel) Timestamp() (time.Time, error) {
args := m.Called()
dr, _ := args.Get(0).(time.Time)
return dr, args.Error(1)
}
func (m *MockModel) GetCollaborators(filterIDs ...identity.DID) (CollaboratorsAccess, error) {
args := m.Called(filterIDs)
cas, _ := args.Get(0).(CollaboratorsAccess)
return cas, args.Error(1)
}
func (m *MockModel) GetAttributes() []Attribute {
args := m.Called()
attrs, _ := args.Get(0).([]Attribute)
return attrs
}
func (m *MockModel) IsDIDCollaborator(did identity.DID) (bool, error) {
args := m.Called(did)
ok, _ := args.Get(0).(bool)
return ok, args.Error(1)
}
func (m *MockModel) GetAccessTokens() ([]*coredocumentpb.AccessToken, error) {
args := m.Called()
ac, _ := args.Get(0).([]*coredocumentpb.AccessToken)
return ac, args.Error(1)
}
func (m *MockModel) AttributeExists(key AttrKey) bool {
args := m.Called(key)
return args.Bool(0)
}
func (m *MockModel) GetAttribute(key AttrKey) (Attribute, error) {
args := m.Called(key)
attr, _ := args.Get(0).(Attribute)
return attr, args.Error(1)
}
func (m *MockModel) AddAttributes(ca CollaboratorsAccess, prepareNewVersion bool, attrs ...Attribute) error {
args := m.Called(ca, prepareNewVersion, attrs)
return args.Error(0)
}
func (m *MockModel) DeleteAttribute(key AttrKey, prepareNewVersion bool) error {
args := m.Called(key, prepareNewVersion)
return args.Error(0)
}
func (m *MockModel) GetStatus() Status {
args := m.Called()
return args.Get(0).(Status)
}
func (m *MockModel) SetStatus(st Status) error {
args := m.Called(st)
return args.Error(0)
}
func (m *MockModel) Patch(payload UpdatePayload) error {
args := m.Called(payload)
return args.Error(0)
}
func (m *MockModel) DeriveFromCreatePayload(ctx context.Context, payload CreatePayload) error {
args := m.Called(ctx, payload)
return args.Error(0)
}
func (m *MockModel) DeriveFromClonePayload(ctx context.Context, d Document) error {
args := m.Called(ctx, d)
return args.Error(0)
}
func (m *MockModel) DeriveFromUpdatePayload(ctx context.Context, payload UpdatePayload) (Document, error) {
args := m.Called(ctx, payload)
doc, _ := args.Get(0).(Document)
return doc, args.Error(1)
}
type MockRepository struct {
mock.Mock
}
func (m *MockRepository) Exists(accountID, id []byte) bool {
args := m.Called(accountID, id)
return args.Get(0).(bool)
}
func (m *MockRepository) Get(accountID, id []byte) (Document, error) {
args := m.Called(accountID, id)
doc, _ := args.Get(0).(Document)
return doc, args.Error(0)
}
func (m *MockRepository) Create(accountID, id []byte, model Document) error {
args := m.Called(accountID, id)
return args.Error(0)
}
func (m *MockRepository) Update(accountID, id []byte, model Document) error {
args := m.Called(accountID, id)
return args.Error(0)
}
func (m *MockRepository) Register(model Document) {
m.Called(model)
}
func (m *MockRepository) GetLatest(accountID, docID []byte) (Document, error) {
args := m.Called(accountID, docID)
doc, _ := args.Get(0).(Document)
return doc, args.Error(1)
}
func (b Bootstrapper) TestBootstrap(context map[string]interface{}) error {
if _, ok := context[storage.BootstrappedDB]; !ok {
return errors.New("initializing LevelDB repository failed")
}
return b.Bootstrap(context)
}
func (Bootstrapper) TestTearDown() error {
return nil
}
func (b PostBootstrapper) TestBootstrap(ctx map[string]interface{}) error {
return b.Bootstrap(ctx)
}
func (PostBootstrapper) TestTearDown() error {
return nil
}
type MockRequestProcessor struct {
mock.Mock
}
func (m *MockRequestProcessor) RequestDocumentWithAccessToken(ctx context.Context, granterDID identity.DID, tokenIdentifier,
documentIdentifier, delegatingDocumentIdentifier []byte) (*p2ppb.GetDocumentResponse, error) {
args := m.Called(granterDID, tokenIdentifier, documentIdentifier, delegatingDocumentIdentifier)
resp, _ := args.Get(0).(*p2ppb.GetDocumentResponse)
return resp, args.Error(1)
}