From 67be40024c4ec8c1cbd97ce76c419821407ad696 Mon Sep 17 00:00:00 2001 From: Marcy Date: Mon, 16 Jun 2014 19:17:04 +0900 Subject: [PATCH] rds parameters and test --- .gitignore | 1 + .travis.yml | 6 ++++ LICENSE.txt | 30 +++++++------------ Rakefile | 10 +++++++ awspec.gemspec | 3 +- bin/awspec | 0 lib/awspec.rb | 1 - lib/awspec/type.rb | 18 ++++++++++++ lib/awspec/type/base.rb | 11 +++++++ lib/awspec/type/rds/base.rb | 16 +++++++---- lib/awspec/type/rds/paramaters.rb | 44 ---------------------------- lib/awspec/type/rds/parameters.rb | 48 +++++++++++++++++++++++++++++++ spec/rds/parameters_spec.rb | 30 +++++++++++++++++++ spec/spec_helper.rb | 16 +++++++++++ 14 files changed, 164 insertions(+), 70 deletions(-) create mode 100644 .travis.yml mode change 100644 => 100755 bin/awspec create mode 100644 lib/awspec/type.rb create mode 100644 lib/awspec/type/base.rb delete mode 100644 lib/awspec/type/rds/paramaters.rb create mode 100644 lib/awspec/type/rds/parameters.rb create mode 100644 spec/rds/parameters_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index d87d4be..04b5275 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +vendor \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ec898de --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: ruby +rvm: +- 2.0.0 +- 1.9.3 +- jruby-19mode +- rbx-2 diff --git a/LICENSE.txt b/LICENSE.txt index 2c46d85..464339a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,22 +1,14 @@ -Copyright (c) 2014 Masashi Terui +Copyright (C) 2014 Masashi Terui + https://github.com/FumblePerson/ -MIT License +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: + http://www.apache.org/licenses/LICENSE-2.0 -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Unless required by applicable law or agreed to in writing, software +distributed under the License 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. \ No newline at end of file diff --git a/Rakefile b/Rakefile index 2995527..2ec33f2 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,11 @@ require "bundler/gem_tasks" + +task :default => [:spec] +begin + require 'rspec/core/rake_task' + RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = 'spec/**/*_spec.rb' + spec.rspec_opts = ['-c'] + end +rescue LoadError => e +end \ No newline at end of file diff --git a/awspec.gemspec b/awspec.gemspec index 22f5b21..51bf61e 100644 --- a/awspec.gemspec +++ b/awspec.gemspec @@ -20,5 +20,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "rake" - spec.add_dependecy "aws-sdk" + spec.add_dependency "aws-sdk" + spec.add_dependency "rspec" end diff --git a/bin/awspec b/bin/awspec old mode 100644 new mode 100755 diff --git a/lib/awspec.rb b/lib/awspec.rb index 6f708db..f936b61 100644 --- a/lib/awspec.rb +++ b/lib/awspec.rb @@ -2,7 +2,6 @@ require "rspec" require "awspec/version" require "awspec/type" -require "awspec/matchers" module Awspec # Your code goes here... diff --git a/lib/awspec/type.rb b/lib/awspec/type.rb new file mode 100644 index 0000000..e927562 --- /dev/null +++ b/lib/awspec/type.rb @@ -0,0 +1,18 @@ +module Awspec + module Type + types = [ + "rds/parameters", + ] + + types.each do |type| + require "awspec/type/#{type}" + method_name = type.gsub("/","_") + class_names = type.split("/") + define_method method_name do |*args| + name = args.first + self.class.const_get('Awspec').const_get('Type').const_get(class_names.first.capitalize).const_get(class_names.last.capitalize).new(name) + end + end + + end +end \ No newline at end of file diff --git a/lib/awspec/type/base.rb b/lib/awspec/type/base.rb new file mode 100644 index 0000000..5eb9f01 --- /dev/null +++ b/lib/awspec/type/base.rb @@ -0,0 +1,11 @@ +module Awspec + module Type + class Base + + def initialize(name=nil) + @name = name + end + + end + end +end \ No newline at end of file diff --git a/lib/awspec/type/rds/base.rb b/lib/awspec/type/rds/base.rb index afaef8d..bb04134 100644 --- a/lib/awspec/type/rds/base.rb +++ b/lib/awspec/type/rds/base.rb @@ -1,10 +1,16 @@ +require 'awspec/type/base' + module Awspec module Type - class RdsBase < Base - - def initialize(name) - super - @rds = AWS::RDS::new + module Rds + class Base < Awspec::Type::Base + + def initialize(name) + super + @rds = AWS::RDS::new + end + end + end end end \ No newline at end of file diff --git a/lib/awspec/type/rds/paramaters.rb b/lib/awspec/type/rds/paramaters.rb deleted file mode 100644 index e2d5c63..0000000 --- a/lib/awspec/type/rds/paramaters.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Awspec - module Type - class RdsParameters < RdsBase - - MAX_RECORDS = 100 - - def initialize(name) - super - @group_name = name - @parameters = {} - - marker = "" - while (res.length == 0) || (@paramaters.length % MAX_RECORDS == 0) do - if marker.empty? then - res = @rds.client.describe_db_parameters( - :db_parameter_group_name => @group_name, - :max_records => MAX_RECORDS) - else - res = @rds.client.describe_db_parameters( - :db_parameter_group_name => @group_name, - :max_records => MAX_RECORDS, - :marker => marker) - end - marker = res[:marker] - res[:parameters].each do |param| - @parameters[param[:parameter_name]] = param[:parameter_value] - end - end - end - - def method_missing(name) - if @parameters.has_key?(name) then - @parameters[name].to_s - else - super - end - end - end - - def rds_parameters(name) - RdsParameters.new(name) - end - end -end \ No newline at end of file diff --git a/lib/awspec/type/rds/parameters.rb b/lib/awspec/type/rds/parameters.rb new file mode 100644 index 0000000..ff7111c --- /dev/null +++ b/lib/awspec/type/rds/parameters.rb @@ -0,0 +1,48 @@ +require 'awspec/type/rds/base' + +module Awspec + module Type + module Rds + class Parameters < Base + + MAX_RECORDS = 100 + + def initialize(name) + super + + @parameters = {} + marker = "" + while (@parameters.length == 0) || (@parameters.length % MAX_RECORDS == 0) do + if marker.empty? then + res = @rds.client.describe_db_parameters( + :db_parameter_group_name => name, + :max_records => MAX_RECORDS) + else + res = @rds.client.describe_db_parameters( + :db_parameter_group_name => name, + :max_records => MAX_RECORDS, + :marker => marker) + end + marker = res[:marker] + if res[:parameters].empty? then + break + end + res[:parameters].each do |param| + @parameters[param[:parameter_name]] = param[:parameter_value] + end + end + end + + def method_missing(name) + param_name = name.to_s + if @parameters.has_key?(param_name) then + @parameters[param_name].to_s + else + super + end + end + + end + end + end +end \ No newline at end of file diff --git a/spec/rds/parameters_spec.rb b/spec/rds/parameters_spec.rb new file mode 100644 index 0000000..6e4ac1e --- /dev/null +++ b/spec/rds/parameters_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +module Awspec + module Type + module Rds + class Base < Awspec::Type::Base + + def initialize(name) + super + @rds = AWS::RDS::new + res = @rds.client.stub_for(:describe_db_parameters) + res.data[:parameters] = [ + { :parameter_name => "key1", :parameter_value => "value1" }, + { :parameter_name => "key2", :parameter_value => "value2" }, + { :parameter_name => "key3", :parameter_value => "value3" }, + ] + end + + end + end + end +end + +describe Awspec::Type::Rds::Parameters do + rds = Awspec::Type::Rds::Parameters.new('test') + example { expect(rds.key1).to eq('value1') } + example { expect(rds.key2).to eq('value2') } + example { expect(rds.key3).to eq('value3') } +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..a070aab --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,16 @@ +%w(AWS AMAZON).each do |prefix| + ENV.delete("#{prefix}_REGION") + ENV.delete("#{prefix}_ACCESS_KEY_ID") + ENV.delete("#{prefix}_SECRET_ACCESS_KEY") +end + +require 'awspec' +require 'rspec' +require 'rspec/mocks/standalone' + +AWS.config( + :access_key_id => "dummy", + :secret_access_key => "dummy", +) + +AWS::stub! \ No newline at end of file