EDIT: by diesel, I am referring to https://github.com/diesel-rs/diesel
EDIT: also provide concrete details, not general/vague advice – i.e. I’m looking for people who have actually unit tested diesel code
With most of my Rust code, it’s easy to unit test. I try to make the function a pure function or modify limited state, then I can
- setup a few local vars
- run the function
- assert conditions on results
With diesel, a lot of the important code is of the form “it modified the global database in this way.” The problem I have with unit testing this is that there is often one global database, defined as DATABASE_URL in
.env , and all the schemas / macros that diesel auto generates ends up being linked directly to this database.
This makes it difficult to do step 1 of unit testing – I can’t just “create a few local vars” – there’s one global datbase, and everything references this global database.
Given this, how do I unit test diesel code?