@@ -508,3 +508,77 @@ func Test_buildARN_NonStandardPartition(t *testing.T) {
508508 arn := ps .buildARN ("sns" , "myTopic" )
509509 r .Equal ("arn:aws-cn:sns:cn-northwest-1:123456789012:myTopic" , arn )
510510}
511+
512+ func Test_getMessageGroupID (t * testing.T ) {
513+ t .Parallel ()
514+
515+ fixtures := []struct {
516+ name string
517+ componentProps map [string ]string
518+ requestMetadata map [string ]string
519+ expectedGroupID string
520+ }{
521+ {
522+ name : "Request with fifoMessageGroupId" ,
523+ componentProps : map [string ]string {"fifoMessageGroupID" : "component-group-id" },
524+ requestMetadata : map [string ]string {"fifoMessageGroupID" : "request-group-id" },
525+ expectedGroupID : "request-group-id" ,
526+ },
527+ {
528+ name : "Request with blank fifoMessageGroupId" ,
529+ componentProps : map [string ]string {"fifoMessageGroupID" : "component-group-id" },
530+ requestMetadata : map [string ]string {"fifoMessageGroupID" : "" },
531+ expectedGroupID : "component-group-id" ,
532+ },
533+ {
534+ name : "Request without fifoMessageGroupId" ,
535+ componentProps : map [string ]string {"fifoMessageGroupID" : "component-group-id" },
536+ requestMetadata : map [string ]string {},
537+ expectedGroupID : "component-group-id" ,
538+ },
539+ {
540+ name : "Component without fifoMessageGroupId" ,
541+ componentProps : map [string ]string {},
542+ requestMetadata : map [string ]string {},
543+ // Should be the default generated value
544+ expectedGroupID : "c" ,
545+ },
546+ }
547+
548+ for _ , f := range fixtures {
549+ t .Run (f .name , func (t * testing.T ) {
550+ r := require .New (t )
551+ l := logger .NewLogger ("SnsSqs unit test" )
552+ l .SetOutputLevel (logger .DebugLevel )
553+ ps := snsSqs {
554+ logger : l ,
555+ id : f .name ,
556+ }
557+
558+ props := map [string ]string {
559+ "consumerID" : "c" ,
560+ "accessKey" : "a" ,
561+ "secretKey" : "s" ,
562+ "fifo" : "true" ,
563+ }
564+ for k , v := range f .componentProps {
565+ props [k ] = v
566+ }
567+
568+ md , err := ps .getSnsSqsMetadata (pubsub.Metadata {
569+ Base : metadata.Base {Properties : props },
570+ })
571+
572+ r .NoError (err )
573+ ps .metadata = md
574+
575+ req := pubsub.PublishRequest {
576+ Metadata : f .requestMetadata ,
577+ PubsubName : "test-pubsub" ,
578+ Topic : "test-topic" ,
579+ }
580+ groupID := ps .getMessageGroupID (& req )
581+ r .Equal (f .expectedGroupID , * groupID )
582+ })
583+ }
584+ }
0 commit comments