@@ -528,9 +528,6 @@ mod tests {
528528 }
529529 }
530530
531- // In the absence of code (for now, anyway) that actually couples backend
532- // configuration with the operator definition, add a test asserting that
533- // the given spec maps to expected configuration values.
534531 #[ test]
535532 fn test_build_env ( ) {
536533 let mut spec = make_spec ( ) ;
@@ -540,35 +537,64 @@ mod tests {
540537 metrics_protocol : Some ( OpenTelemetryProtocol :: Http ) ,
541538 } ) ;
542539
543- let env = build_env ( & spec, "my-cluster" , "my-cluster-headless" , "my-ns" ) ;
544- let get = |name : & str | {
545- env. iter ( )
546- . find ( |e| e. name == name)
547- . and_then ( |e| e. value . as_deref ( ) )
548- } ;
549-
550- assert_eq ! ( get( "DIOM_LISTEN_ADDRESS" ) , Some ( "0.0.0.0:8624" ) ) ;
551- assert_eq ! ( get( "DIOM_CLUSTER_AUTO_INITIALIZE" ) , Some ( "true" ) ) ;
552- assert_eq ! ( get( "DIOM_PERSISTENT_DB_PATH" ) , Some ( "/data/persistent" ) ) ;
553- assert_eq ! ( get( "DIOM_CLUSTER_LOG_PATH" ) , Some ( "/data/persistent/logs" ) ) ;
540+ let env_vars = build_env ( & spec, "my-cluster" , "my-cluster-headless" , "my-ns" ) ;
541+ // This var has k8s placeholders that can't be parsed by Diom config, so just assert it directly
542+ // and exclude from the temp env:
554543 assert_eq ! (
555- get( "DIOM_CLUSTER_SNAPSHOT_PATH" ) ,
556- Some ( "/data/persistent/snapshots" )
544+ env_vars
545+ . iter( )
546+ . find( |e| e. name == "DIOM_CLUSTER_ADVERTISED_ADDRESS" )
547+ . and_then( |e| e. value. as_deref( ) ) ,
548+ Some ( "$(POD_NAME).my-cluster-headless.$(POD_NAMESPACE).svc.cluster.local:8625" ) ,
557549 ) ;
550+
551+ let env_vars: Vec < ( String , Option < String > ) > = env_vars
552+ . into_iter ( )
553+ . filter ( |e| e. name . starts_with ( "DIOM_" ) )
554+ . filter ( |e| e. name != "DIOM_CLUSTER_ADVERTISED_ADDRESS" )
555+ . map ( |e| ( e. name , e. value ) )
556+ . collect ( ) ;
557+
558+ // Backend config should successfully load given our Operator-supplied env vars
559+ let cfg = temp_env:: with_vars ( env_vars, || diom_backend:: cfg:: load ( None ) . unwrap ( ) ) ;
560+
558561 assert_eq ! (
559- get( "DIOM_CLUSTER_ADVERTISED_ADDRESS" ) ,
560- Some ( "$(POD_NAME).my-cluster-headless.$(POD_NAMESPACE).svc.cluster.local:8625" ) ,
562+ cfg. listen_address,
563+ "0.0.0.0:8624" . parse:: <std:: net:: SocketAddr >( ) . unwrap( )
564+ ) ;
565+ assert_eq ! (
566+ cfg. persistent_db. path,
567+ std:: path:: PathBuf :: from( "/data/persistent" )
561568 ) ;
569+ assert ! ( cfg. cluster. auto_initialize) ;
562570 assert_eq ! (
563- get( "DIOM_CLUSTER_SEED_NODES" ) ,
564- Some ( "my-cluster-0.my-cluster-headless.my-ns.svc.cluster.local:8625" ) ,
571+ cfg. cluster. seed_nodes,
572+ vec![
573+ "my-cluster-0.my-cluster-headless.my-ns.svc.cluster.local:8625"
574+ . parse:: <diom_backend:: cfg:: PeerAddr >( )
575+ . unwrap( )
576+ ]
565577 ) ;
566- assert_eq ! ( get( "DIOM_OPENTELEMETRY_ADDRESS" ) , Some ( "grpc://otel:4317" ) ) ;
567578 assert_eq ! (
568- get( "DIOM_OPENTELEMETRY_METRICS_ADDRESS" ) ,
579+ cfg. cluster. log_path,
580+ Some ( std:: path:: PathBuf :: from( "/data/persistent/logs" ) )
581+ ) ;
582+ assert_eq ! (
583+ cfg. cluster. snapshot_path,
584+ Some ( std:: path:: PathBuf :: from( "/data/persistent/snapshots" ) )
585+ ) ;
586+ assert_eq ! (
587+ cfg. opentelemetry. address. as_deref( ) ,
588+ Some ( "grpc://otel:4317" )
589+ ) ;
590+ assert_eq ! (
591+ cfg. opentelemetry. metrics_address. as_deref( ) ,
569592 Some ( "http://otel:4318" )
570593 ) ;
571- assert_eq ! ( get( "DIOM_OPENTELEMETRY_METRICS_PROTOCOL" ) , Some ( "http" ) ) ;
594+ assert ! ( matches!(
595+ cfg. opentelemetry. metrics_protocol,
596+ diom_backend:: cfg:: OpenTelemetryProtocol :: Http
597+ ) ) ;
572598 }
573599
574600 fn make_pvc ( name : & str , storage : & str ) -> PersistentVolumeClaim {
0 commit comments