How to pass different configuration to each test? #2856
-
As I would like each test to be independent from the other tests each one need its own configuration. (e.g. a different database or a different temporary folder). One way to pass this information is by setting environment variables - but those are per process and thus I had to set the test to run in a single thread. How can I pass some parameter to each test? The simplified version of the main file looks like this:
The pseudo version of the test looks like this
The real code is in this repository in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Using #[test]
fn test_simple() {
let rocket = rocket().configure(provider);
let client = Client::tracked(rocket);
}
use rocket::figment::providers::{Toml, Format, Env};
let provider = Toml::file("some_file.toml").nested(); Maybe you just want to set one parameter, though. In which case, maybe you do something like: use rocket::config::Config;
let provider = Config::figment()
.merge(("databases.foo.url", "some_value")); |
Beta Was this translation helpful? Give feedback.
Using
Rocket::configure()
:provider
here is any configuration source. If you want it to be a TOML file, then:Maybe you just want to set one parameter, though. In which case, maybe you do something like: