From 9a52c945135e391ba702f8c6fad4c3f6937ba5bc Mon Sep 17 00:00:00 2001 From: geemus Date: Mon, 3 Jan 2011 18:55:24 -0800 Subject: [PATCH] [aws|simpledb] fixes more granular idempotency convert specs to tests --- .../aws/requests/simpledb/create_domain.rb | 1 + .../requests/simpledb/delete_attributes.rb | 2 - .../aws/requests/simpledb/delete_domain.rb | 1 + .../aws/requests/simpledb/domain_metadata.rb | 1 + .../aws/requests/simpledb/get_attributes.rb | 1 + lib/fog/aws/requests/simpledb/list_domains.rb | 5 +- .../aws/requests/simpledb/put_attributes.rb | 4 +- lib/fog/aws/requests/simpledb/select.rb | 1 + lib/fog/aws/simpledb.rb | 3 +- .../simpledb/batch_put_attributes_spec.rb | 31 -------- .../requests/simpledb/create_domain_spec.rb | 29 ------- .../simpledb/delete_attributes_spec.rb | 39 ---------- .../requests/simpledb/delete_domain_spec.rb | 28 ------- .../requests/simpledb/domain_metadata_spec.rb | 52 ------------- .../requests/simpledb/get_attributes_spec.rb | 67 ----------------- .../requests/simpledb/list_domains_spec.rb | 29 ------- .../requests/simpledb/put_attributes_spec.rb | 49 ------------ spec/aws/requests/simpledb/select_spec.rb | 27 ------- .../aws/requests/simpledb/attributes_tests.rb | 75 +++++++++++++++++++ tests/aws/requests/simpledb/domain_tests.rb | 51 +++++++++++++ tests/aws/requests/simpledb/helper.rb | 16 ++++ 21 files changed, 154 insertions(+), 358 deletions(-) delete mode 100644 spec/aws/requests/simpledb/batch_put_attributes_spec.rb delete mode 100644 spec/aws/requests/simpledb/create_domain_spec.rb delete mode 100644 spec/aws/requests/simpledb/delete_attributes_spec.rb delete mode 100644 spec/aws/requests/simpledb/delete_domain_spec.rb delete mode 100644 spec/aws/requests/simpledb/domain_metadata_spec.rb delete mode 100644 spec/aws/requests/simpledb/get_attributes_spec.rb delete mode 100644 spec/aws/requests/simpledb/list_domains_spec.rb delete mode 100644 spec/aws/requests/simpledb/put_attributes_spec.rb delete mode 100644 spec/aws/requests/simpledb/select_spec.rb create mode 100644 tests/aws/requests/simpledb/attributes_tests.rb create mode 100644 tests/aws/requests/simpledb/domain_tests.rb create mode 100644 tests/aws/requests/simpledb/helper.rb diff --git a/lib/fog/aws/requests/simpledb/create_domain.rb b/lib/fog/aws/requests/simpledb/create_domain.rb index 1078cb34d..c4a2a2a7e 100644 --- a/lib/fog/aws/requests/simpledb/create_domain.rb +++ b/lib/fog/aws/requests/simpledb/create_domain.rb @@ -18,6 +18,7 @@ module Fog request( 'Action' => 'CreateDomain', 'DomainName' => domain_name, + :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) ) end diff --git a/lib/fog/aws/requests/simpledb/delete_attributes.rb b/lib/fog/aws/requests/simpledb/delete_attributes.rb index f2dcd6fae..7fefed80a 100644 --- a/lib/fog/aws/requests/simpledb/delete_attributes.rb +++ b/lib/fog/aws/requests/simpledb/delete_attributes.rb @@ -44,8 +44,6 @@ module Fog @data[:domains][domain_name][key].delete('value') end end - else - @data[:domains].delete(domain_name) end response.status = 200 response.body = { diff --git a/lib/fog/aws/requests/simpledb/delete_domain.rb b/lib/fog/aws/requests/simpledb/delete_domain.rb index f157cfaba..30df4d3d9 100644 --- a/lib/fog/aws/requests/simpledb/delete_domain.rb +++ b/lib/fog/aws/requests/simpledb/delete_domain.rb @@ -18,6 +18,7 @@ module Fog request( 'Action' => 'DeleteDomain', 'DomainName' => domain_name, + :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) ) end diff --git a/lib/fog/aws/requests/simpledb/domain_metadata.rb b/lib/fog/aws/requests/simpledb/domain_metadata.rb index fbe988e5d..515f3a718 100644 --- a/lib/fog/aws/requests/simpledb/domain_metadata.rb +++ b/lib/fog/aws/requests/simpledb/domain_metadata.rb @@ -27,6 +27,7 @@ module Fog request( 'Action' => 'DomainMetadata', 'DomainName' => domain_name, + :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string) ) end diff --git a/lib/fog/aws/requests/simpledb/get_attributes.rb b/lib/fog/aws/requests/simpledb/get_attributes.rb index f2b94e74f..0ba081b78 100644 --- a/lib/fog/aws/requests/simpledb/get_attributes.rb +++ b/lib/fog/aws/requests/simpledb/get_attributes.rb @@ -31,6 +31,7 @@ module Fog 'Action' => 'GetAttributes', 'DomainName' => domain_name, 'ItemName' => item_name, + :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string) }.merge!(encode_attribute_names(attributes))) end diff --git a/lib/fog/aws/requests/simpledb/list_domains.rb b/lib/fog/aws/requests/simpledb/list_domains.rb index a842102a3..0742b4c20 100644 --- a/lib/fog/aws/requests/simpledb/list_domains.rb +++ b/lib/fog/aws/requests/simpledb/list_domains.rb @@ -22,8 +22,9 @@ module Fog # * 'RequestId' def list_domains(options = {}) request({ - 'Action' => 'ListDomains', - :parser => Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string) + 'Action' => 'ListDomains', + :idempotent => true, + :parser => Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string) }.merge!(options)) end diff --git a/lib/fog/aws/requests/simpledb/put_attributes.rb b/lib/fog/aws/requests/simpledb/put_attributes.rb index 0a0ae6afe..deeca8298 100644 --- a/lib/fog/aws/requests/simpledb/put_attributes.rb +++ b/lib/fog/aws/requests/simpledb/put_attributes.rb @@ -30,8 +30,8 @@ module Fog request({ 'Action' => 'PutAttributes', 'DomainName' => domain_name, - :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string), - 'ItemName' => item_name + 'ItemName' => item_name, + :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string) }.merge!(encode_attributes(attributes, options[:replace], options[:expect]))) end diff --git a/lib/fog/aws/requests/simpledb/select.rb b/lib/fog/aws/requests/simpledb/select.rb index 2104be75b..70132e37c 100644 --- a/lib/fog/aws/requests/simpledb/select.rb +++ b/lib/fog/aws/requests/simpledb/select.rb @@ -24,6 +24,7 @@ module Fog 'Action' => 'Select', 'NextToken' => next_token, 'SelectExpression' => select_expression, + :idempotent => true, :parser => Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string) ) end diff --git a/lib/fog/aws/simpledb.rb b/lib/fog/aws/simpledb.rb index 104968469..d76975d41 100644 --- a/lib/fog/aws/simpledb.rb +++ b/lib/fog/aws/simpledb.rb @@ -130,6 +130,7 @@ module Fog end def request(params) + idempotent = params.delete(:idempotent) parser = params.delete(:parser) body = AWS.signed_params( @@ -149,7 +150,7 @@ module Fog :expects => 200, :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :host => @host, - :idempotent => true, + :idempotent => idempotent, :method => 'POST', :parser => parser }) diff --git a/spec/aws/requests/simpledb/batch_put_attributes_spec.rb b/spec/aws/requests/simpledb/batch_put_attributes_spec.rb deleted file mode 100644 index b604245b9..000000000 --- a/spec/aws/requests/simpledb/batch_put_attributes_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.batch_put_attributes' do - describe 'success' do - - before(:all) do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - end - - after(:all) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should return proper attributes' do - actual = AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }) - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - end - - end - describe 'failure' do - - it 'should raise a BadRequest error if the domain does not exist' do - lambda { - AWS[:sdb].batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }) - }.should raise_error(Excon::Errors::BadRequest) - end - - end -end \ No newline at end of file diff --git a/spec/aws/requests/simpledb/create_domain_spec.rb b/spec/aws/requests/simpledb/create_domain_spec.rb deleted file mode 100644 index 7bfe40b82..000000000 --- a/spec/aws/requests/simpledb/create_domain_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.create_domain' do - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - describe 'success' do - - it 'should return proper attributes' do - actual = AWS[:sdb].create_domain(@domain_name) - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - end - - end - describe 'failure' do - - it 'should not raise an error if the domain already exists' do - AWS[:sdb].create_domain(@domain_name) - AWS[:sdb].create_domain(@domain_name) - end - - end -end diff --git a/spec/aws/requests/simpledb/delete_attributes_spec.rb b/spec/aws/requests/simpledb/delete_attributes_spec.rb deleted file mode 100644 index 366ba7a75..000000000 --- a/spec/aws/requests/simpledb/delete_attributes_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.delete_attributes' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => :baz }) - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should return proper attributes from delete_attributes' do - actual = AWS[:sdb].delete_attributes(@domain_name, 'foo') - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - end - - end - describe 'failure' do - - it 'shouild raise a BadRequest error if the domain does not exist' do - lambda { - AWS[:sdb].delete_attributes('notadomain', 'notanattribute') - }.should raise_error(Excon::Errors::BadRequest) - end - - it 'should not raise an error if the attribute does not exist' do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - AWS[:sdb].delete_attributes(@domain_name, 'notanattribute') - AWS[:sdb].delete_domain(@domain_name) - end - - end -end diff --git a/spec/aws/requests/simpledb/delete_domain_spec.rb b/spec/aws/requests/simpledb/delete_domain_spec.rb deleted file mode 100644 index 896160719..000000000 --- a/spec/aws/requests/simpledb/delete_domain_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.delete_domain' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - end - - before(:each) do - AWS[:sdb].create_domain(@domain_name) - end - - it 'should return proper attributes' do - actual = AWS[:sdb].delete_domain(@domain_name) - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - end - - end - describe 'failure' do - - it 'should not raise an error if the domain does not exist' do - AWS[:sdb].delete_domain('notadomain') - end - - end -end diff --git a/spec/aws/requests/simpledb/domain_metadata_spec.rb b/spec/aws/requests/simpledb/domain_metadata_spec.rb deleted file mode 100644 index ae56e4860..000000000 --- a/spec/aws/requests/simpledb/domain_metadata_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.domain_metadata' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should return proper attributes when there are no items' do - results = AWS[:sdb].domain_metadata(@domain_name) - results.body['AttributeNameCount'].should == 0 - results.body['AttributeNamesSizeBytes'].should == 0 - results.body['AttributeValueCount'].should == 0 - results.body['AttributeValuesSizeBytes'].should == 0 - results.body['BoxUsage'].should be_a(Float) - results.body['ItemCount'].should == 0 - results.body['ItemNamesSizeBytes'].should == 0 - results.body['RequestId'].should be_a(String) - results.body['Timestamp'].should be_a(Time) - end - - it 'should return proper attributes with items' do - AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => :baz }) - results = AWS[:sdb].domain_metadata(@domain_name) - results.body['AttributeNameCount'].should == 1 - results.body['AttributeNamesSizeBytes'].should == 3 - results.body['AttributeValueCount'].should == 1 - results.body['AttributeValuesSizeBytes'].should == 3 - results.body['BoxUsage'].should be_a(Float) - results.body['ItemCount'].should == 1 - results.body['ItemNamesSizeBytes'].should == 3 - results.body['RequestId'].should be_a(String) - results.body['Timestamp'].should be_a(Time) - end - - end - describe 'failure' do - - it 'should raise a BadRequest error if the domain does not exist' do - lambda { - AWS[:sdb].domain_metadata('notadomain') - }.should raise_error(Excon::Errors::BadRequest) - end - - end -end diff --git a/spec/aws/requests/simpledb/get_attributes_spec.rb b/spec/aws/requests/simpledb/get_attributes_spec.rb deleted file mode 100644 index 2b3668c3a..000000000 --- a/spec/aws/requests/simpledb/get_attributes_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.get_attributes' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should have no attributes for foo before put_attributes' do - Fog.wait_for do - actual = AWS[:sdb].get_attributes(@domain_name, 'foo') - actual.body['Attributes'].empty? - end - end - - it 'should return multi-value attributes from get_attributes' do - AWS[:sdb].put_attributes(@domain_name, 'buzz', { "attr" => "foo" }) - AWS[:sdb].put_attributes(@domain_name, 'buzz', { "attr" => "foo2" }) - Fog.wait_for do - actual = AWS[:sdb].get_attributes(@domain_name, 'buzz') - actual.body["Attributes"]["attr"] == ['foo', 'foo2'] - end - end - - it 'should have attributes for foo after put_attributes' do - AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => :baz }) - Fog.wait_for do - actual = AWS[:sdb].get_attributes(@domain_name, 'foo') - actual.body['Attributes'] == { 'bar' => ['baz'] } - end - end - - context "foo item is put with bar attribute as an array" do - it "should return the array for foo's bar attribute" do - the_array = %w{A B C} - AWS[:sdb].put_attributes(@domain_name, 'foo', { :bar => the_array }) - Fog.wait_for do - actual = AWS[:sdb].get_attributes(@domain_name, 'foo') - actual.body['Attributes']['bar'] == the_array - end - end - end - - end - describe 'failure' do - - it 'should raise a BadRequest error if the domain does not exist' do - lambda { - AWS[:sdb].get_attributes('notadomain', 'notanattribute') - }.should raise_error(Excon::Errors::BadRequest) - end - - it 'should not raise an error if the attribute does not exist' do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - AWS[:sdb].get_attributes(@domain_name, 'notanattribute') - AWS[:sdb].delete_domain(@domain_name) - end - - end -end diff --git a/spec/aws/requests/simpledb/list_domains_spec.rb b/spec/aws/requests/simpledb/list_domains_spec.rb deleted file mode 100644 index 9fbaab0a0..000000000 --- a/spec/aws/requests/simpledb/list_domains_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.list_domains' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should return proper attributes' do - results = AWS[:sdb].list_domains - results.body['BoxUsage'].should be_a(Float) - results.body['Domains'].should be_an(Array) - results.body['RequestId'].should be_a(String) - end - - it 'should include created domains' do - AWS[:sdb].create_domain(@domain_name) - Fog.wait_for do - AWS[:sdb].list_domains.body['Domains'].include?(@domain_name) - end - end - - end -end diff --git a/spec/aws/requests/simpledb/put_attributes_spec.rb b/spec/aws/requests/simpledb/put_attributes_spec.rb deleted file mode 100644 index 2d25354e5..000000000 --- a/spec/aws/requests/simpledb/put_attributes_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.put_attributes' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should return proper attributes from put_attributes' do - actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'bar' => 'baz' }) - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - end - - it 'conditional put should succeed' do - AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '1' }) - AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']) - actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '3' }, :expect => { 'version' => '2' }, :replace => ['version']) - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - end - - it 'conditional put should raise Conflict error' do - actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '2' }, :replace => ['version']) - actual.body['RequestId'].should be_a(String) - actual.body['BoxUsage'].should be_a(Float) - - lambda { - actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']) - }.should raise_error(Excon::Errors::Conflict) - end - - end - describe 'failure' do - - it 'should raise a BadRequest error if the domain does not exist' do - lambda { - AWS[:sdb].put_attributes(@domain_name, 'notadomain', { 'notanattribute' => 'value' }) - }.should raise_error(Excon::Errors::BadRequest) - end - - end -end diff --git a/spec/aws/requests/simpledb/select_spec.rb b/spec/aws/requests/simpledb/select_spec.rb deleted file mode 100644 index 1dd5b05b7..000000000 --- a/spec/aws/requests/simpledb/select_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require File.dirname(__FILE__) + '/../../../spec_helper' - -describe 'SimpleDB.select' do - describe 'success' do - - before(:each) do - @domain_name = "fog_domain_#{Time.now.to_i}" - AWS[:sdb].create_domain(@domain_name) - end - - after(:each) do - AWS[:sdb].delete_domain(@domain_name) - end - - it 'should return multi-value attributes when present' do - pending if Fog.mocking? - @item = "someitem_fog_domain_#{Time.now.to_i}" - AWS[:sdb].put_attributes(@domain_name, @item, { "attr" => "foo" }) - AWS[:sdb].put_attributes(@domain_name, @item, { "attr" => "foo2" }) - Fog.wait_for do - actual = AWS[:sdb].select("select * from #{@domain_name}") - actual.body['Items'][@item]["attr"] == ['foo','foo2'] - end - end - - end -end diff --git a/tests/aws/requests/simpledb/attributes_tests.rb b/tests/aws/requests/simpledb/attributes_tests.rb new file mode 100644 index 000000000..e111de92a --- /dev/null +++ b/tests/aws/requests/simpledb/attributes_tests.rb @@ -0,0 +1,75 @@ +Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do + + @domain_name = "fog_domain_#{Time.now.to_f.to_s.gsub('.','')}" + + AWS[:sdb].create_domain(@domain_name) + + tests('success') do + + tests("#batch_put_attributes('#{@domain_name}', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }).body").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }).body + end + + tests("#get_attributes('#{@domain_name}', 'a').body['Attributes']").returns({'b' => ['c']}) do + attributes = {} + Fog.wait_for { + attributes = AWS[:sdb].get_attributes(@domain_name, 'a').body['Attributes'] + attributes != {} + } + attributes + end + + tests("#get_attributes('#{@domain_name}', 'notanattribute')").succeeds do + AWS[:sdb].get_attributes(@domain_name, 'notanattribute') + end + + tests("#select('select * from #{@domain_name}').body['Items']").returns({ 'a' => { 'b' => ['c'] }, 'x' => { 'y' => ['z'] } }) do + pending if Fog.mocking? + AWS[:sdb].select("select * from #{@domain_name}").body['Items'] + end + + tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '1' }).body").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].put_attributes(@domain_name, 'conditional', { 'version' => '1' }).body + end + + tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']).body").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].put_attributes(@domain_name, 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']).body + end + + tests("#delete_attributes('#{@domain_name}', 'a').body").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].delete_attributes(@domain_name, 'a').body + end + + tests("#delete_attributes('#{@domain_name}', 'a').body").succeeds do + AWS[:sdb].delete_attributes(@domain_name, 'a').body + end + + end + + tests('failure') do + + tests("#batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })").raises(Excon::Errors::BadRequest) do + AWS[:sdb].batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }) + end + + tests("#get_attributes('notadomain', 'a')").raises(Excon::Errors::BadRequest) do + AWS[:sdb].get_attributes('notadomain', 'a') + end + + tests("#put_attributes('notadomain', 'conditional', { 'version' => '1' })").raises(Excon::Errors::BadRequest) do + AWS[:sdb].put_attributes('notadomain', 'foo', { 'version' => '1' }) + end + + tests("#put_attributes('#{@domain_name}', 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version'])").raises(Excon::Errors::Conflict) do + AWS[:sdb].put_attributes(@domain_name, 'conditional', { 'version' => '2' }, :expect => { 'version' => '1' }, :replace => ['version']) + end + + tests("#delete_attributes('notadomain', 'a')").raises(Excon::Errors::BadRequest) do + AWS[:sdb].delete_attributes('notadomain', 'a') + end + + end + + AWS[:sdb].delete_domain(@domain_name) + +end diff --git a/tests/aws/requests/simpledb/domain_tests.rb b/tests/aws/requests/simpledb/domain_tests.rb new file mode 100644 index 000000000..fbabf298a --- /dev/null +++ b/tests/aws/requests/simpledb/domain_tests.rb @@ -0,0 +1,51 @@ +Shindo.tests('AWS::SimpleDB | domain requests', ['aws']) do + + @domain_metadata_format = AWS::SimpleDB::Formats::BASIC.merge({ + 'AttributeNameCount' => Integer, + 'AttributeNamesSizeBytes' => Integer, + 'AttributeValueCount' => Integer, + 'AttributeValuesSizeBytes' => Integer, + 'ItemCount' => Integer, + 'ItemNamesSizeBytes' => Integer, + 'Timestamp' => Time + }) + + @domain_name = "fog_domain_#{Time.now.to_f.to_s.gsub('.','')}" + + tests('success') do + + tests("#create_domain(#{@domain_name})").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].create_domain(@domain_name).body + end + + tests("#create_domain(#{@domain_name})").succeeds do + AWS[:sdb].create_domain(@domain_name) + end + + tests("#domain_metadata(#{@domain_name})").formats(@domain_metadata_format) do + AWS[:sdb].domain_metadata(@domain_name).body + end + + tests("#list_domains").formats(AWS::SimpleDB::Formats::BASIC.merge('Domains' => [String])) do + AWS[:sdb].list_domains.body + end + + tests("#delete_domain(#{@domain_name})").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].delete_domain(@domain_name).body + end + + tests("#delete_domain(#{@domain_name})").succeeds do + AWS[:sdb].delete_domain(@domain_name) + end + + end + + tests('failure') do + + tests("#domain_metadata('notadomain')").raises(Excon::Errors::BadRequest) do + AWS[:sdb].domain_metadata('notadomain') + end + + end + +end diff --git a/tests/aws/requests/simpledb/helper.rb b/tests/aws/requests/simpledb/helper.rb new file mode 100644 index 000000000..8c5d71016 --- /dev/null +++ b/tests/aws/requests/simpledb/helper.rb @@ -0,0 +1,16 @@ +class AWS + + module SimpleDB + + module Formats + + BASIC = { + 'BoxUsage' => Float, + 'RequestId' => String + } + + end + + end + +end