athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! Service-result assembly for `/debug/schema` report loading.
//!
//! This module maps per-client report-loader results into service-layer report
//! results while staged payload assembly is delegated to
//! `debug_service_result_stage_input_assembly`,
//! `debug_service_result_stage_output_assembly` and final stage-output handoff
//! is delegated to the stable facade in
//! `debug_service_result_from_stage_output_assembly`, which delegates to
//! `debug_service_result_stage_output_handoff_assembly`.

use super::debug_contracts::LoggingSchemaDebugReport;
use super::debug_service_error::LoggingSchemaDebugReportError;
use super::debug_service_result_from_stage_output_assembly::build_logging_schema_debug_report_service_result_from_stage_output_assembly;
use super::debug_service_result_stage_input_assembly::build_debug_service_result_stage_input_assembly;
use super::debug_service_result_stage_input_contracts::LoggingSchemaDebugReportServiceResultStageInput;
use super::debug_service_result_stage_output_assembly::build_debug_service_result_stage_output_assembly;
use super::debug_snapshot_error::LoggingSchemaSnapshotError;

/// Builds service-layer report results from per-client report-loader results.
pub(super) fn build_logging_schema_debug_report_service_result(
    report_result: Result<LoggingSchemaDebugReport, LoggingSchemaSnapshotError>,
) -> Result<LoggingSchemaDebugReport, LoggingSchemaDebugReportError> {
    let stage_input: LoggingSchemaDebugReportServiceResultStageInput =
        build_debug_service_result_stage_input_assembly(report_result);
    let stage = build_debug_service_result_stage_output_assembly(stage_input);
    build_logging_schema_debug_report_service_result_from_stage_output_assembly(stage)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::debug_report_test_fixtures::build_empty_logging_schema_debug_report_for_tests;
    use crate::api::schema::debug_service_result_test_helpers::{
        assert_fetch_snapshot_relations_service_error_for_tests,
        assert_successful_service_report_result_for_tests,
    };

    /// Preserves successful report payloads in service-layer results.
    #[test]
    fn service_result_assembly_preserves_successful_report() {
        let report = build_empty_logging_schema_debug_report_for_tests();
        let result = build_logging_schema_debug_report_service_result(Ok(report));

        assert_successful_service_report_result_for_tests(result, "service result assembly");
    }

    /// Maps snapshot-fetch failures into service-layer fetch-snapshot errors.
    #[test]
    fn service_result_assembly_maps_snapshot_error_to_service_error() {
        let result = build_logging_schema_debug_report_service_result(Err(
            LoggingSchemaSnapshotError::FetchRelations(sqlx::Error::Protocol(
                "relation query failed".to_string(),
            )),
        ));

        assert_fetch_snapshot_relations_service_error_for_tests(
            result,
            None,
            "service result assembly",
        );
    }
}