use super::debug_evaluation_contracts::LoggingSchemaExpectedTableStatus;
use super::logging_expectation_contracts::ExpectedLoggingTable;
pub(super) fn build_missing_expected_table_status(
expected: &ExpectedLoggingTable,
expected_columns: Vec<String>,
) -> LoggingSchemaExpectedTableStatus {
LoggingSchemaExpectedTableStatus {
table_schema: expected.table_schema.to_string(),
table_name: expected.table_name.to_string(),
expected_relation_type: expected.relation_type.to_string(),
required: expected.required,
purpose: expected.purpose.to_string(),
expected_columns,
found: false,
found_relation_type: None,
relation_type_matches: false,
found_columns: Vec::new(),
missing_columns: expected
.required_columns
.iter()
.map(|value| (*value).to_string())
.collect(),
unexpected_columns: Vec::new(),
}
}
#[cfg(test)]
mod tests {
use super::*;
const REQUIRED_COLUMNS: &[&str] = &["request_id", "status_code"];
fn expected_table(required: bool) -> ExpectedLoggingTable {
ExpectedLoggingTable {
table_schema: "public",
table_name: "gateway_request_log",
relation_type: "BASE TABLE",
required,
purpose: "test table",
required_columns: REQUIRED_COLUMNS,
}
}
#[test]
fn missing_status_sets_missing_columns_and_empty_found_columns() {
let expected = expected_table(false);
let row = build_missing_expected_table_status(
&expected,
vec!["request_id".to_string(), "status_code".to_string()],
);
assert!(!row.found);
assert!(row.found_columns.is_empty());
assert_eq!(
row.missing_columns,
vec!["request_id".to_string(), "status_code".to_string()]
);
}
}