@@ -2,6 +2,7 @@ package smoke_tests
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"io"
6
7
"net/http"
7
8
"net/http/httptest"
@@ -11,13 +12,16 @@ import (
11
12
"github.com/aws/aws-sdk-go-v2/config"
12
13
13
14
"github.com/Admiral-Piett/goaws/app/conf"
15
+ af "github.com/Admiral-Piett/goaws/app/fixtures"
14
16
"github.com/Admiral-Piett/goaws/app/test"
15
17
16
18
"github.com/gavv/httpexpect/v2"
17
19
18
20
"github.com/Admiral-Piett/goaws/app"
19
21
"github.com/aws/aws-sdk-go-v2/aws"
20
22
"github.com/aws/aws-sdk-go-v2/service/sns"
23
+ "github.com/aws/aws-sdk-go-v2/service/sns/types"
24
+ "github.com/aws/aws-sdk-go-v2/service/sqs"
21
25
"github.com/stretchr/testify/assert"
22
26
)
23
27
@@ -52,6 +56,74 @@ func Test_Publish_sqs_json_raw(t *testing.T) {
52
56
assert .Equal (t , message , string (messages [0 ].MessageBody ))
53
57
}
54
58
59
+ func Test_Publish_Sqs_With_Message_Attributes (t * testing.T ) {
60
+ server := generateServer ()
61
+ defer func () {
62
+ server .Close ()
63
+ test .ResetResources ()
64
+ }()
65
+
66
+ sdkConfig , _ := config .LoadDefaultConfig (context .TODO ())
67
+ sdkConfig .BaseEndpoint = aws .String (server .URL )
68
+ sqsClient := sqs .NewFromConfig (sdkConfig )
69
+ snsClient := sns .NewFromConfig (sdkConfig )
70
+
71
+ createQueueResult , _ := sqsClient .CreateQueue (context .TODO (), & sqs.CreateQueueInput {
72
+ QueueName : & af .QueueName ,
73
+ })
74
+
75
+ topicName := aws .String ("unit-topic2" )
76
+
77
+ createTopicResult , _ := snsClient .CreateTopic (context .TODO (), & sns.CreateTopicInput {
78
+ Name : topicName ,
79
+ })
80
+
81
+ snsClient .Subscribe (context .TODO (), & sns.SubscribeInput {
82
+ Protocol : aws .String ("sqs" ),
83
+ TopicArn : createTopicResult .TopicArn ,
84
+ Attributes : map [string ]string {},
85
+ Endpoint : createQueueResult .QueueUrl ,
86
+ ReturnSubscriptionArn : true ,
87
+ })
88
+ message := "{\" IAm\" : \" aMessage\" }"
89
+ subject := "I am a subject"
90
+ attributes := map [string ]types.MessageAttributeValue {
91
+ "someKey" : {
92
+ BinaryValue : []byte (message ),
93
+ DataType : aws .String ("Binary" ),
94
+ },
95
+ }
96
+
97
+ publishResponse , publishErr := snsClient .Publish (context .TODO (), & sns.PublishInput {
98
+ TopicArn : createTopicResult .TopicArn ,
99
+ Message : & message ,
100
+ Subject : & subject ,
101
+ MessageAttributes : attributes ,
102
+ })
103
+
104
+ receiveMessageResponse , receiveErr := sqsClient .ReceiveMessage (context .TODO (), & sqs.ReceiveMessageInput {
105
+ QueueUrl : createQueueResult .QueueUrl ,
106
+ })
107
+
108
+ type Message struct {
109
+ Message string `json:"Message"`
110
+ Subject string `json:"Subject"`
111
+ }
112
+
113
+ var receiveMessage Message
114
+
115
+ assert .Nil (t , publishErr )
116
+ assert .NotNil (t , publishResponse )
117
+
118
+ assert .Nil (t , receiveErr )
119
+ assert .NotNil (t , receiveMessageResponse )
120
+
121
+ body := * receiveMessageResponse .Messages [0 ].Body
122
+ json .Unmarshal ([]byte (body ), & receiveMessage )
123
+ assert .Equal (t , message , receiveMessage .Message )
124
+ assert .Equal (t , subject , receiveMessage .Subject )
125
+ }
126
+
55
127
func Test_Publish_sqs_json_not_raw (t * testing.T ) {
56
128
server := generateServer ()
57
129
defaultEnv := app .CurrentEnvironment
0 commit comments