use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[allow(clippy::disallowed_types)]
#[derive(Debug, Clone, Deserialize)]
pub struct ServiceInitializeParams {
pub namespace: String,
#[serde(default)]
pub options: HashMap<String, serde_json::Value>,
pub port: Option<u16>,
}
#[allow(clippy::disallowed_types)]
#[derive(Debug, Clone, Serialize)]
pub struct ServiceInitializeResult {
pub port: u16,
pub installation: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceHealthStatus {
pub status: HealthStatus,
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum HealthStatus {
Healthy,
Degraded,
Unhealthy,
}
#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;
#[rstest]
fn when_params_deserialized_with_namespace_then_field_present() {
let json = r#"{"namespace": "chome-dorey-6y7huf", "options": {}}"#;
let params: ServiceInitializeParams = serde_json::from_str(json).unwrap();
assert_eq!(params.namespace, "chome-dorey-6y7huf");
}
#[rstest]
fn when_params_deserialized_with_all_fields_then_all_present() {
let json = r#"{"namespace": "my-app", "options": {"key": "val"}, "port": 8080}"#;
let params: ServiceInitializeParams = serde_json::from_str(json).unwrap();
assert_eq!(params.namespace, "my-app");
assert_eq!(params.port, Some(8080));
assert!(params.options.contains_key("key"));
}
}