Skip to content

Commit c23aabc

Browse files
committed
test: Add test for internal function, and add docs after seeing it's behavior
1 parent 8f578c2 commit c23aabc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kube-core/src/schema.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ fn hoist_subschema_properties(
739739
..
740740
}) = variant
741741
{
742+
// Clear out the description and type to represent the empty `{}` variant
742743
if *variant_type == Some(SingleOrVec::Single(Box::new(InstanceType::Object))) {
743744
*variant_type = None;
744745
*metadata = None;
@@ -747,6 +748,9 @@ fn hoist_subschema_properties(
747748
}
748749
}
749750

751+
/// Get the single item from an [Iterator].
752+
///
753+
/// Return None if the [Iterator] is empty or has more than one entry.
750754
fn only_item<I: Iterator>(mut i: I) -> Option<I::Item> {
751755
let item = i.next()?;
752756
if i.next().is_some() {
@@ -755,6 +759,13 @@ fn only_item<I: Iterator>(mut i: I) -> Option<I::Item> {
755759
Some(item)
756760
}
757761

762+
#[test]
763+
fn only_item_t() {
764+
assert_eq!(only_item::<std::slice::Iter<'_, &str>>([].iter()), None);
765+
assert_eq!(only_item(["one"].iter()), Some(&"one"));
766+
assert_eq!(only_item(["one", "two"].iter()), None);
767+
}
768+
758769
fn merge_metadata(
759770
instance_type: &mut Option<SingleOrVec<InstanceType>>,
760771
variant_type: Option<SingleOrVec<InstanceType>>,

0 commit comments

Comments
 (0)