|
|
@@ -40,3 +40,44 @@ fn test_config_mikrotik_absent() {
|
|
|
let c: Config = toml::from_str("ssh_user = \"a\"\n").unwrap();
|
|
|
assert!(c.mikrotik.is_none());
|
|
|
}
|
|
|
+
|
|
|
+#[tokio::test]
|
|
|
+async fn test_merge_cluster_sources_merges_mikrotik() {
|
|
|
+ use super::Config;
|
|
|
+ let dir = std::env::temp_dir().join(format!("sm121-csrc-mk-{}", std::process::id()));
|
|
|
+ std::fs::create_dir_all(&dir).unwrap();
|
|
|
+ let src_path = dir.join("clusters-mk.toml");
|
|
|
+ std::fs::write(
|
|
|
+ &src_path,
|
|
|
+ r#"
|
|
|
+[[clusters]]
|
|
|
+name = "c1"
|
|
|
+nodes = [{ name = "n0", ssh_ip = "10.9.0.1", rank = 0 }]
|
|
|
+
|
|
|
+[home_assistant]
|
|
|
+url = "http://ha.lan:8123"
|
|
|
+token = "sufficiently-long-test-token"
|
|
|
+shutdown_delay_seconds = 30
|
|
|
+
|
|
|
+[mikrotik]
|
|
|
+[[mikrotik.devices]]
|
|
|
+name = "SW2-MUC"
|
|
|
+address = "192.168.88.39"
|
|
|
+username = "sm121"
|
|
|
+password = "secret"
|
|
|
+on_entity = "switch.sw6_mt"
|
|
|
+"#,
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
+ // Main config without [mikrotik] (the global-config case): the HA
|
|
|
+ // endpoint and the RouterOS devices must both arrive from the source,
|
|
|
+ // or the device name 404s as a raw HA entity on every probe tick.
|
|
|
+ let mut cfg: Config =
|
|
|
+ toml::from_str("ssh_user = \"a\"\ncluster_sources = [\"/nonexistent\"]\n").unwrap();
|
|
|
+ cfg.cluster_sources = vec![src_path.to_string_lossy().into_owned()];
|
|
|
+ super::merge_cluster_sources(&mut cfg).await.unwrap();
|
|
|
+ assert!(cfg.home_assistant.is_some(), "HA merged from source");
|
|
|
+ let mk = cfg.mikrotik.as_ref().expect("mikrotik merged from source");
|
|
|
+ assert_eq!(mk.devices[0].name, "SW2-MUC");
|
|
|
+ assert_eq!(mk.devices[0].on_entity.as_deref(), Some("switch.sw6_mt"));
|
|
|
+}
|