-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathmock.rs
More file actions
293 lines (245 loc) · 7 KB
/
mock.rs
File metadata and controls
293 lines (245 loc) · 7 KB
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
//! Mock db implementation with methods stubbed to return default values.
#![allow(clippy::new_without_default)]
use async_trait::async_trait;
use syncserver_db_common::GetPoolStatus;
#[cfg(debug_assertions)]
use syncstorage_db_common::util::SyncTimestamp;
use syncstorage_db_common::{BatchDb, Db, DbPool, params, results};
use crate::DbError;
#[derive(Clone, Debug)]
pub struct MockDbPool;
impl MockDbPool {
pub fn new() -> Self {
MockDbPool
}
}
#[async_trait]
impl DbPool for MockDbPool {
type Error = DbError;
async fn get(&self) -> Result<Box<dyn Db<Error = DbError>>, Self::Error> {
Ok(Box::new(MockDb::new()))
}
fn validate_batch_id(&self, _: params::ValidateBatchId) -> Result<(), DbError> {
Ok(())
}
fn box_clone(&self) -> Box<dyn DbPool<Error = DbError>> {
Box::new(self.clone())
}
}
impl GetPoolStatus for MockDbPool {
fn status(&self) -> deadpool::Status {
deadpool::Status {
max_size: 0,
size: 0,
available: 0,
waiting: 0,
}
}
}
#[derive(Clone, Debug)]
pub struct MockDb;
impl MockDb {
pub fn new() -> Self {
MockDb
}
}
#[async_trait(?Send)]
impl Db for MockDb {
async fn commit(&mut self) -> Result<(), Self::Error> {
Ok(())
}
async fn rollback(&mut self) -> Result<(), Self::Error> {
Ok(())
}
async fn begin(&mut self, _for_write: bool) -> Result<(), Self::Error> {
Ok(())
}
async fn check(&mut self) -> Result<results::Check, Self::Error> {
Ok(true)
}
async fn lock_for_read(
&mut self,
_params: params::LockCollection,
) -> Result<results::LockCollection, Self::Error> {
Ok(())
}
async fn lock_for_write(
&mut self,
_params: params::LockCollection,
) -> Result<results::LockCollection, Self::Error> {
Ok(())
}
async fn get_collection_timestamps(
&mut self,
_params: params::GetCollectionTimestamps,
) -> Result<results::GetCollectionTimestamps, Self::Error> {
Ok(Default::default())
}
async fn get_collection_timestamp(
&mut self,
_params: params::GetCollectionTimestamp,
) -> Result<results::GetCollectionTimestamp, Self::Error> {
Ok(Default::default())
}
async fn get_collection_counts(
&mut self,
_params: params::GetCollectionCounts,
) -> Result<results::GetCollectionCounts, Self::Error> {
Ok(Default::default())
}
async fn get_collection_usage(
&mut self,
_params: params::GetCollectionUsage,
) -> Result<results::GetCollectionUsage, Self::Error> {
Ok(Default::default())
}
async fn get_storage_timestamp(
&mut self,
_params: params::GetStorageTimestamp,
) -> Result<results::GetStorageTimestamp, Self::Error> {
Ok(Default::default())
}
async fn get_storage_usage(
&mut self,
_params: params::GetStorageUsage,
) -> Result<results::GetStorageUsage, Self::Error> {
Ok(Default::default())
}
async fn get_quota_usage(
&mut self,
_params: params::GetQuotaUsage,
) -> Result<results::GetQuotaUsage, Self::Error> {
Ok(Default::default())
}
async fn delete_storage(
&mut self,
_params: params::DeleteStorage,
) -> Result<results::DeleteStorage, Self::Error> {
Ok(())
}
async fn delete_collection(
&mut self,
_params: params::DeleteCollection,
) -> Result<results::DeleteCollection, Self::Error> {
Ok(Default::default())
}
async fn delete_bsos(
&mut self,
_params: params::DeleteBsos,
) -> Result<results::DeleteBsos, Self::Error> {
Ok(Default::default())
}
async fn get_bsos(
&mut self,
_params: params::GetBsos,
) -> Result<results::GetBsos, Self::Error> {
Ok(Default::default())
}
async fn get_bso_ids(
&mut self,
_params: params::GetBsoIds,
) -> Result<results::GetBsoIds, Self::Error> {
Ok(Default::default())
}
async fn post_bsos(
&mut self,
_params: params::PostBsos,
) -> Result<results::PostBsos, Self::Error> {
Ok(Default::default())
}
async fn delete_bso(
&mut self,
_params: params::DeleteBso,
) -> Result<results::DeleteBso, Self::Error> {
Ok(Default::default())
}
async fn get_bso(
&mut self,
_params: params::GetBso,
) -> Result<Option<results::GetBso>, Self::Error> {
Ok(Default::default())
}
async fn get_bso_timestamp(
&mut self,
_params: params::GetBsoTimestamp,
) -> Result<results::GetBsoTimestamp, Self::Error> {
Ok(Default::default())
}
async fn put_bso(&mut self, _params: params::PutBso) -> Result<results::PutBso, Self::Error> {
Ok(Default::default())
}
fn get_connection_info(&self) -> results::ConnectionInfo {
Default::default()
}
async fn get_collection_id(
&mut self,
_params: &str,
) -> Result<results::GetCollectionId, Self::Error> {
Ok(Default::default())
}
#[cfg(debug_assertions)]
async fn create_collection(
&mut self,
_params: &str,
) -> Result<results::CreateCollection, Self::Error> {
Ok(Default::default())
}
async fn update_collection(
&mut self,
_params: params::UpdateCollection,
) -> Result<results::UpdateCollection, Self::Error> {
Ok(Default::default())
}
#[cfg(debug_assertions)]
fn timestamp(&self) -> SyncTimestamp {
Default::default()
}
#[cfg(debug_assertions)]
fn set_timestamp(&mut self, _: SyncTimestamp) {}
#[cfg(debug_assertions)]
async fn clear_coll_cache(&mut self) -> Result<(), Self::Error> {
Ok(())
}
#[cfg(debug_assertions)]
fn set_quota(&mut self, _: bool, _: usize, _: bool) {}
}
#[async_trait(?Send)]
impl BatchDb for MockDb {
type Error = DbError;
async fn create_batch(
&mut self,
_params: params::CreateBatch,
) -> Result<results::CreateBatch, Self::Error> {
Ok(Default::default())
}
async fn validate_batch(
&mut self,
_params: params::ValidateBatch,
) -> Result<results::ValidateBatch, Self::Error> {
Ok(Default::default())
}
async fn append_to_batch(
&mut self,
_params: params::AppendToBatch,
) -> Result<results::AppendToBatch, Self::Error> {
Ok(())
}
async fn get_batch(
&mut self,
_params: params::GetBatch,
) -> Result<Option<results::GetBatch>, Self::Error> {
Ok(Default::default())
}
async fn commit_batch(
&mut self,
_params: params::CommitBatch,
) -> Result<results::CommitBatch, Self::Error> {
Ok(Default::default())
}
async fn delete_batch(
&mut self,
_params: params::DeleteBatch,
) -> Result<results::DeleteBatch, Self::Error> {
Ok(())
}
}