Skip to main content

set_config

Function set_config 

Source
pub fn set_config<T: ConfigType>(
    config: &Config<T>,
    value: impl Serialize,
) -> Result<(), Error>
Expand description

Gives config a value for the current test, in place of the app’s. No other test sees it, and it is gone when the test ends. The value is checked against the config’s schema, and read as its type, here.

The value is a value of the config’s type, which then derives Serialize as well as Deserialize, or its JSON form, as its files would hold it. A secret field is left out: it reads its secret as ever. So is a field that serializes as null, as an Option that is None does.

Not in a system test, whose services read their own values: give the config its value for tests in its test config file instead.

ⓘ
encore::testing::set_config(&CHECKOUT, &Checkout { max_items: 2, ..CHECKOUT.get().clone() })?;
encore::testing::set_config(&CHECKOUT, serde_json::json!({"max_items": 2}))?;
assert_eq!(CHECKOUT.get().max_items, 2);