The pseudo version of the test looks like this
\n#[test]\nfn test_simple() {\n let rocket_toml_path = some_temporary_place();\n let database_name = random_for_this_test();\n save_rocket_toml with database_name in rocket_toml_path;\n\n std::env::set_var(\"ROCKET_CONFIG\", rocket_toml_path);\n\n let client = Client::tracked(super::rocket()).unwrap();\n ...\n}\n
The real code is in this repository in src/main.rs
and src/test_simpl.rs
Using Rocket::configure()
:
#[test]\nfn test_simple() {\n let rocket = rocket().configure(provider);\n let client = Client::tracked(rocket);\n}
provider
here is any configuration source. If you want it to be a TOML file, then:
use rocket::figment::providers::{Toml, Format, Env};\n\nlet provider = Toml::file(\"some_file.toml\").nested();
Maybe you just want to set one parameter, though. In which case, maybe you do something like:
\nuse rocket::config::Config;\n\nlet provider = Config::figment()\n .merge((\"databases.foo.url\", \"some_value\"));
-
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.
-
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: