diff --git a/src/kvp/key.rs b/src/kvp/key.rs index 1029daa03..3defc0cfb 100644 --- a/src/kvp/key.rs +++ b/src/kvp/key.rs @@ -335,9 +335,12 @@ where #[cfg(test)] mod test { - use super::*; use rstest::rstest; + use crate::kvp::Label; + + use super::*; + #[test] fn key_with_prefix() { let key = Key::from_str("stackable.tech/vendor").unwrap(); @@ -399,4 +402,30 @@ mod test { let err = KeyName::from_str(&input).unwrap_err(); assert_eq!(err, error); } + + #[rstest] + #[case("app.kubernetes.io/name", true)] + #[case("name", false)] + fn key_prefix_deref(#[case] key: &str, #[case] expected: bool) { + let label = Label::try_from((key, "zookeeper")).unwrap(); + + let is_valid = label + .key() + .prefix() + .is_some_and(|prefix| *prefix == "app.kubernetes.io"); + + assert_eq!(is_valid, expected) + } + + #[rstest] + #[case("app.kubernetes.io/name", true)] + #[case("app.kubernetes.io/foo", false)] + #[case("name", true)] + #[case("foo", false)] + fn key_name_deref(#[case] key: &str, #[case] expected: bool) { + let label = Label::try_from((key, "zookeeper")).unwrap(); + let is_valid = *label.key().name() == "name"; + + assert_eq!(is_valid, expected); + } }