1use rskit_config::{AppConfig, ServiceConfig};
4use serde::Deserialize;
5use validator::{ValidationError, ValidationErrors};
6
7#[derive(Debug, Clone, Default, Deserialize)]
9pub struct TestAppConfig {
10 #[serde(default)]
12 pub service: ServiceConfig,
13}
14
15impl rskit_validation::Validate for TestAppConfig {
16 fn validate(&self) -> Result<(), ValidationErrors> {
17 let mut errors = ValidationErrors::new();
18 if let Err(error) = rskit_validation::Validate::validate(&self.service) {
19 let mut validation_error = ValidationError::new("invalid_service");
20 validation_error.message = Some(error.to_string().into());
21 errors.add("service", validation_error);
22 }
23 if errors.is_empty() {
24 Ok(())
25 } else {
26 Err(errors)
27 }
28 }
29}
30
31impl TestAppConfig {
32 #[must_use]
34 pub fn named(name: impl Into<String>) -> Self {
35 let service = ServiceConfig {
36 name: name.into(),
37 ..ServiceConfig::default()
38 };
39 Self { service }
40 }
41}
42
43impl AppConfig for TestAppConfig {
44 fn apply_defaults(&mut self) {}
45
46 fn service_config(&self) -> &ServiceConfig {
47 &self.service
48 }
49}