athena_rs 3.26.1

Hyper performant polyglot Database driver
Documentation
//! Service-loader report-result assembly for `/debug/schema`.
//!
//! This module maps snapshot fetch results into report-loading service results
//! while delegating successful payload construction to
//! `debug_service_loader_output_assembly`.

use super::debug_contracts::LoggingSchemaDebugReport;
use super::debug_service_loader_output_assembly::build_logging_schema_debug_report_for_client_output;
use super::debug_service_loader_output_input_contracts::LoggingSchemaDebugReportForClientOutputInput;
use super::debug_service_loader_result_assembly_input_contracts::LoggingSchemaDebugReportForClientResultInput;
use super::debug_snapshot_error::LoggingSchemaSnapshotError;

/// Builds one service-loader report result from a client name and snapshot result.
pub(super) fn build_logging_schema_debug_report_for_client_result(
    input: LoggingSchemaDebugReportForClientResultInput,
) -> Result<LoggingSchemaDebugReport, LoggingSchemaSnapshotError> {
    let LoggingSchemaDebugReportForClientResultInput {
        logging_client_name,
        snapshot_result,
    } = input;

    snapshot_result.map(|snapshot| {
        build_logging_schema_debug_report_for_client_output(
            LoggingSchemaDebugReportForClientOutputInput {
                logging_client_name,
                snapshot,
            },
        )
    })
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::api::schema::debug_service_loader_test_helpers::assert_fetch_columns_snapshot_error_for_tests;
    use crate::api::schema::debug_service_loader_test_helpers::assert_successful_service_loader_report_result_for_tests;
    use crate::api::schema::debug_service_loader_test_helpers::build_empty_logging_schema_snapshot_for_tests;

    /// Maps successful snapshot results into diagnostics report payloads.
    #[test]
    fn service_loader_result_assembly_maps_snapshot_success_to_report() {
        let result = build_logging_schema_debug_report_for_client_result(
            LoggingSchemaDebugReportForClientResultInput {
                logging_client_name: "athena_logging".to_string(),
                snapshot_result: Ok(build_empty_logging_schema_snapshot_for_tests()),
            },
        );
        assert_successful_service_loader_report_result_for_tests(
            result,
            "service_loader_result_assembly_maps_snapshot_success_to_report",
        );
    }

    /// Preserves snapshot-fetch errors when assembling service-loader results.
    #[test]
    fn service_loader_result_assembly_preserves_snapshot_error() {
        let result = build_logging_schema_debug_report_for_client_result(
            LoggingSchemaDebugReportForClientResultInput {
                logging_client_name: "athena_logging".to_string(),
                snapshot_result: Err(LoggingSchemaSnapshotError::FetchColumns(
                    sqlx::Error::Protocol("fetch failure".to_string()),
                )),
            },
        );
        assert_fetch_columns_snapshot_error_for_tests(
            result,
            None,
            "service_loader_result_assembly_preserves_snapshot_error",
        );
    }
}