feat(agent): config struct avec valeurs par défaut MQTT + tests
TDD : 3 tests d'intégration écrits en premier (config_test.rs), puis implémentation MqttConfig avec default_mqtt_host/port/topic_base pour garantir des valeurs par défaut même si la section [protocols.mqtt] est minimale dans le TOML. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+34
-8
@@ -1,4 +1,3 @@
|
||||
// stub — implémenté dans la Task 2
|
||||
use serde::Deserialize;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -30,24 +29,51 @@ pub struct UdpConfig {
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Default)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct MqttConfig {
|
||||
#[serde(default)]
|
||||
pub enabled: bool,
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_mqtt_host")]
|
||||
pub host: String,
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_mqtt_port")]
|
||||
pub port: u16,
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_topic_base")]
|
||||
pub topic_base: String,
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_true")]
|
||||
pub auto_discovery: bool,
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_true")]
|
||||
pub birth_message: bool,
|
||||
#[serde(default)]
|
||||
#[serde(default = "default_true")]
|
||||
pub last_will: bool,
|
||||
}
|
||||
|
||||
impl Default for MqttConfig {
|
||||
fn default() -> Self {
|
||||
MqttConfig {
|
||||
enabled: false,
|
||||
host: default_mqtt_host(),
|
||||
port: default_mqtt_port(),
|
||||
topic_base: default_topic_base(),
|
||||
auto_discovery: true,
|
||||
birth_message: true,
|
||||
last_will: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_mqtt_host() -> String {
|
||||
"10.0.0.3".to_string()
|
||||
}
|
||||
fn default_mqtt_port() -> u16 {
|
||||
1883
|
||||
}
|
||||
fn default_topic_base() -> String {
|
||||
"nanometrics/agents".to_string()
|
||||
}
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Default)]
|
||||
pub struct MetricsConfig {
|
||||
#[serde(default)]
|
||||
|
||||
Reference in New Issue
Block a user