#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(std::clone::Clone, std::fmt::Debug)]
pub struct RefreshRequest {
pub project: std::string::String,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(std::clone::Clone, std::fmt::Debug)]
pub struct RefreshResult {
pub status: std::string::String,
pub compiled: bool,
pub components_added: usize,
pub components_removed: usize,
pub error: std::option::Option<std::string::String>,
}
impl RefreshResult {
pub fn success(added: usize, removed: usize) -> Self {
Self {
status: std::string::String::from("success"),
compiled: true,
components_added: added,
components_removed: removed,
error: std::option::Option::None,
}
}
pub fn compilation_error(error_msg: std::string::String) -> Self {
Self {
status: std::string::String::from("error"),
compiled: false,
components_added: 0,
components_removed: 0,
error: std::option::Option::Some(error_msg),
}
}
pub fn restart_required() -> Self {
Self {
status: std::string::String::from("restart_required"),
compiled: true,
components_added: 0,
components_removed: 0,
error: std::option::Option::Some(std::string::String::from(
"Compilation successful. Server restart required to load new graph.",
)),
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_refresh_request_creation() {
let request = super::RefreshRequest {
project: std::string::String::from("test_project"),
};
std::assert_eq!(request.project, "test_project");
}
#[test]
fn test_refresh_result_success() {
let result = super::RefreshResult::success(3, 1);
std::assert_eq!(result.status, "success");
std::assert!(result.compiled);
std::assert_eq!(result.components_added, 3);
std::assert_eq!(result.components_removed, 1);
std::assert!(result.error.is_none());
}
#[test]
fn test_refresh_result_compilation_error() {
let result = super::RefreshResult::compilation_error(std::string::String::from("syntax error"));
std::assert_eq!(result.status, "error");
std::assert!(!result.compiled);
std::assert!(result.error.is_some());
}
#[test]
fn test_refresh_result_restart_required() {
let result = super::RefreshResult::restart_required();
std::assert_eq!(result.status, "restart_required");
std::assert!(result.compiled);
std::assert!(result.error.is_some());
}
}