From 7c46cbecd13552d0da029e9e33ada14aa578fb83 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 23 Jan 2024 12:50:27 +0100 Subject: [PATCH 1/4] Change Deref target of KeyPrefix and KeyName to str --- src/kvp/key.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kvp/key.rs b/src/kvp/key.rs index 924373401..1029daa03 100644 --- a/src/kvp/key.rs +++ b/src/kvp/key.rs @@ -229,7 +229,7 @@ impl FromStr for KeyPrefix { } impl Deref for KeyPrefix { - type Target = String; + type Target = str; fn deref(&self) -> &Self::Target { &self.0 @@ -247,7 +247,7 @@ where T: AsRef, { fn eq(&self, other: &T) -> bool { - self.as_str() == other.as_ref() + self.deref() == other.as_ref() } } @@ -311,7 +311,7 @@ impl FromStr for KeyName { } impl Deref for KeyName { - type Target = String; + type Target = str; fn deref(&self) -> &Self::Target { &self.0 @@ -329,7 +329,7 @@ where T: AsRef, { fn eq(&self, other: &T) -> bool { - self.as_str() == other.as_ref() + self.deref() == other.as_ref() } } From e3392df857810af84ef0c0e220014f25cfe1ee79 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 23 Jan 2024 12:53:12 +0100 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b76728232..ae2e61bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Changed + +- Change Deref target of `KeyPrefix` and `KeyName` to `str` ([#725]). + +[#725]: https://github.com/stackabletech/operator-rs/pull/725 + ## [0.62.0] - 2024-01-19 ### Added From 78670bed480c0627260700f493813ebbe141d3d6 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 23 Jan 2024 14:15:13 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md Co-authored-by: Sebastian Bernauer --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae2e61bfb..f8a8e3f4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. ### Changed -- Change Deref target of `KeyPrefix` and `KeyName` to `str` ([#725]). +- Change Deref target of `KeyPrefix` and `KeyName` from `String` to `str` ([#725]). [#725]: https://github.com/stackabletech/operator-rs/pull/725 From 2b80f5a8ba91611007346d641b0d9574632bfe79 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 23 Jan 2024 14:51:44 +0100 Subject: [PATCH 4/4] Add KeyPrefix and KeyName deref tests --- src/kvp/key.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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); + } }