Rocket/core/codegen/tests/route-ranking.rs
Sergio Benitez 1fb061496d Revamp configuration.
This commit completely overhauls Rocket's configuration systems, basing
it on the new Figment library. It includes many breaking changes
pertaining to configuration. They are:

  * "Environments" are replaced by "profiles".
  * 'ROCKET_PROFILE' takes the place of 'ROCKET_ENV'.
  * Profile names are now arbitrary, but 'debug' and 'release' are given
    special treatment as default profiles for the debug and release
    compilation profiles.
  * A 'default' profile now sits along-side the meta 'global' profile.
  * The concept of "extras" is no longer present; users can extract any
    values they want from the configured 'Figment'.
  * The 'Poolable' trait takes an '&Config'.
  * The 'secrets' feature is disabled by default.
  * It is a hard error if 'secrets' is enabled under the 'release'
    profile and no 'secret_key' is configured.
  * 'ConfigBuilder' no longer exists: all fields of 'Config' are public
    with public constructors for each type.
  * 'keep_alive' is disabled with '0', not 'false' or 'off'.
  * Inlined error variants into the 'Error' structure.
  * 'LoggingLevel' is now 'LogLevel'.
  * Limits can now be specified in SI units: "1 MiB".

The summary of other changes are:

  * The default config file can be configured with 'ROCKET_CONFIG'.
  * HTTP/1 and HTTP/2 keep-alive configuration is restored.
  * 'ctrlc' is now a recognized config option.
  * 'serde' is now a core dependency.
  * TLS misconfiguration errors are improved.
  * Several example use '_' as the return type of '#[launch]' fns.
  * 'AdHoc::config()' was added for simple config extraction.
  * Added more documentation for using 'Limits'.
  * Launch information is no longer treated specially.
  * The configuration guide was rewritten.

Resolves #852.
Resolves #209.
Closes #1404.
Closes #652.
2020-10-20 19:21:56 -07:00

54 lines
1.5 KiB
Rust

#[macro_use] extern crate rocket;
use rocket::local::blocking::Client;
// Test that manual/auto ranking works as expected.
#[get("/<_number>")]
fn get0(_number: u8) -> &'static str { "0" }
#[get("/<_number>", rank = 1)]
fn get1(_number: u16) -> &'static str { "1" }
#[get("/<_number>", rank = 2)]
fn get2(_number: u32) -> &'static str { "2" }
#[get("/<_number>", rank = 3)]
fn get3(_number: u64) -> &'static str { "3" }
#[test]
fn test_ranking() {
let rocket = rocket::ignite().mount("/", routes![get0, get1, get2, get3]);
let client = Client::tracked(rocket).unwrap();
let response = client.get("/0").dispatch();
assert_eq!(response.into_string().unwrap(), "0");
let response = client.get(format!("/{}", 1 << 8)).dispatch();
assert_eq!(response.into_string().unwrap(), "1");
let response = client.get(format!("/{}", 1 << 16)).dispatch();
assert_eq!(response.into_string().unwrap(), "2");
let response = client.get(format!("/{}", 1u64 << 32)).dispatch();
assert_eq!(response.into_string().unwrap(), "3");
}
// Test a collision due to same auto rank.
#[get("/<_n>")]
fn get0b(_n: u8) { }
#[test]
fn test_rank_collision() {
use rocket::error::ErrorKind;
let rocket = rocket::ignite().mount("/", routes![get0, get0b]);
let client_result = Client::tracked(rocket);
match client_result.as_ref().map_err(|e| e.kind()) {
Err(ErrorKind::Collision(..)) => { /* o.k. */ },
Ok(_) => panic!("client succeeded unexpectedly"),
Err(e) => panic!("expected collision, got {}", e)
}
}