Skip to content

Commit 178a042

Browse files
author
Alexei Pastuchov
committed
insta assertion is wrapped into std::panic::catch_unwind
an alternative to previous thread based approach
1 parent 67feb90 commit 178a042

File tree

1 file changed

+11
-14
lines changed
  • wundergraph_cli/src/print_schema

1 file changed

+11
-14
lines changed

wundergraph_cli/src/print_schema/mod.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ mod tests {
324324
}
325325
}
326326

327-
fn request_test(client: &reqwest::Client, listen_url: &str, body: &'static str) -> Result<(), std::string::String> {
327+
fn request_test(
328+
client: &reqwest::Client,
329+
listen_url: &str,
330+
body: &'static str,
331+
) -> Result<(), std::string::String> {
328332
let r = client
329333
.post(&format!("http://{}/graphql", listen_url))
330334
.body(body)
@@ -333,21 +337,14 @@ mod tests {
333337
reqwest::header::HeaderValue::from_static("application/json"),
334338
)
335339
.send();
336-
337340
match r {
338-
Ok(mut r) => {
339-
let builder = std::thread::Builder::new().name("round_trip".into());
340-
let handler = builder
341-
.spawn(move || {
342-
insta::assert_json_snapshot!(r.json::<serde_json::Value>().unwrap())
343-
})
344-
.unwrap();
345-
346-
match handler.join() {
341+
Ok(mut r) => match r.json::<serde_json::Value>() {
342+
Ok(r) => match std::panic::catch_unwind(|| insta::assert_json_snapshot!(r)) {
343+
Ok(_) => Ok(()),
347344
Err(e) => Err(format!("{:?}", e)),
348-
_ => Ok(()),
349-
}
350-
}
345+
},
346+
Err(e) => Err(format!("{:?}", e)),
347+
},
351348
Err(e) => Err(format!("{:?}", e)),
352349
}
353350
}

0 commit comments

Comments
 (0)