I'm currently trying to test an API endpoint using actix-web and reqwest.
I can insert some records (using sqlx), and then make the request and check it returned a 200 HTTP status, and corroborate that the returned data belongs to the user created - the endpoint returned what's expected. But, doing so it's "order dependent", otherwise I receive the following error:
borrow of moved value:
response
value borrowed here after move rustc(E0382)
This is what gives the error:
let inserted_user = sqlx::query!(
r#"
INSERT INTO users (name)
VALUES ($1)
RETURNING id
"#,
String::from("john"),
)
.fetch_one(&app.db_pool)
.await
.unwrap();
let response = client
.get(&format!("{}/", &app.address))
.send()
.await?;
let users: Vec<User> = response.json().await?;
assert_eq!(inserted_user.id, users[0].id);
assert!(response.status().is_success());
If I swap the order of the assertion on response.status()
, with the assert_eq!
it works. But I think isn't the best way, as it should be explicitly stated, with comments or further knowledge that this work in this specific way.
Is there I can do to avoid relying on the order of the assertions if I can't clone a reqwest response? Or how could I clone it?