@@ -3,8 +3,6 @@ use graph::blockchain::BlockPtr;
3
3
use graph:: data:: subgraph:: schema:: { SubgraphError , SubgraphHealth } ;
4
4
use graph:: prelude:: { Schema , StopwatchMetrics , StoreError } ;
5
5
use lazy_static:: lazy_static;
6
- use mockall:: predicate:: * ;
7
- use mockall:: * ;
8
6
use slog:: Logger ;
9
7
use std:: collections:: BTreeMap ;
10
8
use std:: sync:: Arc ;
@@ -21,12 +19,13 @@ lazy_static! {
21
19
DeploymentLocator :: new( DeploymentId :: new( -12 ) , SUBGRAPH_ID . clone( ) ) ;
22
20
}
23
21
24
- mock ! {
25
- pub Store {
26
- fn get_many_mock<' a>(
27
- & self ,
28
- _ids_for_type: BTreeMap <& ' a EntityType , Vec <& ' a str >>,
29
- ) -> Result <BTreeMap <EntityType , Vec <Entity >>, StoreError >;
22
+ struct MockStore {
23
+ get_many_res : BTreeMap < EntityType , Vec < Entity > > ,
24
+ }
25
+
26
+ impl MockStore {
27
+ fn new ( get_many_res : BTreeMap < EntityType , Vec < Entity > > ) -> Self {
28
+ Self { get_many_res }
30
29
}
31
30
}
32
31
@@ -83,9 +82,9 @@ impl WritableStore for MockStore {
83
82
84
83
fn get_many (
85
84
& self ,
86
- ids_for_type : BTreeMap < & EntityType , Vec < & str > > ,
85
+ _ids_for_type : BTreeMap < & EntityType , Vec < & str > > ,
87
86
) -> Result < BTreeMap < EntityType , Vec < Entity > > , StoreError > {
88
- self . get_many_mock ( ids_for_type )
87
+ Ok ( self . get_many_res . clone ( ) )
89
88
}
90
89
91
90
async fn is_deployment_synced ( & self ) -> Result < bool , StoreError > {
@@ -131,21 +130,17 @@ fn sort_by_entity_key(mut mods: Vec<EntityModification>) -> Vec<EntityModificati
131
130
132
131
#[ tokio:: test]
133
132
async fn empty_cache_modifications ( ) {
134
- let store = Arc :: new ( MockStore :: new ( ) ) ;
133
+ let store = Arc :: new ( MockStore :: new ( BTreeMap :: new ( ) ) ) ;
135
134
let cache = EntityCache :: new ( store. clone ( ) ) ;
136
135
let result = cache. as_modifications ( ) ;
137
136
assert_eq ! ( result. unwrap( ) . modifications, vec![ ] ) ;
138
137
}
139
138
140
139
#[ test]
141
140
fn insert_modifications ( ) {
142
- let mut store = MockStore :: new ( ) ;
143
-
144
141
// Return no entities from the store, forcing the cache to treat any `set`
145
142
// operation as an insert.
146
- store
147
- . expect_get_many_mock ( )
148
- . returning ( |_| Ok ( BTreeMap :: new ( ) ) ) ;
143
+ let store = MockStore :: new ( BTreeMap :: new ( ) ) ;
149
144
150
145
let store = Arc :: new ( store) ;
151
146
let mut cache = EntityCache :: new ( store. clone ( ) ) ;
@@ -178,33 +173,34 @@ fn insert_modifications() {
178
173
) ;
179
174
}
180
175
176
+ fn entity_version_map (
177
+ entity_type : & str ,
178
+ entities : Vec < Entity > ,
179
+ ) -> BTreeMap < EntityType , Vec < Entity > > {
180
+ let mut map = BTreeMap :: new ( ) ;
181
+ map. insert ( EntityType :: from ( entity_type) , entities) ;
182
+ map
183
+ }
184
+
181
185
#[ test]
182
186
fn overwrite_modifications ( ) {
183
- let mut store = MockStore :: new ( ) ;
184
-
185
187
// Pre-populate the store with entities so that the cache treats
186
188
// every set operation as an overwrite.
187
- store. expect_get_many_mock ( ) . returning ( |_| {
188
- let mut map = BTreeMap :: new ( ) ;
189
-
190
- map. insert (
191
- EntityType :: from ( "Band" ) ,
192
- vec ! [
193
- make_band(
194
- "mogwai" ,
195
- vec![ ( "id" , "mogwai" . into( ) ) , ( "name" , "Mogwai" . into( ) ) ] ,
196
- )
197
- . 1 ,
198
- make_band(
199
- "sigurros" ,
200
- vec![ ( "id" , "sigurros" . into( ) ) , ( "name" , "Sigur Ros" . into( ) ) ] ,
201
- )
202
- . 1 ,
203
- ] ,
204
- ) ;
205
-
206
- Ok ( map)
207
- } ) ;
189
+ let store = {
190
+ let entities = vec ! [
191
+ make_band(
192
+ "mogwai" ,
193
+ vec![ ( "id" , "mogwai" . into( ) ) , ( "name" , "Mogwai" . into( ) ) ] ,
194
+ )
195
+ . 1 ,
196
+ make_band(
197
+ "sigurros" ,
198
+ vec![ ( "id" , "sigurros" . into( ) ) , ( "name" , "Sigur Ros" . into( ) ) ] ,
199
+ )
200
+ . 1 ,
201
+ ] ;
202
+ MockStore :: new ( entity_version_map ( "Band" , entities) )
203
+ } ;
208
204
209
205
let store = Arc :: new ( store) ;
210
206
let mut cache = EntityCache :: new ( store. clone ( ) ) ;
@@ -247,30 +243,23 @@ fn overwrite_modifications() {
247
243
248
244
#[ test]
249
245
fn consecutive_modifications ( ) {
250
- let mut store = MockStore :: new ( ) ;
251
-
252
246
// Pre-populate the store with data so that we can test setting a field to
253
247
// `Value::Null`.
254
- store. expect_get_many_mock ( ) . returning ( |_| {
255
- let mut map = BTreeMap :: new ( ) ;
256
-
257
- map. insert (
258
- EntityType :: from ( "Band" ) ,
259
- vec ! [
260
- make_band(
261
- "mogwai" ,
262
- vec![
263
- ( "id" , "mogwai" . into( ) ) ,
264
- ( "name" , "Mogwai" . into( ) ) ,
265
- ( "label" , "Chemikal Underground" . into( ) ) ,
266
- ] ,
267
- )
268
- . 1 ,
269
- ] ,
270
- ) ;
271
-
272
- Ok ( map)
273
- } ) ;
248
+ let store = {
249
+ let entities = vec ! [
250
+ make_band(
251
+ "mogwai" ,
252
+ vec![
253
+ ( "id" , "mogwai" . into( ) ) ,
254
+ ( "name" , "Mogwai" . into( ) ) ,
255
+ ( "label" , "Chemikal Underground" . into( ) ) ,
256
+ ] ,
257
+ )
258
+ . 1 ,
259
+ ] ;
260
+
261
+ MockStore :: new ( entity_version_map ( "Band" , entities) )
262
+ } ;
274
263
275
264
let store = Arc :: new ( store) ;
276
265
let mut cache = EntityCache :: new ( store. clone ( ) ) ;
0 commit comments