use super::NnsTopologyAssessmentStatus;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsTopologyGapsReport {
pub schema_version: u32,
pub network: String,
pub source_endpoint: String,
pub status: NnsTopologyAssessmentStatus,
pub gap_count: usize,
pub gaps: Vec<NnsTopologyGapRow>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NnsTopologyGapRow {
pub subject_kind: NnsTopologyGapSubjectKind,
pub subject: String,
pub missing_relation: NnsTopologyGapRelationKind,
pub referenced_id: String,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum NnsTopologyGapSubjectKind {
Node,
NodeOperator,
}
impl NnsTopologyGapSubjectKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Node => "node",
Self::NodeOperator => "node_operator",
}
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum NnsTopologyGapRelationKind {
NodeProvider,
NodeOperator,
DataCenter,
}
impl NnsTopologyGapRelationKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::NodeProvider => "node_provider",
Self::NodeOperator => "node_operator",
Self::DataCenter => "data_center",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn topology_gap_labels_round_trip() {
assert_labels(&[
(NnsTopologyGapSubjectKind::Node, "node"),
(NnsTopologyGapSubjectKind::NodeOperator, "node_operator"),
]);
assert_labels(&[
(NnsTopologyGapRelationKind::NodeProvider, "node_provider"),
(NnsTopologyGapRelationKind::NodeOperator, "node_operator"),
(NnsTopologyGapRelationKind::DataCenter, "data_center"),
]);
}
fn assert_labels<T>(cases: &[(T, &str)])
where
T: Copy + std::fmt::Debug + Eq + Serialize + serde::de::DeserializeOwned,
{
for &(value, label) in cases {
assert_eq!(
serde_json::to_string(&value).unwrap(),
format!("\"{label}\"")
);
assert_eq!(
serde_json::from_str::<T>(&format!("\"{label}\"")).unwrap(),
value
);
}
}
}