-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration testing examples and documentation #2058
Comments
The following code will call struct TestTransaction;
impl CustomizeConnection<DbConnection, ::diesel::r2d2::Error> for TestTransaction {
fn on_acquire(
&self,
conn: &mut DbConnection,
) -> ::std::result::Result<(), ::diesel::r2d2::Error> {
conn.begin_test_transaction().unwrap();
Ok(())
}
}
let manager = ConnectionManager::<DbConnection>::new(db_url);
let pool = Pool::builder()
.connection_customizer(Box::new(TestTransaction))
.build(manager)
.expect("Failed to init pool") |
Thanks @weiznich, I've tried implementing what you've put above but I'm getting |
Just to add the solution also to this issue: |
I think a guide on testing would be very helpful. |
@Mastermindaxe I'm not sure about documentation, but I did implement it and have an example of the path I took here: https://github.com/WillSquire/Graphy/blob/master/api/src/db/mod.rs . Not worked on it for perhaps a year though. |
Closed as this seems to be a duplicate of #777 |
I've been reading through the examples and docs but I can't find material on integration testing? Found a bit of information here regarding
Connection::test_transaction
. Is there material on this?This is my code that contains the database connection pool:
For brevity the actual usage can be found here, which I might get away with passing a test connection if it exists.
Noticed the r2d2 feature uses
TestConnection
fromtest_helpers::*
. Is the the recommended way?The text was updated successfully, but these errors were encountered: