couch-rs icon indicating copy to clipboard operation
couch-rs copied to clipboard

Proposed functionality for testing

Open kingledion opened this issue 2 years ago • 1 comments

I made a crate to help test couch_rs.

Docs: https://docs.rs/couch_rs_test/0.2.0/couch_rs_test/ GitHub: https://github.com/kingledion/couch_rs_test

The way it works is this. You send the same arguments to the TestRepo::new method that you would to set up a couch_rs Client and Database. TestRepo will create a database with the same name as your database except appending a random string; dbname-ab13958cf or something like that. It also implements Drop to ensure that the database is destroyed in your CouchDB instance when TestRepo is de-allocated. This way, you can create multiple test databases instances in parallel to prevent collisions during testing, and clean them all up for parallel integration testing.

Not sure if you are interested in incorporating this into the repository here, the way couch_rs_derive is or not. If so, I'd be happy to open a PR and merge it in.

kingledion avatar Dec 29 '22 17:12 kingledion

Might be worthwhile to integrate this with the database_tests in couch_rs/lib.rs.

Currently this uses a sequence of let (client, db, mut doc) = setup("should_update_a_document").await; ... teardown(client, "should_update_a_document").await;

Auto-cleanup upon dropping the TestRepo is a cleaner way of doing things. We could amend the setup function to return a TestRepo in stead of a db. This would also give users a few ideas on how to use the crate.

The only concern I have is the std::thread::sleep(std::time::Duration::from_millis(100)); in the drop operation. We need to see if this has an effect on the test runner.

Give it a shot! 😄

mibes avatar Jan 06 '23 08:01 mibes