Skip to content

Commit

Permalink
rds parameters and test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcy-terui committed Jun 16, 2014
1 parent ba0e1ae commit 67be400
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
vendor
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: ruby
rvm:
- 2.0.0
- 1.9.3
- jruby-19mode
- rbx-2
30 changes: 11 additions & 19 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion awspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file modified bin/awspec
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion lib/awspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require "rspec"
require "awspec/version"
require "awspec/type"
require "awspec/matchers"

module Awspec
# Your code goes here...
Expand Down
18 changes: 18 additions & 0 deletions lib/awspec/type.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions lib/awspec/type/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Awspec
module Type
class Base

def initialize(name=nil)
@name = name
end

end
end
end
16 changes: 11 additions & 5 deletions lib/awspec/type/rds/base.rb
Original file line number Diff line number Diff line change
@@ -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
44 changes: 0 additions & 44 deletions lib/awspec/type/rds/paramaters.rb

This file was deleted.

48 changes: 48 additions & 0 deletions lib/awspec/type/rds/parameters.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions spec/rds/parameters_spec.rb
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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!

0 comments on commit 67be400

Please sign in to comment.