-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
113 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Aws | ||
module Stubbing | ||
class EmptyStub | ||
|
||
include Seahorse::Model::Shapes | ||
|
||
# @param [Seahorse::Models::Shapes::ShapeRef] rules | ||
def initialize(rules) | ||
@rules = rules | ||
end | ||
|
||
# @return [Structure] | ||
def stub | ||
stub_ref(@rules) | ||
end | ||
|
||
private | ||
|
||
def stub_ref(ref, visited = []) | ||
if visited.include?(ref.shape) | ||
return nil | ||
else | ||
visited = visited + [ref.shape] | ||
end | ||
case ref.shape | ||
when StructureShape then stub_structure(ref, visited) | ||
when ListShape then [] | ||
when MapShape then {} | ||
else stub_scalar(ref) | ||
end | ||
end | ||
|
||
def stub_structure(ref, visited) | ||
ref.shape.members.inject(ref[:struct_class].new) do |struct, (mname, mref)| | ||
struct[mname] = stub_ref(mref, visited) | ||
struct | ||
end | ||
end | ||
|
||
def stub_scalar(ref) | ||
case ref.shape | ||
when StringShape then ref.shape.name || 'string' | ||
when IntegerShape then 0 | ||
when FloatShape then 0.0 | ||
when BooleanShape then false | ||
when TimestampShape then Time.now | ||
else nil | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'spec_helper' | ||
require 'stringio' | ||
|
||
module Aws | ||
module Stubbing | ||
describe EmptyStub do | ||
|
||
it 'supports complex recursive structures' do | ||
now = Time.now | ||
allow(Time).to receive(:now).and_return(now) | ||
rules = ApiHelper.sample_shapes | ||
rules = Api::ShapeMap.new(rules).shape_ref('shape' => 'StructureShape') | ||
stub = EmptyStub.new(rules).stub | ||
expect(stub.to_h).to eq({ | ||
nested_list: [], | ||
nested_map: {}, | ||
number_list: [], | ||
string_map: {}, | ||
byte: "ByteShape", | ||
boolean: false, | ||
character: "CharacterShape", | ||
double: 0.0, | ||
float: 0.0, | ||
integer: 0, | ||
long: 0, | ||
string: "StringShape", | ||
timestamp: now, | ||
}) | ||
end | ||
|
||
it 'does not stub paging markers' do | ||
client = S3::Client.new(stub_responses:true) | ||
resp = client.list_objects(bucket:'bucket') | ||
expect(resp.to_h).to eq({ | ||
common_prefixes: [], | ||
contents: [], | ||
delimiter: "Delimiter", | ||
encoding_type: "EncodingType", | ||
is_truncated: false, | ||
marker: "Marker", | ||
max_keys: 0, | ||
name: "BucketName", | ||
prefix: "Prefix", | ||
}) | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.