use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
pub(crate) const DATABASE_CONNECTIONS_PATH: &str =
"/data/api/v1/resources/list/ignition/database-connection";
pub(crate) const OPC_CONNECTIONS_PATH: &str = "/data/api/v1/resources/list/ignition/opc-connection";
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GatewayConnection {
#[serde(default)]
pub name: String,
#[serde(default)]
pub enabled: bool,
#[serde(default)]
pub healthchecks: serde_json::Value,
#[serde(flatten)]
pub extra: BTreeMap<String, serde_json::Value>,
}
#[cfg(test)]
mod tests {
use super::GatewayConnection;
#[test]
fn gateway_connection_parses_with_passthrough_healthchecks() {
let connection: GatewayConnection = serde_json::from_value(serde_json::json!({
"name": "MyPostgres",
"enabled": true,
"healthchecks": {"jdbc": "FAIR"},
"collection": "database-connections",
"config": {"driver": "postgresql"}
}))
.expect("plausible resource item must parse");
assert_eq!(connection.name, "MyPostgres");
assert!(connection.enabled);
assert_eq!(
connection.healthchecks["jdbc"], "FAIR",
"healthchecks ride through UNINTERPRETED"
);
assert_eq!(
connection.extra.get("collection"),
Some(&serde_json::json!("database-connections")),
"resource keys round-trip"
);
let bare: GatewayConnection = serde_json::from_value(serde_json::json!({
"name": "Bare",
"enabled": false
}))
.expect("healthchecks may be absent — default Value::Null");
assert_eq!(bare.healthchecks, serde_json::Value::Null);
}
}