Skip to content

Commit

Permalink
Add sample rpcv2 cbor model and error handler spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Oct 15, 2024
1 parent dcec497 commit dd8408a
Show file tree
Hide file tree
Showing 5 changed files with 3,778 additions and 102 deletions.
8 changes: 8 additions & 0 deletions gems/aws-sdk-core/spec/api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def sample_ec2 # ec2 has its own protocol
end
end

def sample_rpcv2_cbor # cloudwatch logs changed to cbor
@sample_rpcv2_cbor ||= begin
api = File.expand_path('../fixtures/apis/logs.json', __FILE__)
api = JSON.load(File.read(api))
sample_service(api: api)
end
end

def sample_shapes
{
'StructureShape' => {
Expand Down
4 changes: 2 additions & 2 deletions gems/aws-sdk-core/spec/aws/json/error_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Json
JSON

let(:unmodeled_error_resp) { <<~JSON.strip }
let(:un_modeled_error_resp) { <<~JSON.strip }
{
"__type":"UnModeledException",
"message":"foo"
Expand Down Expand Up @@ -69,7 +69,7 @@ module Json
it 'extracts code and message for unmodeled errors' do
client.stub_responses(
:batch_get_item,
{ status_code: 400, body: unmodeled_error_resp, headers: {} }
{ status_code: 400, body: un_modeled_error_resp, headers: {} }
)

expect { client.batch_get_item(request_items: {}) }
Expand Down
129 changes: 129 additions & 0 deletions gems/aws-sdk-core/spec/aws/rpc_v2/error_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# frozen_string_literal: true

require_relative '../../spec_helper'

module Aws
module RpcV2
describe ErrorHandler do
let(:client) do
ApiHelper.sample_rpcv2_cbor::Client.new(stub_responses: true)
end

let(:error_resp) do
Cbor.encode(
{
"__type": 'ServiceUnavailableException',
"message": 'foo',
"foo": 'bar'
}
)
end

let(:invalid_error_resp) do
Cbor.encode(
{
"__type": 'ServiceUnavailableException:',
"message": 'foo',
"foo": 'bar'
}
)
end

let(:un_modeled_error_resp) do
Cbor.encode(
{
"__type": 'UnModeledException',
"message": 'foo'
}
)
end

let(:empty_struct_error_resp) do
Cbor.encode(
{
"__type": 'EmptyStructError',
"message": 'foo'
}
)
end

it 'extracts error data' do
client.stub_responses(
:describe_log_groups,
{
status_code: 400,
headers: {
'smithy-protocol' => 'rpc-v2-cbor'
},
body: error_resp
}
)

expect { client.describe_log_groups }
.to raise_error do |e|
expect(e.code).to eq('ServiceUnavailableException')
expect(e.message).to eq('foo')
expect(e.foo).to eq('bar')
end
end

it 'ignore invalid characters when matching' do
client.stub_responses(
:describe_log_groups,
{
status_code: 400,
headers: {
'smithy-protocol' => 'rpc-v2-cbor'
},
body: invalid_error_resp
}
)

expect { client.describe_log_groups }
.to raise_error do |e|
expect(e.code).to eq('ServiceUnavailableException')
expect(e.message).to eq('foo')
expect(e.foo).to eq('bar')
end
end

it 'extracts code and message for unmodeled errors' do
client.stub_responses(
:describe_log_groups,
{
status_code: 400,
headers: {
'smithy-protocol' => 'rpc-v2-cbor'
},
body: un_modeled_error_resp
}
)

expect { client.describe_log_groups }
.to raise_error do |e|
expect(e.code).to eq('UnModeledException')
expect(e.message).to eq('foo')
end
end

it 'extracts code and message for modeled empty struct errors' do
client.stub_responses(
:describe_log_groups,
{
status_code: 400,
headers: {
'smithy-protocol' => 'rpc-v2-cbor'
},
body: empty_struct_error_resp
}
)

expect { client.describe_log_groups }
.to raise_error do |e|
expect(e.code).to eq('EmptyStructError')
expect(e.message).to eq('foo')
end
end
end
end
end
100 changes: 0 additions & 100 deletions gems/aws-sdk-core/spec/fixtures/api/swf.json

This file was deleted.

Loading

0 comments on commit dd8408a

Please sign in to comment.