Skip to content

Commit

Permalink
Add KeyPrefix and KeyName deref tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Jan 23, 2024
1 parent fb5d04d commit 2b80f5a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/kvp/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2b80f5a

Please sign in to comment.