@@ -853,4 +853,87 @@ func TestMapValueGroupsDecoration(t *testing.T) {
853853 }
854854 assert .ElementsMatch (t , []string {"alpha" , "beta" , "gamma" }, finalKeys )
855855 })
856+
857+ t .Run ("map decoration across modules" , func (t * testing.T ) {
858+ t .Parallel ()
859+
860+ type DecorationInput struct {
861+ fx.In
862+ Processors map [string ]testProcessor `group:"processors"`
863+ }
864+
865+ type DecorationOutput struct {
866+ fx.Out
867+ Processors map [string ]testProcessor `group:"processors"`
868+ }
869+
870+ var outerProcessors map [string ]testProcessor
871+ var innerProcessors map [string ]testProcessor
872+
873+ app := fxtest .New (t ,
874+ fx .Provide (
875+ fx .Annotate (
876+ func () testProcessor { return & testBasicProcessor {name : "auth" } },
877+ fx .ResultTags (`name:"auth" group:"processors"` ),
878+ ),
879+ fx .Annotate (
880+ func () testProcessor { return & testBasicProcessor {name : "billing" } },
881+ fx .ResultTags (`name:"billing" group:"processors"` ),
882+ ),
883+ ),
884+ fx .Decorate (func (input DecorationInput ) DecorationOutput {
885+ enhanced := make (map [string ]testProcessor )
886+ for name , processor := range input .Processors {
887+ enhanced [name ] = & testEnhancedProcessor {
888+ wrapped : processor ,
889+ prefix : "[OUTER]" ,
890+ }
891+ }
892+ return DecorationOutput {Processors : enhanced }
893+ }),
894+ fx .Invoke (fx .Annotate (
895+ func (processors map [string ]testProcessor ) {
896+ outerProcessors = processors
897+ },
898+ fx .ParamTags (`group:"processors"` ),
899+ )),
900+ fx .Module ("mymodule" ,
901+ fx .Decorate (func (input DecorationInput ) DecorationOutput {
902+ enhanced := make (map [string ]testProcessor )
903+ for name , processor := range input .Processors {
904+ enhanced [name ] = & testEnhancedProcessor {
905+ wrapped : processor ,
906+ prefix : "[INNER]" ,
907+ }
908+ }
909+ return DecorationOutput {Processors : enhanced }
910+ }),
911+ fx .Invoke (fx .Annotate (
912+ func (processors map [string ]testProcessor ) {
913+ innerProcessors = processors
914+ },
915+ fx .ParamTags (`group:"processors"` ),
916+ )),
917+ ),
918+ )
919+ defer app .RequireStart ().RequireStop ()
920+
921+ t .Logf ("Outer processors:" )
922+ for name , p := range outerProcessors {
923+ t .Logf (" %s: %s" , name , p .Process ("data" ))
924+ }
925+ t .Logf ("Inner processors:" )
926+ for name , p := range innerProcessors {
927+ t .Logf (" %s: %s" , name , p .Process ("data" ))
928+ }
929+
930+ // Test that map decoration chains across modules
931+ require .Len (t , outerProcessors , 2 )
932+ assert .Equal (t , "[OUTER] auth: data" , outerProcessors ["auth" ].Process ("data" ))
933+ assert .Equal (t , "[OUTER] billing: data" , outerProcessors ["billing" ].Process ("data" ))
934+
935+ require .Len (t , innerProcessors , 2 )
936+ assert .Equal (t , "[INNER] [OUTER] auth: data" , innerProcessors ["auth" ].Process ("data" ))
937+ assert .Equal (t , "[INNER] [OUTER] billing: data" , innerProcessors ["billing" ].Process ("data" ))
938+ })
856939}
0 commit comments