Skip to content
\n

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
\n

The real code is in this repository in src/main.rs and src/test_simpl.rs

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Using Rocket::configure():

\n
#[test]\nfn test_simple() {\n    let rocket = rocket().configure(provider);\n    let client = Client::tracked(rocket);\n}
\n

provider here is any configuration source. If you want it to be a TOML file, then:

\n
use rocket::figment::providers::{Toml, Format, Env};\n\nlet provider = Toml::file(\"some_file.toml\").nested();
\n

Maybe you just want to set one parameter, though. In which case, maybe you do something like:

\n
use rocket::config::Config;\n\nlet provider = Config::figment()\n    .merge((\"databases.foo.url\", \"some_value\"));    
","upvoteCount":2,"url":"https://github.com/rwf2/Rocket/discussions/2856#discussioncomment-10478398"}}}

How to pass different configuration to each test? #2856

Discussion options

You must be logged in to vote

Using Rocket::configure():

#[test]
fn test_simple() {
    let rocket = rocket().configure(provider);
    let client = Client::tracked(rocket);
}

provider here is any configuration source. If you want it to be a TOML file, then:

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"));    

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@szabgab
Comment options

Answer selected by szabgab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants