use cfgmatic_source::prelude::*;
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize, PartialEq)]
struct TestConfig {
name: String,
value: i32,
}
#[test]
fn test_composite_source_creation() {
let source = CompositeSource::new();
assert!(source.is_empty());
}
#[test]
fn test_composite_source_with_sources() {
let source1 = MemorySource::from_json(serde_json::json!({"name": "first", "value": 1}));
let source2 = MemorySource::from_json(serde_json::json!({"name": "second", "value": 2}));
let composite = CompositeSource::builder()
.add_with_priority(source1, SourcePriority::HIGH)
.add_with_priority(source2, SourcePriority::LOWEST)
.build();
assert_eq!(composite.len(), 2);
}
#[test]
fn test_composite_source_load_single_source() {
let memory = MemorySource::from_json(serde_json::json!({"name": "test", "value": 42}));
let composite = CompositeSource::builder()
.add_with_priority(memory, SourcePriority::HIGH)
.build();
let raw = composite.load_raw().expect("Failed to load");
let content = raw.as_str().expect("Failed to get string");
let config: TestConfig = Format::Json
.parse_as(content.as_ref())
.expect("Failed to parse");
assert_eq!(config.name, "test");
assert_eq!(config.value, 42);
}