use super::debug_contracts::LoggingSchemaDebugReport;
use super::debug_service_loader_stage_contracts::LoggingSchemaDebugReportForClientStage;
use super::debug_snapshot_contracts::LoggingSchemaSnapshot;
use super::debug_snapshot_error::LoggingSchemaSnapshotError;
use super::debug_snapshot_error_assertions_test_helpers::{
assert_fetch_columns_snapshot_error_variant_for_tests,
assert_fetch_relations_snapshot_error_variant_for_tests,
};
#[cfg(test)]
pub(crate) fn build_empty_logging_schema_snapshot_for_tests() -> LoggingSchemaSnapshot {
LoggingSchemaSnapshot {
relations: Vec::new(),
columns: Vec::new(),
}
}
#[cfg(test)]
pub(crate) fn build_successful_service_loader_stage_for_tests()
-> LoggingSchemaDebugReportForClientStage {
LoggingSchemaDebugReportForClientStage {
logging_client_name: "athena_logging".to_string(),
snapshot_result: Ok(build_empty_logging_schema_snapshot_for_tests()),
}
}
#[cfg(test)]
pub(crate) fn build_fetch_relations_service_loader_stage_for_tests(
source_message: &str,
) -> LoggingSchemaDebugReportForClientStage {
LoggingSchemaDebugReportForClientStage {
logging_client_name: "athena_logging".to_string(),
snapshot_result: Err(LoggingSchemaSnapshotError::FetchRelations(
sqlx::Error::Protocol(source_message.to_string()),
)),
}
}
#[cfg(test)]
pub(crate) fn build_fetch_columns_service_loader_stage_for_tests(
source_message: &str,
) -> LoggingSchemaDebugReportForClientStage {
LoggingSchemaDebugReportForClientStage {
logging_client_name: "athena_logging".to_string(),
snapshot_result: Err(LoggingSchemaSnapshotError::FetchColumns(
sqlx::Error::Protocol(source_message.to_string()),
)),
}
}
#[cfg(test)]
pub(crate) fn assert_successful_service_loader_report_result_for_tests(
result: Result<LoggingSchemaDebugReport, LoggingSchemaSnapshotError>,
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 report result for {context}"),
}
}
#[cfg(test)]
pub(crate) fn assert_fetch_columns_snapshot_error_for_tests(
result: Result<LoggingSchemaDebugReport, LoggingSchemaSnapshotError>,
expected_source_fragment: Option<&str>,
context: &str,
) {
assert_fetch_columns_snapshot_error_variant_for_tests(
result,
expected_source_fragment,
context,
);
}
#[cfg(test)]
pub(crate) fn assert_fetch_relations_snapshot_error_for_tests(
result: Result<LoggingSchemaDebugReport, LoggingSchemaSnapshotError>,
expected_source_fragment: Option<&str>,
context: &str,
) {
assert_fetch_relations_snapshot_error_variant_for_tests(
result,
expected_source_fragment,
context,
);
}