|
| 1 | +use crate::fingerprint_identity::main::canonical_text::canonical_text; |
| 2 | +use crate::fingerprint_identity::main::decoded_object::decoded_object; |
| 3 | +use crate::fingerprint_identity::main::model_local_identity_hash::model_local_identity_hash; |
| 4 | +use crate::fingerprint_identity::main::recorded_model_local_hash::recorded_model_local_hash; |
| 5 | +use crate::fingerprint_identity::tests::test_types::RecordedLocalHashTestCase; |
| 6 | + |
| 7 | +#[test] |
| 8 | +fn given_recorded_metadata_when_hashing_then_it_matches_the_config_as_written() { |
| 9 | + let test_cases = [ |
| 10 | + RecordedLocalHashTestCase { |
| 11 | + description: "a written-out default refresh mode stays in the hash", |
| 12 | + metadata_json: r#"{"config":{"materialized":"maintained","refresh_mode":"incremental"},"execution_signature":{},"local_function_hashes":{},"model_name":"daily_totals"}"#, |
| 13 | + expected_hashed_json: r#"{"config":{"materialized":"maintained","refresh_mode":"incremental"},"execution_signature":{},"local_function_hashes":{},"model_name":"daily_totals"}"#, |
| 14 | + }, |
| 15 | + RecordedLocalHashTestCase { |
| 16 | + description: "a model that declares no refresh mode", |
| 17 | + metadata_json: r#"{"config":{"materialized":"maintained"},"execution_signature":{},"local_function_hashes":{},"model_name":"daily_totals"}"#, |
| 18 | + expected_hashed_json: r#"{"config":{"materialized":"maintained"},"execution_signature":{},"local_function_hashes":{},"model_name":"daily_totals"}"#, |
| 19 | + }, |
| 20 | + ]; |
| 21 | + |
| 22 | + for test_case in test_cases { |
| 23 | + assert_eq!( |
| 24 | + recorded_model_local_hash("query_hash", test_case.metadata_json), |
| 25 | + Some(model_local_identity_hash( |
| 26 | + "query_hash", |
| 27 | + &canonical_text( |
| 28 | + decoded_object(test_case.expected_hashed_json) |
| 29 | + .expect("metadata is JSON") |
| 30 | + .expect("metadata is an object") |
| 31 | + ) |
| 32 | + )), |
| 33 | + "{}", |
| 34 | + test_case.description |
| 35 | + ); |
| 36 | + } |
| 37 | +} |
0 commit comments