datadog_agent_config/
schema_defaults.rs

1use std::sync::LazyLock;
2
3use crate::DatadogConfiguration;
4
5static SCHEMA_DEFAULTS: LazyLock<DatadogConfiguration> = LazyLock::new(DatadogConfiguration::default);
6
7impl DatadogConfiguration {
8    /// Returns a shared configuration populated with the vendored schema's defaults.
9    ///
10    /// The configuration is initialized on first use.
11    pub fn schema_defaults() -> &'static Self {
12        &SCHEMA_DEFAULTS
13    }
14}
15
16#[cfg(test)]
17mod tests {
18    use super::DatadogConfiguration;
19
20    #[test]
21    fn the_defaults_match_an_empty_configuration() {
22        let deserialized: DatadogConfiguration =
23            serde_json::from_value(serde_json::json!({})).expect("an empty object deserializes");
24
25        assert_eq!(
26            serde_json::to_value(&deserialized).expect("the deserialized configuration serializes"),
27            serde_json::to_value(DatadogConfiguration::schema_defaults()).expect("the shared defaults serialize")
28        );
29    }
30
31    #[test]
32    fn the_defaults_are_built_once() {
33        assert!(std::ptr::eq(
34            DatadogConfiguration::schema_defaults(),
35            DatadogConfiguration::schema_defaults()
36        ));
37    }
38}