athena_rs 3.22.1

Hyper performant polyglot Database driver
Documentation
//! Final health-assessment payload assembly for `/debug/schema`.
//!
//! This module owns constructing `LoggingSchemaDebugHealthAssessment` from one
//! derived health label and already-built structured health reasons.

use super::debug_health_assessment_contracts::LoggingSchemaDebugHealthAssessment;
use super::debug_summary_contracts::LoggingSchemaDebugHealthReason;

/// Builds one composed health-assessment payload from health label and reasons.
pub(super) fn build_logging_schema_debug_health_assessment_output(
    health: &str,
    health_reasons: Vec<LoggingSchemaDebugHealthReason>,
) -> LoggingSchemaDebugHealthAssessment {
    LoggingSchemaDebugHealthAssessment {
        health: health.to_string(),
        health_reasons,
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::debug_health_stage_test_fixtures::build_health_reason_missing_required_tables_for_tests;

    #[test]
    /// Preserves provided health label and reason rows in composed payload output.
    fn health_assessment_output_preserves_health_and_reason_rows() {
        let reasons = vec![build_health_reason_missing_required_tables_for_tests(2)];

        let assessment = build_logging_schema_debug_health_assessment_output("degraded", reasons);

        assert_eq!(assessment.health, "degraded");
        assert_eq!(assessment.health_reasons.len(), 1);
        assert_eq!(assessment.health_reasons[0].code, "missing_required_tables");
        assert_eq!(assessment.health_reasons[0].severity, "error");
        assert_eq!(assessment.health_reasons[0].count, 2);
    }
}