athena_rs 3.26.2

Hyper performant polyglot Database driver
Documentation
//! Missing-table status-row assembly for `/debug/schema`.
//!
//! This module owns construction of `LoggingSchemaExpectedTableStatus` entries
//! for expected tables that were not discovered in observed schema state.

use super::debug_evaluation_contracts::LoggingSchemaExpectedTableStatus;
use super::logging_expectation_contracts::ExpectedLoggingTable;

/// Builds one status row for an expected table that was not discovered.
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"];

    /// Builds a reusable expected-table contract for missing-status tests.
    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]
    /// Marks all required columns as missing and found columns as empty on missing rows.
    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()]
        );
    }
}