Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8fdd1f

Browse files
committed
core/tests: Test subgraph_list
1 parent cf5f3a3 commit f8fdd1f

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

core/tests/tests.rs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,34 @@ fn subgraph_provider_events() {
180180
let subgraph1_id = subgraph1_link.trim_left_matches("/ipfs/");
181181
let subgraph2_id = subgraph2_link.trim_left_matches("/ipfs/");
182182

183-
// Add "subgraph1"
183+
// Deploy
184184
runtime
185185
.block_on(SubgraphProvider::deploy(
186186
&provider,
187187
"subgraph".to_owned(),
188188
subgraph1_link.clone(),
189189
)).unwrap();
190190

191-
// Update "subgraph1"
191+
// Update
192192
runtime
193193
.block_on(SubgraphProvider::deploy(
194194
&provider,
195195
"subgraph".to_owned(),
196196
subgraph2_link.clone(),
197197
)).unwrap();
198198

199-
// Remove "subgraph1"
199+
// Remove
200200
runtime
201201
.block_on(provider.remove("subgraph".to_owned()))
202202
.unwrap();
203203

204+
// Removing a subgraph that is not deployed is an error.
205+
assert!(
206+
runtime
207+
.block_on(provider.remove("subgraph".to_owned()))
208+
.is_err()
209+
);
210+
204211
// Finish the event streams.
205212
drop(provider);
206213

@@ -243,3 +250,51 @@ fn subgraph_provider_events() {
243250
SchemaEvent::SchemaRemoved("subgraph".to_owned(), subgraph2_id.to_owned())
244251
);
245252
}
253+
254+
#[test]
255+
fn subgraph_list() {
256+
let mut runtime = tokio::runtime::Runtime::new().unwrap();
257+
let logger = Logger::root(slog::Discard, o!());
258+
let provider = Arc::new(graph_core::SubgraphProvider::new(
259+
logger,
260+
Arc::new(IpfsClient::default()),
261+
));
262+
263+
let (subgraph1_link, subgraph2_link) = runtime
264+
.block_on(future::lazy(|| {
265+
let resolver = Arc::new(IpfsClient::default());
266+
add_subgraph_to_ipfs(resolver.clone(), "two-datasources")
267+
.join(add_subgraph_to_ipfs(resolver, "dummy"))
268+
})).unwrap();
269+
let subgraph1_id = subgraph1_link.trim_left_matches("/ipfs/").to_owned();
270+
let subgraph2_id = subgraph2_link.trim_left_matches("/ipfs/").to_owned();
271+
272+
assert!(provider.list().is_empty());
273+
runtime
274+
.block_on(SubgraphProvider::deploy(
275+
&provider,
276+
"subgraph1".to_owned(),
277+
subgraph1_link.clone(),
278+
)).unwrap();
279+
runtime
280+
.block_on(SubgraphProvider::deploy(
281+
&provider,
282+
"subgraph2".to_owned(),
283+
subgraph2_link.clone(),
284+
)).unwrap();
285+
assert_eq!(
286+
provider.list(),
287+
[
288+
("subgraph1".to_owned(), subgraph1_id),
289+
("subgraph2".to_owned(), subgraph2_id.clone())
290+
]
291+
);
292+
runtime
293+
.block_on(provider.remove("subgraph1".to_owned()))
294+
.unwrap();
295+
assert_eq!(provider.list(), [("subgraph2".to_owned(), subgraph2_id)]);
296+
runtime
297+
.block_on(provider.remove("subgraph2".to_owned()))
298+
.unwrap();
299+
assert!(provider.list().is_empty());
300+
}

0 commit comments

Comments
 (0)