@@ -508,3 +508,164 @@ 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_RequestMessageGroupId (t * testing.T ) {
513+ t .Parallel ()
514+ r := require .New (t )
515+ l := logger .NewLogger ("SnsSqs unit test" )
516+ l .SetOutputLevel (logger .DebugLevel )
517+ ps := snsSqs {
518+ logger : l ,
519+ id : "test-id" ,
520+ }
521+
522+ md , err := ps .getSnsSqsMetadata (pubsub.Metadata {Base : metadata.Base {Properties : map [string ]string {
523+ "consumerID" : "c" ,
524+ "accessKey" : "a" ,
525+ "secretKey" : "s" ,
526+ "fifo" : "true" ,
527+ "fifoMessageGroupID" : "test-group-id" ,
528+ }}})
529+ r .NoError (err )
530+ ps .metadata = md
531+
532+ req := pubsub.PublishRequest {
533+ Metadata : map [string ]string {"fifoMessageGroupID" : "request-group-id" },
534+ PubsubName : "test-pubsub" ,
535+ Topic : "test-topic" ,
536+ }
537+ groupID := ps .getMessageGroupID (& req )
538+ r .Equal ("request-group-id" , * groupID )
539+ }
540+
541+ func Test_getMessageGroupID_BlankRequestMessgeGroupId (t * testing.T ) {
542+ t .Parallel ()
543+ r := require .New (t )
544+ l := logger .NewLogger ("SnsSqs unit test" )
545+ l .SetOutputLevel (logger .DebugLevel )
546+ ps := snsSqs {
547+ logger : l ,
548+ id : "test-id" ,
549+ }
550+
551+ md , err := ps .getSnsSqsMetadata (pubsub.Metadata {Base : metadata.Base {Properties : map [string ]string {
552+ "consumerID" : "c" ,
553+ "accessKey" : "a" ,
554+ "secretKey" : "s" ,
555+ "fifo" : "true" ,
556+ "fifoMessageGroupID" : "test-group-id" ,
557+ }}})
558+ r .NoError (err )
559+ ps .metadata = md
560+
561+ req := pubsub.PublishRequest {
562+ Metadata : map [string ]string {"fifoMessageGroupID" : "" },
563+ PubsubName : "test-pubsub" ,
564+ Topic : "test-topic" ,
565+ }
566+ groupID := ps .getMessageGroupID (& req )
567+ r .Equal ("test-group-id" , * groupID )
568+ }
569+
570+ func Test_getMessageGroupID_NoRequestMessageGroupId (t * testing.T ) {
571+ t .Parallel ()
572+ r := require .New (t )
573+ l := logger .NewLogger ("SnsSqs unit test" )
574+ l .SetOutputLevel (logger .DebugLevel )
575+ ps := snsSqs {
576+ logger : l ,
577+ id : "test-id" ,
578+ }
579+
580+ md , err := ps .getSnsSqsMetadata (pubsub.Metadata {Base : metadata.Base {Properties : map [string ]string {
581+ "consumerID" : "c" ,
582+ "accessKey" : "a" ,
583+ "secretKey" : "s" ,
584+ "fifo" : "true" ,
585+ "fifoMessageGroupID" : "test-group-id" ,
586+ }}})
587+ r .NoError (err )
588+ ps .metadata = md
589+
590+ req := pubsub.PublishRequest {
591+ Metadata : map [string ]string {},
592+ PubsubName : "test-pubsub" ,
593+ Topic : "test-topic" ,
594+ }
595+ groupID := ps .getMessageGroupID (& req )
596+ r .Equal ("test-group-id" , * groupID )
597+ }
598+
599+ func Test_getMessageGroupID (t * testing.T ) {
600+ t .Parallel ()
601+
602+ fixtures := []struct {
603+ name string
604+ componentProps map [string ]string
605+ requestMetadata map [string ]string
606+ expectedGroupID string
607+ }{
608+ {
609+ name : "Request with fifoMessageGroupId" ,
610+ componentProps : map [string ]string {"fifoMessageGroupID" : "component-group-id" },
611+ requestMetadata : map [string ]string {"fifoMessageGroupID" : "request-group-id" },
612+ expectedGroupID : "request-group-id" ,
613+ },
614+ {
615+ name : "Request with blank fifoMessageGroupId" ,
616+ componentProps : map [string ]string {"fifoMessageGroupID" : "component-group-id" },
617+ requestMetadata : map [string ]string {"fifoMessageGroupID" : "" },
618+ expectedGroupID : "component-group-id" ,
619+ },
620+ {
621+ name : "Request without fifoMessageGroupId" ,
622+ componentProps : map [string ]string {"fifoMessageGroupID" : "component-group-id" },
623+ requestMetadata : map [string ]string {},
624+ expectedGroupID : "component-group-id" ,
625+ },
626+ {
627+ name : "Component without fifoMessageGroupId" ,
628+ componentProps : map [string ]string {},
629+ requestMetadata : map [string ]string {},
630+ // Should be the default generated value
631+ expectedGroupID : "c" ,
632+ },
633+ }
634+
635+ for _ , f := range fixtures {
636+ t .Run (f .name , func (t * testing.T ) {
637+ r := require .New (t )
638+ l := logger .NewLogger ("SnsSqs unit test" )
639+ l .SetOutputLevel (logger .DebugLevel )
640+ ps := snsSqs {
641+ logger : l ,
642+ id : f .name ,
643+ }
644+
645+ props := map [string ]string {
646+ "consumerID" : "c" ,
647+ "accessKey" : "a" ,
648+ "secretKey" : "s" ,
649+ "fifo" : "true" ,
650+ }
651+ for k , v := range f .componentProps {
652+ props [k ] = v
653+ }
654+
655+ md , err := ps .getSnsSqsMetadata (pubsub.Metadata {
656+ Base : metadata.Base {Properties : props },
657+ })
658+
659+ r .NoError (err )
660+ ps .metadata = md
661+
662+ req := pubsub.PublishRequest {
663+ Metadata : f .requestMetadata ,
664+ PubsubName : "test-pubsub" ,
665+ Topic : "test-topic" ,
666+ }
667+ groupID := ps .getMessageGroupID (& req )
668+ r .Equal (f .expectedGroupID , * groupID )
669+ })
670+ }
671+ }
0 commit comments