@@ -444,3 +444,82 @@ func TestConfigFilePath(t *testing.T) {
444444})
445445}
446446}
447+
448+ func TestTopicsNormalization (t * testing.T ) {
449+ tests := []struct {
450+ name string
451+ topicsEnv string
452+ expectedCount int
453+ expected []string
454+ description string
455+ }{
456+ {
457+ name :"normal topics" ,
458+ topicsEnv :"topic1,topic2,topic3" ,
459+ expectedCount :3 ,
460+ expected : []string {"topic1" ,"topic2" ,"topic3" },
461+ description :"should parse normal comma-separated topics as-is" ,
462+ },
463+ {
464+ name :"topics with leading/trailing spaces" ,
465+ topicsEnv :" topic1 , topic2 , topic3 " ,
466+ expectedCount :3 ,
467+ expected : []string {" topic1 " ," topic2 " ," topic3 " },
468+ description :"should preserve topics with spaces (not trimmed)" ,
469+ },
470+ {
471+ name :"empty string only" ,
472+ topicsEnv :" " ,
473+ expectedCount :0 ,
474+ expected : []string {},
475+ description :"should treat whitespace-only as empty" ,
476+ },
477+ {
478+ name :"multiple spaces" ,
479+ topicsEnv :" " ,
480+ expectedCount :0 ,
481+ expected : []string {},
482+ description :"should treat multiple spaces as empty" ,
483+ },
484+ {
485+ name :"empty strings between commas" ,
486+ topicsEnv :" , , " ,
487+ expectedCount :0 ,
488+ expected : []string {},
489+ description :"should treat whitespace-only entries as empty" ,
490+ },
491+ {
492+ name :"mixed valid topics and whitespace" ,
493+ topicsEnv :"topic1, ,topic2" ,
494+ expectedCount :3 ,
495+ expected : []string {"topic1" ," " ,"topic2" },
496+ description :"should preserve valid topics even with whitespace entries" ,
497+ },
498+ {
499+ name :"wildcard with spaces" ,
500+ topicsEnv :" * " ,
501+ expectedCount :1 ,
502+ expected : []string {" * " },
503+ description :"should preserve wildcard with spaces" ,
504+ },
505+ }
506+
507+ for _ ,tt := range tests {
508+ t .Run (tt .name ,func (t * testing.T ) {
509+ mockOS := & mockOS {
510+ envVars :map [string ]string {
511+ "TOPICS" :tt .topicsEnv ,
512+ "API_KEY" :"test" ,
513+ "API_JWT_SECRET" :"test" ,
514+ "AES_ENCRYPTION_SECRET" :"test" ,
515+ "POSTGRES_URL" :"postgres://test" ,
516+ },
517+ }
518+
519+ cfg ,err := config .ParseWithoutValidation (config.Flags {},mockOS )
520+ assert .NoError (t ,err )
521+ assert .Equal (t ,tt .expectedCount ,len (cfg .Topics ),tt .description )
522+ assert .Equal (t ,tt .expected ,cfg .Topics ,tt .description )
523+ })
524+ }
525+ }