@@ -621,3 +621,81 @@ func Test_DeleteMessageBatchRequest_SetAttributesFromForm_stops_at_invalid_keys(
621
621
assert .Equal (t , "message-id-1" , dmbr .Entries [0 ].Id )
622
622
assert .Equal (t , "receipt-handle-1" , dmbr .Entries [0 ].ReceiptHandle )
623
623
}
624
+
625
+ func TestParseMessageAttributes (t * testing.T ) {
626
+ for _ , tc := range []struct {
627
+ description string
628
+ values url.Values
629
+ keyPrefix string
630
+ want map [string ]MessageAttribute
631
+ }{
632
+ {
633
+ description : "empty" ,
634
+ values : url.Values {},
635
+ keyPrefix : "foo" ,
636
+ want : nil ,
637
+ },
638
+ {
639
+ description : "simple" ,
640
+ values : url.Values {
641
+ "MessageAttribute.1.Name" : []string {"Attr1" },
642
+ "MessageAttribute.1.Value.DataType" : []string {"String" },
643
+ "MessageAttribute.1.Value.StringValue" : []string {"Value1" },
644
+ "MessageAttribute.2.Name" : []string {"Attr2" },
645
+ "MessageAttribute.2.Value.DataType" : []string {"Binary" },
646
+ "MessageAttribute.2.Value.BinaryValue" : []string {"VmFsdWUy" },
647
+ },
648
+ keyPrefix : "MessageAttribute" ,
649
+ want : map [string ]MessageAttribute {
650
+ "Attr1" : {
651
+ DataType : "String" ,
652
+ StringValue : "Value1" ,
653
+ BinaryValue : []byte {},
654
+ },
655
+ "Attr2" : {
656
+ DataType : "Binary" ,
657
+ BinaryValue : []byte ("VmFsdWUy" ),
658
+ },
659
+ },
660
+ },
661
+ {
662
+ description : "attributes after empty name ignored" ,
663
+ values : url.Values {
664
+ "MessageAttribute.1.Name" : []string {"" },
665
+ "MessageAttribute.1.Value.DataType" : []string {"String" },
666
+ "MessageAttribute.1.Value.StringValue" : []string {"Value4" },
667
+ "MessageAttribute.2.Name" : []string {"Attr2" },
668
+ "MessageAttribute.2.Value.DataType" : []string {"Binary" },
669
+ "MessageAttribute.2.Value.BinaryValue" : []string {"VmFsdWUy" },
670
+ },
671
+ keyPrefix : "MessageAttribute" ,
672
+ want : nil ,
673
+ },
674
+ {
675
+ description : "attributes after missing number ignored" ,
676
+ values : url.Values {
677
+ // Note starting from 2
678
+ "MessageAttribute.2.Name" : []string {"Attr2" },
679
+ "MessageAttribute.2.Value.DataType" : []string {"Binary" },
680
+ "MessageAttribute.2.Value.BinaryValue" : []string {"VmFsdWUy" },
681
+ },
682
+ keyPrefix : "MessageAttribute" ,
683
+ want : nil ,
684
+ },
685
+ {
686
+ description : "empty DataType ignored" ,
687
+ values : url.Values {
688
+ "MessageAttribute.1.Name" : []string {"Attr4" },
689
+ "MessageAttribute.1.Value.DataType" : []string {"" },
690
+ "MessageAttribute.1.Value.StringValue" : []string {"Value4" },
691
+ },
692
+ keyPrefix : "MessageAttribute" ,
693
+ want : nil ,
694
+ },
695
+ } {
696
+ t .Run (tc .description , func (t * testing.T ) {
697
+ got := parseMessageAttributes (tc .values , tc .keyPrefix )
698
+ assert .Equal (t , tc .want , got )
699
+ })
700
+ }
701
+ }
0 commit comments