Skip to content
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

Proposed functionality for testing #28

Open
kingledion opened this issue Dec 29, 2022 · 1 comment
Open

Proposed functionality for testing #28

kingledion opened this issue Dec 29, 2022 · 1 comment

Comments

@kingledion
Copy link
Contributor

kingledion commented Dec 29, 2022

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.

@mibes
Copy link
Owner

mibes commented Jan 6, 2023

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! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants