Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added unit tests for RDS::DBSnapshotCollection.

  • Loading branch information...
commit 48a9f67301b5405a9ee0cbb493f00948ab39abfd 1 parent 4786030
@trevorrowe trevorrowe authored
View
17 lib/aws/rds/db_snapshot_collection.rb
@@ -29,11 +29,22 @@ def [] db_snapshot_id
DBSnapshot.new(db_snapshot_id, :config => config)
end
- def with_id db_instance_id
- filter(:db_instance_identifier, db_instance_id)
+ # Filters the DB snapshots to those beloning to a single db instance.
+ # You may pass the ID of a db instance or a {DBInstance} object.
+ #
+ # @param [String,DBInstance] db_instance A db instance identifier
+ # string or a {DBInstance} object.
+ #
+ # @return [DBSnapshotCollection]
+ #
+ def db_instance db_instance
+ id = db_instance.is_a?(Core::Model) ? db_instance.id : db_instance
+ filter(:db_instance_identifier, id.to_s.downcase)
end
- alias_method :db_instance, :with_id
+ # Filters the DB snapshots to those of a given snapshot type.
+ # @param [String] snapshot_type
+ # @return [DBSnapshotCollection]
def with_type snapshot_type
filter(:snapshot_type, snapshot_type)
end
View
146 spec/aws/rds/db_snapshot_collection_spec.rb
@@ -0,0 +1,146 @@
+# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"). You
+# may not use this file except in compliance with the License. A copy of
+# the License is located at
+#
+# http://aws.amazon.com/apache2.0/
+#
+# or in the "license" file accompanying this file. This file is
+# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+# ANY KIND, either express or implied. See the License for the specific
+# language governing permissions and limitations under the License.
+
+require 'spec_helper'
+
+module AWS
+ class RDS
+ describe DBSnapshotCollection do
+
+ let(:config) { stub_config }
+
+ let(:client) { config.rds_client }
+
+ let(:snapshots) { DBSnapshotCollection.new(:config => config) }
+
+ context '#[]' do
+
+ it 'returns a DBSnapshot' do
+ snapshots['abc'].should be_a(DBSnapshot)
+ end
+
+ it 'has the correct configuration' do
+ snapshots['abc'].config.should eq(snapshots.config)
+ end
+
+ end
+
+ context '#db_instance' do
+
+ it 'returns another snapshot collection' do
+ snapshots.db_instance('abc').should be_a(DBSnapshotCollection)
+ end
+
+ it 'returns a collection with the correct config)' do
+ snapshots.db_instance('abc').config.should eq(config)
+ end
+
+ it 'returns a collection that filters by the db instance id' do
+
+ client.should_receive(:describe_db_snapshots).
+ with(:db_instance_identifier => 'abc').
+ and_return(client.stub_for(:describe_db_snapshots))
+
+ snapshots.db_instance('abc').each {|s|}
+
+ end
+
+ it 'accepts db instance objects' do
+
+ db = DBInstance.new('abc')
+
+ client.should_receive(:describe_db_snapshots).
+ with(:db_instance_identifier => db.id).
+ and_return(client.stub_for(:describe_db_snapshots))
+
+ snapshots.db_instance(db).each{|s|}
+
+ end
+
+ end
+
+ context '#with_type' do
+
+ it 'returns another snapshot collection' do
+ snapshots.with_type('abc').should be_a(DBSnapshotCollection)
+ end
+
+ it 'returns a collection with the correct config)' do
+ snapshots.with_type('abc').config.should eq(config)
+ end
+
+ it 'returns a collection that filters by the db instance id' do
+
+ client.should_receive(:describe_db_snapshots).
+ with(:snapshot_type => 'abc').
+ and_return(client.stub_for(:describe_db_snapshots))
+
+ snapshots.with_type('abc').each {|s|}
+
+ end
+
+ end
+
+ context '#filter' do
+
+ it 'returns another snapshot collection' do
+ snapshots.filter('key', 'value').should be_a(DBSnapshotCollection)
+ end
+
+ it 'returns a collection with the correct config)' do
+ snapshots.filter('key', 'value').config.should eq(config)
+ end
+
+ it 'returns a collection that filters by the key and value' do
+
+ client.should_receive(:describe_db_snapshots).
+ with(:key => 'value').
+ and_return(client.stub_for(:describe_db_snapshots))
+
+ snapshots.filter('key', 'value').each {|s|}
+
+ end
+
+ end
+
+ it_behaves_like "a pageable collection with limits" do
+
+ let(:collection) { snapshots }
+ let(:client_method) { :describe_db_snapshots }
+ let(:next_token_key) { :marker }
+ let(:limit_key) { :max_records }
+ let(:request_options) {{}}
+
+ def stub_next_token(response, token)
+ response.data[:marker] = token
+ end
+
+ def stub_n_members response, n
+ response.data[:db_snapshots] = (1..n).map{|i|
+ { :db_snapshot_identifier => "id-#{i}" }
+ }
+ end
+
+ it 'yields DBSnapshot objects' do
+ stub_n_members(response,2)
+ snapshots.count.should == 2
+ snapshots.each{|i| i.should be_an(DBSnapshot) }
+ snapshots.each{|i| i.config.should == config }
+ snapshots.map(&:id).should == %w(id-1 id-2)
+ end
+
+ end
+
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.