fix: Use the parts method to get the template length
The template length should always return a value > 0 because templates must have at least one part. Before this change, `len` would have returned 0 if there was no override because of the `unwrap_or_default`. Instead, use the `parts` method, which takes care of the fallback to the hardcoded default template, whose len will always be 1.pull/24376/head
parent
eef84d9df3
commit
5761226728
|
@ -288,10 +288,7 @@ impl TablePartitionTemplateOverride {
|
|||
/// Returns the number of parts in this template.
|
||||
#[allow(clippy::len_without_is_empty)] // Senseless - there must always be >0 parts.
|
||||
pub fn len(&self) -> usize {
|
||||
self.0
|
||||
.as_ref()
|
||||
.map(|v| v.inner().parts.len())
|
||||
.unwrap_or_default()
|
||||
self.parts().count()
|
||||
}
|
||||
|
||||
/// Iterate through the protobuf parts and lend out what the `mutable_batch` crate needs to
|
||||
|
@ -911,6 +908,14 @@ mod tests {
|
|||
assert_matches!(got.as_slice(), [TemplatePart::TimeFormat("%Y-%m-%d")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn len_of_default_template_is_1() {
|
||||
let ns = NamespacePartitionTemplateOverride::default();
|
||||
let t = TablePartitionTemplateOverride::try_new(None, &ns).unwrap();
|
||||
|
||||
assert_eq!(t.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_custom_table_template_specified_gets_namespace_template() {
|
||||
let namespace_template =
|
||||
|
@ -923,6 +928,7 @@ mod tests {
|
|||
let table_template =
|
||||
TablePartitionTemplateOverride::try_new(None, &namespace_template).unwrap();
|
||||
|
||||
assert_eq!(table_template.len(), 1);
|
||||
assert_eq!(table_template.0, namespace_template.0);
|
||||
}
|
||||
|
||||
|
@ -946,6 +952,7 @@ mod tests {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(table_template.len(), 1);
|
||||
assert_eq!(table_template.0.unwrap().inner(), &custom_table_template);
|
||||
}
|
||||
|
||||
|
@ -995,5 +1002,6 @@ mod tests {
|
|||
);
|
||||
let table_json_str: String = buf.iter().map(extract_sqlite_argument_text).collect();
|
||||
assert_eq!(table_json_str, expected_json_str);
|
||||
assert_eq!(table.len(), 2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue