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

Overrides config with value for the current test only.

Other tests do not see the override, and it is discarded when the test ends. value is validated against the config schema and decoded into T immediately.

Pass either a value of type T (if it derives Serialize) or an equivalent JSON value. Secret fields and fields that serialize to null (such as Option::None) are omitted so secrets continue to resolve normally.

Not supported in system tests (where services read their own values); set test config values in the service’s 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);