From ab7282795abc3ff58d6efd46f41ed34fa79198d8 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 11 Sep 2023 17:11:45 -0400 Subject: [PATCH] refactor: Extract functions for creating repeated NamespaceSchema values --- router/src/namespace_cache/memory.rs | 54 +++++++++++++++------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/router/src/namespace_cache/memory.rs b/router/src/namespace_cache/memory.rs index 6fcf6bc134..5f714b6904 100644 --- a/router/src/namespace_cache/memory.rs +++ b/router/src/namespace_cache/memory.rs @@ -181,6 +181,30 @@ mod tests { const TEST_NAMESPACE_ID: NamespaceId = NamespaceId::new(42); + // One arbitrary `NamespaceSchema` value + fn schema1() -> NamespaceSchema { + NamespaceSchema { + id: TEST_NAMESPACE_ID, + tables: Default::default(), + max_columns_per_table: 50, + max_tables: 24, + retention_period_ns: Some(876), + partition_template: Default::default(), + } + } + + // Another, slightly different, arbitrary `NamespaceSchema` value + fn schema2() -> NamespaceSchema { + NamespaceSchema { + id: TEST_NAMESPACE_ID, + tables: Default::default(), + max_columns_per_table: 10, + max_tables: 42, + retention_period_ns: Some(876), + partition_template: Default::default(), + } + } + #[tokio::test] async fn test_put_get() { let ns = NamespaceName::new("test").expect("namespace name is valid"); @@ -193,14 +217,7 @@ mod tests { } ); - let schema1 = NamespaceSchema { - id: TEST_NAMESPACE_ID, - tables: Default::default(), - max_columns_per_table: 50, - max_tables: 24, - retention_period_ns: Some(876), - partition_template: Default::default(), - }; + let schema1 = schema1(); assert_matches!(cache.put_schema(ns.clone(), schema1.clone()), (new, s) => { assert_eq!(*new, schema1); assert!(s.new_tables.is_empty()); @@ -210,15 +227,7 @@ mod tests { schema1 ); - let schema2 = NamespaceSchema { - id: TEST_NAMESPACE_ID, - tables: Default::default(), - max_columns_per_table: 10, - max_tables: 42, - retention_period_ns: Some(876), - partition_template: Default::default(), - }; - + let schema2 = schema2(); assert_matches!(cache.put_schema(ns.clone(), schema2.clone()), (new, s) => { assert_eq!(*new, schema2); assert!(s.new_tables.is_empty()); @@ -269,12 +278,9 @@ mod tests { assert_ne!(first_write_table_schema, second_write_table_schema); let schema_update_1 = NamespaceSchema { - id: NamespaceId::new(42), tables: BTreeMap::from([(String::from(table_name), first_write_table_schema.clone())]), - max_columns_per_table: 50, - max_tables: 24, retention_period_ns: None, - partition_template: Default::default(), + ..schema1() }; let schema_update_2 = NamespaceSchema { tables: BTreeMap::from([(String::from(table_name), second_write_table_schema.clone())]), @@ -368,16 +374,14 @@ mod tests { table_3.add_column(column_3); let schema_update_1 = NamespaceSchema { - id: NamespaceId::new(42), tables: BTreeMap::from([ (String::from("table_1"), table_1.to_owned()), (String::from("table_2"), table_2.to_owned()), ]), - max_columns_per_table: 50, - max_tables: 24, retention_period_ns: None, - partition_template: Default::default(), + ..schema1() }; + let schema_update_2 = NamespaceSchema { tables: BTreeMap::from([ (String::from("table_1"), table_1.to_owned()),