use super::debug_snapshot_contracts::LoggingSchemaSnapshotRows;
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,
};
use super::debug_snapshot_error_test_fixtures::{
build_fetch_columns_snapshot_error_for_tests, build_fetch_relations_snapshot_error_for_tests,
};
use super::debug_snapshot_queries_output_input_contracts::LoggingSchemaSnapshotRowsOutputInput;
use super::debug_snapshot_queries_result_assembly_input_contracts::LoggingSchemaSnapshotRowsResultAssemblyInput;
use super::debug_snapshot_queries_result_output_handoff_input_contracts::LoggingSchemaSnapshotRowsResultOutputHandoffInput;
use super::debug_snapshot_queries_stage_contracts::LoggingSchemaSnapshotRowsStage;
use super::service::{SchemaColumnRecord, SchemaRelationRecord};
#[cfg(test)]
pub(crate) fn build_snapshot_query_relation_row_for_tests() -> SchemaRelationRecord {
SchemaRelationRecord {
table_schema: "public".to_string(),
table_name: "gateway_request_log".to_string(),
relation_type: "BASE TABLE".to_string(),
}
}
#[cfg(test)]
pub(crate) fn build_snapshot_query_column_row_for_tests() -> SchemaColumnRecord {
SchemaColumnRecord {
table_schema: "public".to_string(),
table_name: "gateway_request_log".to_string(),
column_name: "request_id".to_string(),
data_type: Some("uuid".to_string()),
column_default: None,
is_nullable: Some("NO".to_string()),
}
}
#[cfg(test)]
pub(crate) fn build_snapshot_query_relations_for_tests() -> Vec<SchemaRelationRecord> {
vec![build_snapshot_query_relation_row_for_tests()]
}
#[cfg(test)]
pub(crate) fn build_snapshot_query_columns_for_tests() -> Vec<SchemaColumnRecord> {
vec![build_snapshot_query_column_row_for_tests()]
}
#[cfg(test)]
pub(crate) fn build_successful_snapshot_rows_stage_for_tests() -> LoggingSchemaSnapshotRowsStage {
LoggingSchemaSnapshotRowsStage {
relations_result: Ok(build_snapshot_query_relations_for_tests()),
columns_result: Ok(build_snapshot_query_columns_for_tests()),
}
}
#[cfg(test)]
pub(crate) fn build_successful_snapshot_rows_result_input_for_tests()
-> LoggingSchemaSnapshotRowsResultAssemblyInput {
LoggingSchemaSnapshotRowsResultAssemblyInput {
relations_result: Ok(build_snapshot_query_relations_for_tests()),
columns_result: Ok(build_snapshot_query_columns_for_tests()),
}
}
#[cfg(test)]
pub(crate) fn build_successful_snapshot_rows_output_input_for_tests()
-> LoggingSchemaSnapshotRowsOutputInput {
LoggingSchemaSnapshotRowsOutputInput {
relations: build_snapshot_query_relations_for_tests(),
columns: build_snapshot_query_columns_for_tests(),
}
}
#[cfg(test)]
pub(crate) fn build_successful_snapshot_rows_result_output_handoff_input_for_tests()
-> LoggingSchemaSnapshotRowsResultOutputHandoffInput {
LoggingSchemaSnapshotRowsResultOutputHandoffInput {
relations: build_snapshot_query_relations_for_tests(),
columns: build_snapshot_query_columns_for_tests(),
}
}
#[cfg(test)]
pub(crate) fn build_relation_error_snapshot_rows_stage_for_tests(
source_message: &str,
) -> LoggingSchemaSnapshotRowsStage {
LoggingSchemaSnapshotRowsStage {
relations_result: Err(build_fetch_relations_snapshot_error_for_tests(
source_message,
)),
columns_result: Ok(Vec::new()),
}
}
#[cfg(test)]
pub(crate) fn build_column_error_snapshot_rows_stage_for_tests(
source_message: &str,
) -> LoggingSchemaSnapshotRowsStage {
LoggingSchemaSnapshotRowsStage {
relations_result: Ok(Vec::new()),
columns_result: Err(build_fetch_columns_snapshot_error_for_tests(source_message)),
}
}
#[cfg(test)]
pub(crate) fn build_relation_and_column_error_snapshot_rows_stage_for_tests(
relation_source_message: &str,
column_source_message: &str,
) -> LoggingSchemaSnapshotRowsStage {
LoggingSchemaSnapshotRowsStage {
relations_result: Err(build_fetch_relations_snapshot_error_for_tests(
relation_source_message,
)),
columns_result: Err(build_fetch_columns_snapshot_error_for_tests(
column_source_message,
)),
}
}
#[cfg(test)]
pub(crate) fn build_relation_error_snapshot_rows_result_input_for_tests(
source_message: &str,
) -> LoggingSchemaSnapshotRowsResultAssemblyInput {
LoggingSchemaSnapshotRowsResultAssemblyInput {
relations_result: Err(build_fetch_relations_snapshot_error_for_tests(
source_message,
)),
columns_result: Ok(Vec::new()),
}
}
#[cfg(test)]
pub(crate) fn build_column_error_snapshot_rows_result_input_for_tests(
source_message: &str,
) -> LoggingSchemaSnapshotRowsResultAssemblyInput {
LoggingSchemaSnapshotRowsResultAssemblyInput {
relations_result: Ok(Vec::new()),
columns_result: Err(build_fetch_columns_snapshot_error_for_tests(source_message)),
}
}
#[cfg(test)]
pub(crate) fn assert_snapshot_rows_output_for_tests(
rows: LoggingSchemaSnapshotRows,
context: &str,
) {
assert_eq!(
rows.relations.len(),
1,
"unexpected {context} relation row count"
);
assert_eq!(
rows.columns.len(),
1,
"unexpected {context} column row count"
);
assert_eq!(
rows.relations[0].table_name, "gateway_request_log",
"unexpected {context} relation table name"
);
assert_eq!(
rows.columns[0].column_name, "request_id",
"unexpected {context} column name"
);
}
#[cfg(test)]
pub(crate) fn assert_successful_snapshot_rows_result_for_tests(
result: Result<LoggingSchemaSnapshotRows, LoggingSchemaSnapshotError>,
context: &str,
) {
match result {
Ok(rows) => assert_snapshot_rows_output_for_tests(rows, context),
Err(_) => panic!("expected successful snapshot rows result for {context}"),
}
}
#[cfg(test)]
pub(crate) fn assert_successful_snapshot_rows_stage_for_tests(
stage: LoggingSchemaSnapshotRowsStage,
context: &str,
) {
match stage.relations_result {
Ok(relations) => assert_eq!(
relations.len(),
1,
"unexpected {context} relations result row count"
),
Err(_) => panic!("expected successful relations result for {context}"),
}
match stage.columns_result {
Ok(columns) => assert_eq!(
columns.len(),
1,
"unexpected {context} columns result row count"
),
Err(_) => panic!("expected successful columns result for {context}"),
}
}
#[cfg(test)]
pub(crate) fn assert_relation_and_column_error_snapshot_rows_stage_for_tests(
stage: LoggingSchemaSnapshotRowsStage,
relation_source_fragment: Option<&str>,
column_source_fragment: Option<&str>,
context: &str,
) {
assert_fetch_relations_snapshot_error_variant_for_tests(
stage.relations_result,
relation_source_fragment,
context,
);
assert_fetch_columns_snapshot_error_variant_for_tests(
stage.columns_result,
column_source_fragment,
context,
);
}
#[cfg(test)]
pub(crate) fn assert_fetch_relations_snapshot_error_for_tests(
result: Result<LoggingSchemaSnapshotRows, LoggingSchemaSnapshotError>,
expected_source_fragment: Option<&str>,
context: &str,
) {
assert_fetch_relations_snapshot_error_variant_for_tests(
result,
expected_source_fragment,
context,
);
}
#[cfg(test)]
pub(crate) fn assert_fetch_columns_snapshot_error_for_tests(
result: Result<LoggingSchemaSnapshotRows, LoggingSchemaSnapshotError>,
expected_source_fragment: Option<&str>,
context: &str,
) {
assert_fetch_columns_snapshot_error_variant_for_tests(
result,
expected_source_fragment,
context,
);
}