athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! Shared `/debug/schema` service-result test helpers.
//!
//! These helpers centralize common service-result success and error-variant
//! assertions so module tests can focus on stage and handoff behavior.

use super::debug_contracts::LoggingSchemaDebugReport;
use super::debug_service_error::LoggingSchemaDebugReportError;
use super::debug_snapshot_error::LoggingSchemaSnapshotError;

/// Asserts a service-result payload is successful and preserves base report fields.
#[cfg(test)]
pub(crate) fn assert_successful_service_report_result_for_tests(
    result: Result<LoggingSchemaDebugReport, LoggingSchemaDebugReportError>,
    context: &str,
) {
    match result {
        Ok(report) => {
            assert_eq!(
                report.logging_client, "athena_logging",
                "unexpected {context} logging_client"
            );
            assert!(
                report.observed_tables.is_empty(),
                "expected {context} observed tables to be empty"
            );
        }
        Err(_) => panic!("expected successful service report result for {context}"),
    }
}

/// Asserts a service-result payload maps to the `FetchSnapshot(FetchColumns(_))` variant.
#[cfg(test)]
pub(crate) fn assert_fetch_snapshot_columns_service_error_for_tests(
    result: Result<LoggingSchemaDebugReport, LoggingSchemaDebugReportError>,
    expected_source_fragment: Option<&str>,
    context: &str,
) {
    match result {
        Err(LoggingSchemaDebugReportError::FetchSnapshot(
            LoggingSchemaSnapshotError::FetchColumns(source),
        )) => {
            if let Some(fragment) = expected_source_fragment {
                assert!(
                    source.to_string().contains(fragment),
                    "expected {context} columns source to contain '{fragment}': {source}"
                );
            }
        }
        _ => panic!("expected FetchSnapshot(FetchColumns) service error for {context}"),
    }
}

/// Asserts a service-result payload maps to the `FetchSnapshot(FetchRelations(_))` variant.
#[cfg(test)]
pub(crate) fn assert_fetch_snapshot_relations_service_error_for_tests(
    result: Result<LoggingSchemaDebugReport, LoggingSchemaDebugReportError>,
    expected_source_fragment: Option<&str>,
    context: &str,
) {
    match result {
        Err(LoggingSchemaDebugReportError::FetchSnapshot(
            LoggingSchemaSnapshotError::FetchRelations(source),
        )) => {
            if let Some(fragment) = expected_source_fragment {
                assert!(
                    source.to_string().contains(fragment),
                    "expected {context} relations source to contain '{fragment}': {source}"
                );
            }
        }
        _ => panic!("expected FetchSnapshot(FetchRelations) service error for {context}"),
    }
}