Skip to content

Commit dcb7f80

Browse files
test: Add unit test for RoleGroupBuilder::build_node_role_label
1 parent c48fadf commit dcb7f80

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

rust/operator-binary/src/controller/build/role_group_builder.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ impl<'a> RoleGroupBuilder<'a> {
233233
}
234234

235235
fn build_node_role_label(node_role: &v1alpha1::NodeRole) -> Label {
236-
// TODO Check the maximum length at compile-time
236+
// It is not possible to check the infallibility of the following statement at
237+
// compile-time. Instead, it is tested in `tests::test_build_node_role_label`.
237238
Label::try_from((
238239
format!("stackable.tech/opensearch-role.{node_role}"),
239240
"true".to_string(),
@@ -444,3 +445,17 @@ impl<'a> RoleGroupBuilder<'a> {
444445
)
445446
}
446447
}
448+
449+
#[cfg(test)]
450+
mod tests {
451+
use strum::IntoEnumIterator;
452+
453+
use crate::{controller::build::role_group_builder::RoleGroupBuilder, crd::v1alpha1};
454+
455+
#[test]
456+
fn test_build_node_role_label() {
457+
for node_role in v1alpha1::NodeRole::iter() {
458+
RoleGroupBuilder::build_node_role_label(&node_role);
459+
}
460+
}
461+
}

rust/operator-binary/src/crd/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use stackable_operator::{
2323
time::Duration,
2424
versioned::versioned,
2525
};
26-
use strum::Display;
26+
use strum::{Display, EnumIter};
2727

2828
use crate::framework::{
2929
ClusterName, IsLabelValue, ProductName, RoleName,
@@ -76,7 +76,17 @@ pub mod versioned {
7676
// https://github.com/opensearch-project/ml-commons/blob/3.0.0.0/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java#L394.
7777
// If such a plugin is added, then this enumeration must be extended accordingly.
7878
#[derive(
79-
Clone, Debug, Deserialize, Display, Eq, JsonSchema, Ord, PartialEq, PartialOrd, Serialize,
79+
Clone,
80+
Debug,
81+
Deserialize,
82+
Display,
83+
EnumIter,
84+
Eq,
85+
JsonSchema,
86+
Ord,
87+
PartialEq,
88+
PartialOrd,
89+
Serialize,
8090
)]
8191
// The OpenSearch configuration uses snake_case. To make it easier to match the log output of
8292
// OpenSearch with this cluster configuration, snake_case is also used here.

0 commit comments

Comments
 (0)