@@ -566,3 +566,81 @@ func TestSubscribeRequest_SetAttributesFromForm_stops_if_attributes_not_numbered
566
566
assert .False (t , cqr .Attributes .RawMessageDelivery )
567
567
assert .Equal (t , FilterPolicy (nil ), cqr .Attributes .FilterPolicy )
568
568
}
569
+
570
+ func TestParseMessageAttributes (t * testing.T ) {
571
+ for _ , tc := range []struct {
572
+ description string
573
+ values url.Values
574
+ keyPrefix string
575
+ want map [string ]MessageAttribute
576
+ }{
577
+ {
578
+ description : "empty" ,
579
+ values : url.Values {},
580
+ keyPrefix : "foo" ,
581
+ want : nil ,
582
+ },
583
+ {
584
+ description : "simple" ,
585
+ values : url.Values {
586
+ "MessageAttribute.1.Name" : []string {"Attr1" },
587
+ "MessageAttribute.1.Value.DataType" : []string {"String" },
588
+ "MessageAttribute.1.Value.StringValue" : []string {"Value1" },
589
+ "MessageAttribute.2.Name" : []string {"Attr2" },
590
+ "MessageAttribute.2.Value.DataType" : []string {"Binary" },
591
+ "MessageAttribute.2.Value.BinaryValue" : []string {"VmFsdWUy" },
592
+ },
593
+ keyPrefix : "MessageAttribute" ,
594
+ want : map [string ]MessageAttribute {
595
+ "Attr1" : {
596
+ DataType : "String" ,
597
+ StringValue : "Value1" ,
598
+ BinaryValue : []byte {},
599
+ },
600
+ "Attr2" : {
601
+ DataType : "Binary" ,
602
+ BinaryValue : []byte ("VmFsdWUy" ),
603
+ },
604
+ },
605
+ },
606
+ {
607
+ description : "attributes after empty name ignored" ,
608
+ values : url.Values {
609
+ "MessageAttribute.1.Name" : []string {"" },
610
+ "MessageAttribute.1.Value.DataType" : []string {"String" },
611
+ "MessageAttribute.1.Value.StringValue" : []string {"Value4" },
612
+ "MessageAttribute.2.Name" : []string {"Attr2" },
613
+ "MessageAttribute.2.Value.DataType" : []string {"Binary" },
614
+ "MessageAttribute.2.Value.BinaryValue" : []string {"VmFsdWUy" },
615
+ },
616
+ keyPrefix : "MessageAttribute" ,
617
+ want : nil ,
618
+ },
619
+ {
620
+ description : "attributes after missing number ignored" ,
621
+ values : url.Values {
622
+ // Note starting from 2
623
+ "MessageAttribute.2.Name" : []string {"Attr2" },
624
+ "MessageAttribute.2.Value.DataType" : []string {"Binary" },
625
+ "MessageAttribute.2.Value.BinaryValue" : []string {"VmFsdWUy" },
626
+ },
627
+ keyPrefix : "MessageAttribute" ,
628
+ want : nil ,
629
+ },
630
+ {
631
+ description : "empty DataType ignored" ,
632
+ values : url.Values {
633
+ "MessageAttribute.1.Name" : []string {"Attr4" },
634
+ "MessageAttribute.1.Value.DataType" : []string {"" },
635
+ "MessageAttribute.1.Value.StringValue" : []string {"Value4" },
636
+ },
637
+ keyPrefix : "MessageAttribute" ,
638
+ want : nil ,
639
+ },
640
+ } {
641
+ t .Run (tc .description , func (t * testing.T ) {
642
+ got := parseMessageAttributes (tc .values , tc .keyPrefix )
643
+ assert .Equal (t , tc .want , got )
644
+ })
645
+ }
646
+ }
0 commit comments