Skip to content

Commit 70448d1

Browse files
alextwoodsmullermp
andauthored
Update sqs specs for json responses (#2847)
Co-authored-by: Matt Muller <[email protected]>
1 parent 4c7c563 commit 70448d1

File tree

2 files changed

+113
-57
lines changed

2 files changed

+113
-57
lines changed

gems/aws-sdk-sqs/spec/client/verify_checksums_spec.rb

Lines changed: 88 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,25 @@ class Client
5454
let(:md5_of_attributes) { '756d7f4338696745d063b420a2f7e502' }
5555

5656
before(:each) do
57-
response_body = <<-XML
58-
<SendMessageResponse>
59-
<SendMessageResult>
60-
<MD5OfMessageBody>900150983cd24fb0d6963f7d28e17f72</MD5OfMessageBody>
61-
<MD5OfMessageAttributes>#{md5_of_attributes}</MD5OfMessageAttributes>
62-
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
63-
64-
</SendMessageResult>
65-
</SendMessageResponse>
66-
XML
67-
57+
if client.config.api.metadata['protocol'] == 'json'
58+
response_body = <<-JSON
59+
{
60+
"MD5OfMessageAttributes": "#{md5_of_attributes}",
61+
"MD5OfMessageBody": "900150983cd24fb0d6963f7d28e17f72",
62+
"MessageId": "5fea7756-0ea4-451a-a703-a558b933e274"
63+
}
64+
JSON
65+
else
66+
response_body = <<-XML
67+
<SendMessageResponse>
68+
<SendMessageResult>
69+
<MD5OfMessageBody>900150983cd24fb0d6963f7d28e17f72</MD5OfMessageBody>
70+
<MD5OfMessageAttributes>#{md5_of_attributes}</MD5OfMessageAttributes>
71+
<MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId>
72+
</SendMessageResult>
73+
</SendMessageResponse>
74+
XML
75+
end
6876

6977
client.handle(step: :send) do |context|
7078
context.http_response.signal_done(
@@ -159,22 +167,42 @@ class Client
159167
describe '#send_message_batch' do
160168

161169
before(:each) do
162-
client.handle(step: :send) do |context|
163-
context.http_response.signal_done(
164-
status_code: 200,
165-
headers: {},
166-
body:<<-XML)
167-
<SendMessageBatchResponse>
168-
<SendMessageBatchResult>
169-
<SendMessageBatchResultEntry>
170-
<Id>msg-id</Id>
171-
<MD5OfMessageBody>900150983cd24fb0d6963f7d28e17f72</MD5OfMessageBody>
172-
<MD5OfMessageAttributes>756d7f4338696745d063b420a2f7e502</MD5OfMessageAttributes>
173-
</SendMessageBatchResultEntry>
174-
</SendMessageBatchResult>
175-
</SendMessageBatchResponse>
176-
XML
177-
Seahorse::Client::Response.new(context: context)
170+
if client.config.api.metadata['protocol'] == 'json'
171+
client.handle(step: :send) do |context|
172+
context.http_response.signal_done(
173+
status_code: 200,
174+
headers: {},
175+
body:<<-JSON)
176+
{
177+
"Successful": [
178+
{
179+
"Id": "msg-id",
180+
"MD5OfMessageBody": "900150983cd24fb0d6963f7d28e17f72",
181+
"MD5OfMessageAttributes": "756d7f4338696745d063b420a2f7e502"
182+
}
183+
]
184+
}
185+
JSON
186+
Seahorse::Client::Response.new(context: context)
187+
end
188+
else
189+
client.handle(step: :send) do |context|
190+
context.http_response.signal_done(
191+
status_code: 200,
192+
headers: {},
193+
body:<<-XML)
194+
<SendMessageBatchResponse>
195+
<SendMessageBatchResult>
196+
<SendMessageBatchResultEntry>
197+
<Id>msg-id</Id>
198+
<MD5OfMessageBody>900150983cd24fb0d6963f7d28e17f72</MD5OfMessageBody>
199+
<MD5OfMessageAttributes>756d7f4338696745d063b420a2f7e502</MD5OfMessageAttributes>
200+
</SendMessageBatchResultEntry>
201+
</SendMessageBatchResult>
202+
</SendMessageBatchResponse>
203+
XML
204+
Seahorse::Client::Response.new(context: context)
205+
end
178206
end
179207
end
180208

@@ -225,20 +253,39 @@ class Client
225253
end
226254

227255
it 'skips failed errors' do
228-
client.handle(step: :send) do |context|
229-
context.http_response.signal_done(
230-
status_code: 200,
231-
headers: {},
232-
body:<<-XML)
233-
<SendMessageBatchResponse>
234-
<SendMessageBatchResult>
235-
<BatchResultErrorEntry>
236-
<Id>msg-id</Id>
237-
</BatchResultErrorEntry>
238-
</SendMessageBatchResult>
239-
</SendMessageBatchResponse>
240-
XML
241-
Seahorse::Client::Response.new(context: context)
256+
if client.config.api.metadata['protocol'] == 'json'
257+
client.handle(step: :send) do |context|
258+
context.http_response.signal_done(
259+
status_code: 200,
260+
headers: {},
261+
body:<<-JSON)
262+
{
263+
"Successful": [],
264+
"Failed": [
265+
{
266+
"Id": "msg-id"
267+
}
268+
]
269+
}
270+
JSON
271+
Seahorse::Client::Response.new(context: context)
272+
end
273+
else
274+
client.handle(step: :send) do |context|
275+
context.http_response.signal_done(
276+
status_code: 200,
277+
headers: {},
278+
body:<<-XML)
279+
<SendMessageBatchResponse>
280+
<SendMessageBatchResult>
281+
<BatchResultErrorEntry>
282+
<Id>msg-id</Id>
283+
</BatchResultErrorEntry>
284+
</SendMessageBatchResult>
285+
</SendMessageBatchResponse>
286+
XML
287+
Seahorse::Client::Response.new(context: context)
288+
end
242289
end
243290
expect {
244291
client.send_message_batch(

gems/aws-sdk-sqs/spec/client_spec.rb

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,37 @@ module SQS
2020
Aws.config = {}
2121
end
2222

23-
describe 'empty XML result element' do
24-
23+
describe 'empty result element' do
2524
it 'returns a structure with all of the root members' do
26-
client.handle(step: :send) do |context|
27-
context.http_response.signal_done(
28-
status_code: 200,
29-
headers: {},
30-
body:<<-XML)
31-
<ReceiveMessageResponse>
32-
<ReceiveMessageResult/>
33-
<ResponseMetadata>
34-
<RequestId>request-id</RequestId>
35-
</ResponseMetadata>
36-
</ReceiveMessageResponse>
37-
XML
38-
Seahorse::Client::Response.new(context: context)
25+
if client.config.api.metadata['protocol'] == 'json'
26+
client.handle(step: :send) do |context|
27+
context.http_response.signal_done(
28+
status_code: 200,
29+
headers: {},
30+
body: '{"Messages": []}'
31+
)
32+
Seahorse::Client::Response.new(context: context)
33+
end
34+
else
35+
client.handle(step: :send) do |context|
36+
context.http_response.signal_done(
37+
status_code: 200,
38+
headers: {},
39+
body:<<-XML)
40+
<ReceiveMessageResponse>
41+
<ReceiveMessageResult/>
42+
<ResponseMetadata>
43+
<RequestId>request-id</RequestId>
44+
</ResponseMetadata>
45+
</ReceiveMessageResponse>
46+
XML
47+
Seahorse::Client::Response.new(context: context)
48+
end
3949
end
4050
resp = client.receive_message(queue_url: 'https://foo.com')
4151
expect(resp.data.members).to eq([:messages])
4252
expect(resp.data.messages).to eq([])
4353
end
44-
4554
end
4655

4756
describe '#stub_responses' do

0 commit comments

Comments
 (0)