diff --git a/router/tests/common/mod.rs b/router/tests/common/mod.rs index 2b16645fca..1741d27459 100644 --- a/router/tests/common/mod.rs +++ b/router/tests/common/mod.rs @@ -37,25 +37,22 @@ pub fn test_context() -> TestContextBuilder { #[derive(Debug, Default)] pub struct TestContextBuilder { - namespace_autocreate_policy: Option, + namespace_autocreate_policy: NamespaceAutocreatePolicy, } impl TestContextBuilder { - pub fn autocreate_namespace(mut self, enabled: bool) -> Self { - self.namespace_autocreate_policy = match self.namespace_autocreate_policy { - Some(p) => Some(NamespaceAutocreatePolicy { enabled, ..p }), - None => Some(NamespaceAutocreatePolicy::new(true, None)), + pub fn with_autocreate_namespace(mut self, enabled: bool) -> Self { + self.namespace_autocreate_policy = NamespaceAutocreatePolicy { + enabled, + ..self.namespace_autocreate_policy }; self } - pub fn autocreate_namespace_retention_period_nanos(mut self, period_nanos: i64) -> Self { - self.namespace_autocreate_policy = match self.namespace_autocreate_policy { - Some(p) => Some(NamespaceAutocreatePolicy { - retention_period_nanos: Some(period_nanos), - ..p - }), - None => Some(NamespaceAutocreatePolicy::new(false, Some(period_nanos))), + pub fn with_autocreate_namespace_retention_period_nanos(mut self, period_nanos: i64) -> Self { + self.namespace_autocreate_policy = NamespaceAutocreatePolicy { + retention_period_nanos: Some(period_nanos), + ..self.namespace_autocreate_policy }; self } @@ -67,8 +64,7 @@ impl TestContextBuilder { test_helpers::maybe_start_logging(); - let namespace_autocreate_policy = namespace_autocreate_policy - .unwrap_or_else(|| NamespaceAutocreatePolicy::new(false, None)); + let namespace_autocreate_policy = namespace_autocreate_policy; let metrics: Arc = Default::default(); @@ -78,21 +74,12 @@ impl TestContextBuilder { } } -#[derive(Debug)] +#[derive(Debug, Default)] struct NamespaceAutocreatePolicy { enabled: bool, retention_period_nanos: Option, } -impl NamespaceAutocreatePolicy { - fn new(enabled: bool, retention_period_nanos: Option) -> Self { - Self { - enabled, - retention_period_nanos, - } - } -} - #[derive(Debug)] pub struct TestContext { client: Arc, diff --git a/router/tests/grpc.rs b/router/tests/grpc.rs index c49c9484b0..bfa3e1f888 100644 --- a/router/tests/grpc.rs +++ b/router/tests/grpc.rs @@ -140,7 +140,7 @@ async fn test_namespace_create() { #[tokio::test] async fn test_namespace_delete() { // Initialise a TestContext with implicit namespace creation. - let ctx = test_context().autocreate_namespace(true).build().await; + let ctx = test_context().with_autocreate_namespace(true).build().await; const RETENTION: i64 = Duration::from_secs(42 * 60 * 60).as_nanos() as _; diff --git a/router/tests/http.rs b/router/tests/http.rs index 31651a7f71..0f6ac880d4 100644 --- a/router/tests/http.rs +++ b/router/tests/http.rs @@ -16,7 +16,7 @@ pub mod common; #[tokio::test] async fn test_write_ok() { // Create a test context with implicit namespace creation. - let ctx = test_context().autocreate_namespace(true).build().await; + let ctx = test_context().with_autocreate_namespace(true).build().await; // Write data inside retention period let now = SystemProvider::default() @@ -91,8 +91,8 @@ async fn test_write_ok() { #[tokio::test] async fn test_write_outside_retention_period() { let ctx = test_context() - .autocreate_namespace(true) - .autocreate_namespace_retention_period_nanos(TEST_RETENTION_PERIOD_NS) + .with_autocreate_namespace(true) + .with_autocreate_namespace_retention_period_nanos(TEST_RETENTION_PERIOD_NS) .build() .await; @@ -120,7 +120,7 @@ async fn test_write_outside_retention_period() { #[tokio::test] async fn test_schema_conflict() { - let ctx = test_context().autocreate_namespace(true).build().await; + let ctx = test_context().with_autocreate_namespace(true).build().await; // data inside the retention period let now = SystemProvider::default() @@ -199,7 +199,7 @@ async fn test_rejected_ns() { #[tokio::test] async fn test_schema_limit() { - let ctx = test_context().autocreate_namespace(true).build().await; + let ctx = test_context().with_autocreate_namespace(true).build().await; let now = SystemProvider::default() .now() @@ -253,7 +253,7 @@ async fn test_schema_limit() { #[tokio::test] async fn test_write_propagate_ids() { - let ctx = test_context().autocreate_namespace(true).build().await; + let ctx = test_context().with_autocreate_namespace(true).build().await; // Create the namespace and a set of tables. let ns = ctx @@ -338,7 +338,7 @@ async fn test_write_propagate_ids() { #[tokio::test] async fn test_delete_unsupported() { - let ctx = test_context().autocreate_namespace(true).build().await; + let ctx = test_context().with_autocreate_namespace(true).build().await; // Create the namespace and a set of tables. ctx.catalog()