@@ -393,16 +393,18 @@ pub fn error_policy(
393393/// Shared helpers for building validated test clusters from minimal YAML fixtures.
394394#[ cfg( test) ]
395395pub ( crate ) mod test_support {
396+ use std:: str:: FromStr ;
397+
396398 use stackable_operator:: {
397399 cli:: OperatorEnvironmentOptions , commons:: networking:: DomainName ,
398- utils:: cluster_info:: KubernetesClusterInfo ,
400+ utils:: cluster_info:: KubernetesClusterInfo , v2 :: types :: operator :: RoleGroupName ,
399401 } ;
400402
401403 use crate :: {
402- crd:: { authentication:: DereferencedAuthenticationClasses , v1alpha1} ,
404+ crd:: { ZookeeperRole , authentication:: DereferencedAuthenticationClasses , v1alpha1} ,
403405 zk_controller:: {
404406 dereference:: DereferencedObjects ,
405- validate:: { ValidatedCluster , validate} ,
407+ validate:: { ValidatedCluster , ZookeeperRoleGroupConfig , validate} ,
406408 } ,
407409 } ;
408410
@@ -471,24 +473,36 @@ pub(crate) mod test_support {
471473 )
472474 . expect ( "validate should succeed for the test fixture" )
473475 }
476+
477+ /// Looks up the validated, merged config of the named `server` role group together with its
478+ /// parsed [`RoleGroupName`] — the standard `(name, config)` inputs to the
479+ /// `build_server_rolegroup_*` functions. Panics if the group does not exist.
480+ pub fn server_rolegroup_config < ' a > (
481+ validated : & ' a ValidatedCluster ,
482+ role_group : & str ,
483+ ) -> ( RoleGroupName , & ' a ZookeeperRoleGroupConfig ) {
484+ let role_group_name = RoleGroupName :: from_str ( role_group) . expect ( "valid role group name" ) ;
485+ let config = validated
486+ . role_group_configs
487+ . get ( & ZookeeperRole :: Server )
488+ . and_then ( |groups| groups. get ( & role_group_name) )
489+ . unwrap_or_else ( || panic ! ( "server role group {role_group:?} should exist" ) ) ;
490+ ( role_group_name, config)
491+ }
474492}
475493
476494#[ cfg( test) ]
477495mod tests {
478- use std:: {
479- collections:: { BTreeMap , BTreeSet } ,
480- str:: FromStr ,
481- } ;
496+ use std:: collections:: { BTreeMap , BTreeSet } ;
482497
483- use stackable_operator:: {
484- k8s_openapi:: api:: core:: v1:: ConfigMap , v2:: types:: operator:: RoleGroupName ,
485- } ;
498+ use stackable_operator:: k8s_openapi:: api:: core:: v1:: ConfigMap ;
486499
487500 use super :: * ;
488501 use crate :: zk_controller:: {
489502 build:: properties:: zoo_cfg,
490503 test_support:: {
491- cluster_info, minimal_zk, validated_cluster, validated_cluster_with_client_auth,
504+ cluster_info, minimal_zk, server_rolegroup_config, validated_cluster,
505+ validated_cluster_with_client_auth,
492506 } ,
493507 validate:: ValidatedCluster ,
494508 } ;
@@ -967,9 +981,7 @@ mod tests {
967981 /// pinned separately (`test_server_lines_use_myid_offset_across_rolegroups`,
968982 /// `test_seeded_operator_defaults`).
969983 fn zoo_cfg_map ( validated : & ValidatedCluster , role_group : & str ) -> BTreeMap < String , String > {
970- let role_group_name = RoleGroupName :: from_str ( role_group) . expect ( "valid role group name" ) ;
971- let rolegroup_config =
972- & validated. role_group_configs [ & ZookeeperRole :: Server ] [ & role_group_name] ;
984+ let ( _, rolegroup_config) = server_rolegroup_config ( validated, role_group) ;
973985 let server_addresses = zoo_cfg:: server_addresses ( validated, & cluster_info ( ) ) ;
974986 zoo_cfg:: build ( validated, rolegroup_config, & server_addresses)
975987 }
@@ -1167,9 +1179,8 @@ mod tests {
11671179
11681180 /// Builds the rolegroup `ConfigMap` for the named server role group of a validated cluster.
11691181 fn config_map_for ( validated_cluster : & ValidatedCluster , role_group : & str ) -> ConfigMap {
1170- let role_group_name = RoleGroupName :: from_str ( role_group) . expect ( "valid role group name" ) ;
1171- let rolegroup_config =
1172- & validated_cluster. role_group_configs [ & ZookeeperRole :: Server ] [ & role_group_name] ;
1182+ let ( role_group_name, rolegroup_config) =
1183+ server_rolegroup_config ( validated_cluster, role_group) ;
11731184
11741185 config_map:: build_server_rolegroup_config_map (
11751186 validated_cluster,
0 commit comments