use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResourceAnnotations {
#[serde(skip_serializing_if = "Option::is_none")]
pub audience: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub priority: Option<f64>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_empty_annotations_serialize() {
let ann = ResourceAnnotations {
audience: None,
priority: None,
};
let json = serde_json::to_value(&ann).unwrap();
assert!(json.get("audience").is_none());
assert!(json.get("priority").is_none());
}
#[test]
fn test_full_annotations_serialize() {
let ann = ResourceAnnotations {
audience: Some(vec!["user".to_string(), "assistant".to_string()]),
priority: Some(0.8),
};
let json = serde_json::to_value(&ann).unwrap();
assert_eq!(json["audience"], serde_json::json!(["user", "assistant"]));
assert_eq!(json["priority"], 0.8);
}
#[test]
fn test_deserialize() {
let json = serde_json::json!({"audience": ["user"], "priority": 0.5});
let ann: ResourceAnnotations = serde_json::from_value(json).unwrap();
assert_eq!(ann.audience.unwrap(), vec!["user"]);
assert_eq!(ann.priority.unwrap(), 0.5);
}
}