Skip to main content

test_override

Function test_override 

Source
pub fn test_override<'a>(headers: &'a HeaderMap, name: &str) -> Option<&'a str>
Expand description

The value of the request header x-ocre-test-<name> in debug builds (ocre dev, ocre test); always None in release builds.

How request tests point the app at a fake service without a setting: the test sends x-ocre-test-payments-api: http://127.0.0.1:41234 with its requests (ocre::testing::Client::header), and the code reads http::test_override(&headers, "payments-api") .unwrap_or(API_URL). Release builds (ocre deploy) never read the header, so a visitor cannot redirect the app’s calls.

§Examples

use axum::http::HeaderMap;

let mut headers = HeaderMap::new();
headers.insert("x-ocre-test-payments-api", "http://127.0.0.1:41234".parse().unwrap());
let base = ocre::http::test_override(&headers, "payments-api").unwrap_or("https://api.payments.example");
assert_eq!(base, if cfg!(debug_assertions) { "http://127.0.0.1:41234" } else { "https://api.payments.example" });