@@ -432,3 +432,89 @@ func TestValidateAWS(t *testing.T) {
432432 })
433433 }
434434}
435+
436+ func TestInitConsumerGroupRebalanceStrategy (t * testing.T ) {
437+ tests := []struct {
438+ name string
439+ metadata map [string ]string
440+ expectedStrategy string
441+ }{
442+ {
443+ name : "missing consumerGroupRebalanceStrategy property defaults to Range" ,
444+ metadata : map [string ]string {},
445+ expectedStrategy : "range" ,
446+ },
447+ {
448+ name : "empty consumerGroupRebalanceStrategy property defaults to Range" ,
449+ metadata : map [string ]string {
450+ "consumerGroupRebalanceStrategy" : "" ,
451+ },
452+ expectedStrategy : "range" ,
453+ },
454+ {
455+ name : "valid sticky strategy" ,
456+ metadata : map [string ]string {
457+ "consumerGroupRebalanceStrategy" : "sticky" ,
458+ },
459+ expectedStrategy : "sticky" ,
460+ },
461+ {
462+ name : "valid roundrobin strategy" ,
463+ metadata : map [string ]string {
464+ "consumerGroupRebalanceStrategy" : "roundrobin" ,
465+ },
466+ expectedStrategy : "roundrobin" ,
467+ },
468+ {
469+ name : "valid range strategy" ,
470+ metadata : map [string ]string {
471+ "consumerGroupRebalanceStrategy" : "range" ,
472+ },
473+ expectedStrategy : "range" ,
474+ },
475+ {
476+ name : "case insensitive strategy" ,
477+ metadata : map [string ]string {
478+ "consumerGroupRebalanceStrategy" : "sTickY" ,
479+ },
480+ expectedStrategy : "sticky" ,
481+ },
482+ {
483+ name : "case insensitive strategy default" ,
484+ metadata : map [string ]string {
485+ "consumerGroupRebalanceStrategy" : "Range" ,
486+ },
487+ expectedStrategy : "range" ,
488+ },
489+ {
490+ name : "invalid strategy defaults to Range with warning" ,
491+ metadata : map [string ]string {
492+ "consumerGroupRebalanceStrategy" : "invalid" ,
493+ },
494+ expectedStrategy : "range" ,
495+ },
496+ }
497+
498+ for _ , tt := range tests {
499+ t .Run (tt .name , func (t * testing.T ) {
500+ // Create Kafka instance with logger
501+ k := & Kafka {
502+ logger : logger .NewLogger ("kafka_test" ),
503+ }
504+
505+ // Create sarama config
506+ config := sarama .NewConfig ()
507+
508+ // Call the method under test
509+ k .initConsumerGroupRebalanceStrategy (config , tt .metadata )
510+
511+ // Verify the strategy was set correctly
512+ require .Len (t , config .Consumer .Group .Rebalance .GroupStrategies , 1 , "Expected exactly one rebalance strategy" )
513+
514+ assert .Equal (t , tt .expectedStrategy , config .Consumer .Group .Rebalance .GroupStrategies [0 ].Name ())
515+
516+ // Note: Warning verification would require a more sophisticated mock
517+ // For now, we just verify the strategy is set correctly
518+ })
519+ }
520+ }
0 commit comments