Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged new tests

  • Loading branch information...
commit ffefbf680a418bdc1c1a27000ca3a3c78f6abb9a 2 parents b7fd2c0 + fe4d45a
@auser authored
View
1  .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2@poolparty --create
View
17 Gemfile
@@ -1,19 +1,22 @@
source "http://rubygems.org"
+
+gemspec
gem 'amazon-ec2', '~>0.9.17'
gem 'xml-simple'
gem 'json'
+gem 'git-style-binaries'
group :test do
- gem "shoulda"
- gem "mocha"
- gem "fakeweb"
- gem "right_http_connection"
- gem "matchy"
+ gem 'fakeweb'
+ gem 'webmock'
+ gem 'shoulda'
+ gem 'rcov'
+ gem 'mocha'
+ gem 'right_http_connection'
+ gem "jnunemaker-matchy", "~> 0.4.0"
end
group :development do
gem 'jeweler'
end
-
-gemspec
View
43 Gemfile.lock
@@ -1,14 +1,55 @@
PATH
remote: .
specs:
- poolparty (1.6.9)
+ poolparty (1.7.0.pre)
+ amazon-ec2 (~> 0.9.17)
+ json
+ poolparty
+ xml-simple
GEM
remote: http://rubygems.org/
specs:
+ addressable (2.2.6)
+ amazon-ec2 (0.9.17)
+ xml-simple (>= 1.0.12)
+ crack (0.1.8)
+ fakeweb (1.3.0)
+ git (1.2.5)
+ git-style-binaries (0.1.11)
+ shoulda
+ trollop
+ jeweler (1.6.2)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ jnunemaker-matchy (0.4.0)
+ json (1.5.1)
+ mocha (0.9.12)
+ rake (0.9.1)
+ rcov (0.9.9)
+ right_http_connection (1.3.0)
+ shoulda (2.11.3)
+ trollop (1.16.2)
+ webmock (1.6.4)
+ addressable (~> 2.2, > 2.2.5)
+ crack (>= 0.1.7)
+ xml-simple (1.0.16)
PLATFORMS
ruby
DEPENDENCIES
+ amazon-ec2 (~> 0.9.17)
+ fakeweb
+ git-style-binaries
+ jeweler
+ jnunemaker-matchy (~> 0.4.0)
+ json
+ mocha
poolparty!
+ rcov
+ right_http_connection
+ shoulda
+ webmock
+ xml-simple
View
15 Rakefile
@@ -1,7 +1,8 @@
+$:.unshift(File.join(File.dirname(__FILE__), "."))
require 'rake'
require 'rake/testtask'
-require 'rake/rdoctask'
-$: << File.dirname(__FILE__)
+require 'rdoc/task'
+
require 'config/requirements'
begin
@@ -34,12 +35,12 @@ end
# sh "ruby -Ilib:test #{Dir["#{File.dirname(__FILE__)}/../test/poolparty/*/*.rb"].join(" ")}"
# end
-Rake::TestTask.new(:test) do |t|
- t.test_files = FileList['test/lib/**/*_test.rb']
- t.warning = false
- t.verbose = false
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
end
-
+
begin
require 'rcov/rcovtask'
View
11 lib/cloud_providers/ec2/ec2.rb
@@ -2,17 +2,6 @@
EC2 CloudProvider
This serves as the basis for running PoolParty on Amazon's ec2 cloud.
=end
-begin
- require 'AWS'
-rescue LoadError
- puts <<-EOM
- There was an error requiring AWS
-EOM
-end
-
-require 'pp'
-
-POOLPARTY_CONFIG_FILE = "#{ENV["HOME"]}/.poolparty/aws" unless defined?(POOLPARTY_CONFIG_FILE)
module CloudProviders
class Ec2 < CloudProvider
View
16 lib/poolparty.rb
@@ -2,11 +2,23 @@
t=Time.now
+require 'yaml'
+
# Load system gems
-%w(rubygems logger erb open-uri yaml).each do |lib|
+%w(rubygems logger erb open-uri fileutils).each do |lib|
require lib
end
+begin
+ require 'AWS'
+rescue LoadError
+ puts <<-EOM
+ There was an error requiring AWS
+EOM
+end
+
+require 'pp'
+
# Add all vendor gems to the load paths
Dir[File.dirname(__FILE__)+"/../vendor/gems/*"].each {|lib| $LOAD_PATH.unshift(File.expand_path("#{lib}/lib")) }
@@ -42,6 +54,8 @@ def self.lib_dir
require "keypair"
+POOLPARTY_CONFIG_FILE = "#{ENV["HOME"]}/.poolparty/aws" unless defined?(POOLPARTY_CONFIG_FILE)
+
# PoolParty core
$LOAD_PATH.unshift(File.dirname(__FILE__)/"poolparty")
%w( base
View
2  test/fixtures/clouds/ssh_cloud.rb
@@ -1,7 +1,7 @@
pool :tssh do
cloud :tgarden do
instances 2
- keypair fixtures_dir/'keys/test_key'
+ keypair File.join(FIXTURES_PATH, 'keys/test_key')
using :ssh do
user 'fairchild' #default is root
hosts %w(beet squash)
View
2  test/lib/core/array_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require "test_helper"
class ArrayTest < Test::Unit::TestCase
def setup
View
2  test/lib/core/hash_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require 'test_helper'
class HashTest < Test::Unit::TestCase
context "Hash" do
View
2  test/lib/core/object_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require 'test_helper'
class ObjectTest < Test::Unit::TestCase
context "object" do
View
2  test/lib/core/string_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require 'test_helper'
class StringTest < Test::Unit::TestCase
context "string" do
View
2  test/lib/core/symbol_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require 'test_helper'
class SymbolTest < Test::Unit::TestCase
context "Symbol" do
View
10 test/lib/poolparty/cloud_test.rb
@@ -1,14 +1,14 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require 'test_helper'
# require 'rr'
-stub_ec2_calls
class CloudTest < Test::Unit::TestCase
# include RR::Adapters::TestUnit
def setup
clear!
- @filepath = fixtures_dir/"clouds/simple_cloud.rb"
+ @filepath = File.join(FIXTURES_PATH, "clouds/simple_cloud.rb")
require @filepath
@cloud = pool.clouds[pool.clouds.keys.first]
+ stub_ec2_calls
end
def test_have_a_pool_name
@@ -33,7 +33,7 @@ def test_set_the_cloud_provider_cloud_and_keypair_with_cloud_provider
def test_set_the_cloud_provider_with_a_using_block
@cloud.instance_eval do
using :ec2
- keypair "test_key", fixtures_dir/"keys"
+ keypair "test_key", File.join(FIXTURES_PATH, "keys")
image_id 'emi-39921602'
end
assert_equal :ec2, @cloud.cloud_provider.name
@@ -44,7 +44,7 @@ def test_set_the_cloud_provider_with_a_using_block
def test_nodes
assert_respond_to @cloud, :nodes
assert_respond_to @cloud.nodes, :each
- assert @cloud.nodes.size>1
+ assert @cloud.nodes.size>1, "Cloudsize was: #{@cloud.nodes.size}"
end
def test_run
View
27 test/lib/poolparty/keypair_test.rb
@@ -1,24 +1,23 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
-
-Keypair.searchable_paths << fixtures_dir/"keys"
+require 'test_helper'
class KeypairTest < Test::Unit::TestCase
context "Base" do
setup do
- @keypair = Keypair.new(fixtures_dir/"keys"/"test_key")
- @keypair_pem = Keypair.new(fixtures_dir/"keys"/"pem_key")
+ Keypair.searchable_paths << File.join(FIXTURES_PATH, "keys")
+ @keypair = Keypair.new(File.join(FIXTURES_PATH, "keys", "test_key"))
+ @keypair_pem = Keypair.new(File.join(FIXTURES_PATH, "keys", "pem_key"))
end
should "set the file given as the file for the keypair" do
- assert_equal @keypair.filepath, fixtures_dir/"keys"/"test_key"
- assert_equal @keypair.full_filepath, File.expand_path(fixtures_dir/"keys"/"test_key")
- assert_match @keypair.to_s, File.expand_path(fixtures_dir/"keys"/"test_key")
+ assert_equal @keypair.filepath, File.join(FIXTURES_PATH, "keys", "test_key")
+ assert_equal @keypair.full_filepath, File.expand_path(File.join(FIXTURES_PATH, "keys", "test_key"))
+ assert_match @keypair.to_s, File.expand_path(File.join(FIXTURES_PATH, "keys", "test_key"))
end
should "find the suffixed file given without pem suffix" do
- assert_equal @keypair_pem.filepath, fixtures_dir/"keys"/"pem_key"
- assert_equal @keypair_pem.full_filepath, File.expand_path(fixtures_dir/"keys"/"pem_key.pem")
- assert_match @keypair_pem.to_s, File.expand_path(fixtures_dir/"keys"/"pem_key")
+ assert_equal @keypair_pem.filepath, File.join(FIXTURES_PATH, "keys", "pem_key")
+ assert_equal @keypair_pem.full_filepath, File.expand_path(File.join(FIXTURES_PATH, "keys", "pem_key.pem"))
+ assert_match @keypair_pem.to_s, File.expand_path(File.join(FIXTURES_PATH, "keys", "pem_key"))
end
should "find the suffixed file given without pem suffix or dir" do
@@ -35,11 +34,11 @@ class KeypairTest < Test::Unit::TestCase
end
should "have the content of the file available" do
- assert_equal @keypair.content, open(fixtures_dir/"keys"/"test_key").read
+ assert_equal @keypair.content, open(File.join(FIXTURES_PATH, "keys", "test_key")).read
end
should "be able to generate the public key from the private" # do
- # # assert_equal @keypair.public_key, "#{open(fixtures_dir/"test_pub_key").read}"
+ # # assert_equal @keypair.public_key, "#{open(FIXTURES_PATH/"test_pub_key").read}"
# end
should "have the basename of the keypair" do
@@ -53,7 +52,7 @@ class KeypairTest < Test::Unit::TestCase
should "be invalid if the file permissions are executable" do
assert_raises StandardError do
- Keypair.new(fixtures_dir/"bad_perms_test_key").valid?
+ Keypair.new(File.join(FIXTURES_PATH, "bad_perms_test_key")).valid?
end
end
end
View
2  test/lib/poolparty/pool_party_error_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
+require 'test_helper'
class PoolPartyErrorTest < Test::Unit::TestCase
include PoolParty
View
8 test/lib/poolparty/pool_test.rb
@@ -1,8 +1,10 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
-
-stub_keypair_searchable_paths
+require 'test_helper'
class PoolTest < Test::Unit::TestCase
+ def setup
+ stub_keypair_searchable_paths
+ end
+
def test_set_up_pool_object
reset!
pool "hi" do
View
8 test/lib/poolparty/rds_test.rb
@@ -1,8 +1,8 @@
-require "#{File.dirname(__FILE__)}/../../test_helper"
-stub_ec2_calls
+require 'test_helper'
class RdsTest < Test::Unit::TestCase
def setup
+ stub_ec2_calls
stub_response(AWS::EC2::Base, :describe_security_groups, 'ec2-describe-security-groups')
stub_response(AWS::EC2::Base, :run_instances, 'ec2-run-instances')
stub_response(AWS::RDS::Base, :describe_db_instances, 'rds-describe-db-instances-empty')
@@ -22,7 +22,7 @@ def test_required_properties
def scenario(filename)
clear!
- @filepath = fixtures_dir/"clouds/#{filename}.rb"
+ @filepath = File.join(FIXTURES_PATH, "clouds/#{filename}.rb")
require @filepath
@cloud = pool.clouds[pool.clouds.keys.first]
@@ -30,6 +30,6 @@ def scenario(filename)
end
def stub_response(klass, method, fixture_filename)
- klass.any_instance.stubs(method).returns AWS::Response.parse(:xml => open(fixtures_dir/"ec2/#{fixture_filename}_response_body.xml").read)
+ klass.any_instance.stubs(method).returns AWS::Response.parse(:xml => open(File.join(FIXTURES_PATH, "ec2/#{fixture_filename}_response_body.xml")).read)
end
end
View
23 test/test_helper.rb
@@ -1,5 +1,7 @@
-$:.unshift(::File.dirname(__FILE__))
-$:.unshift(::File.dirname(__FILE__) + "/../lib")
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+
+ENV['RACK_ENV'] ||= 'test'
# Test dependencies
%w(fakeweb right_http_connection matchy shoulda).each do |dep|
@@ -7,23 +9,20 @@
# require "#{dep}"
end
-require "test_methods"
-
-modify_env_with_hash(
- "EC2_ACCESS_KEY" => "fake_access_key",
- "EC2_SECRET_KEY" => "fake_secret_key",
- "EC2_PRIVATE_KEY" => ::File.dirname(__FILE__) + "/fixtures/keys/test_key",
- "EC2_CERT" => ::File.dirname(__FILE__) + "/fixtures/keys/test_key",
- "EC2_USER_ID" => '1234567890'
- )
-
require 'poolparty'
+
require "rubygems"
require "test/unit"
# TODO: Rip out shoulda
require "shoulda"
require 'mocha' # ARG! don't want to introduce additional test dependencies, but FakeWeb can only handle one fake post per URL!!!
+require 'webmock/test_unit'
+require 'pathname'
require 'git-style-binary/command'
+require "test_methods"
+
GitStyleBinary.run = true
+
+FIXTURES_PATH = Pathname.new(File.expand_path('../fixtures', __FILE__))
View
144 test/test_methods.rb
@@ -1,73 +1,99 @@
-# Helpers
-def fixtures_dir
- "#{::File.dirname(__FILE__)}/fixtures"
-end
+class Test::Unit::TestCase
+ # Helpers
+ def FIXTURES_PATH
+ "#{::File.dirname(__FILE__)}/fixtures"
+ end
-def test_dir
- "#{File.dirname(__FILE__)}/test_dir"
-end
+ def test_dir
+ "#{File.dirname(__FILE__)}/test_dir"
+ end
-def clear!
- $pools = $clouds = nil
-end
+ def clear!
+ $pools = $clouds = nil
+ end
-def modify_env_with_hash(h={})
- orig_env = Kernel.const_get(:ENV)
+ def modify_env_with_hash(h={})
+ orig_env = Kernel.const_get(:ENV)
- h.each do |k,v|
- orig_env.delete(k)
- orig_env[k] = v
- orig_env[k].freeze
- end
- if RUBY_VERSION.scan(/1.8/).pop
- Kernel.instance_eval {remove_const :ENV } if Kernel.const_defined?('ENV' )
- elsif RUBY_VERSION.scan(/1.9/).pop
- Object.instance_eval {remove_const :ENV } if Object.const_defined?('ENV' )
- else
- raise "can't determine what version of ruby you are running."
+ h.each do |k,v|
+ orig_env.delete(k)
+ orig_env[k] = v
+ orig_env[k].freeze
+ end
+
+ if RUBY_VERSION.scan(/1.8/).pop
+ # Kernel.send :remove_const, 'ENV' if Kernel.const_defined?('ENV')
+ Kernel.stubs(:ENV).returns(orig_env)
+ elsif RUBY_VERSION.scan(/1.9/).pop
+ Object.stubs(:ENV).returns(orig_env)
+ # Object.send :remove_const, 'ENV' if Object.const_defined?('ENV')
+ else
+ raise "can't determine what version of ruby you are running."
+ end
+
+ # Kernel.const_set(:ENV, orig_env)
end
- Kernel.const_set(:ENV, orig_env)
-end
-def capture_stdout(&block)
- old_stdout = $stdout
- old_stderr = $stderr
- out = StringIO.new
- $stdout = out
- old_stderr = StringIO.new
- begin
- block.call if block
- ensure
- $stdout = old_stdout
- $stderr = old_stderr
- end
- out.string
-end
+ def capture_stdout(&block)
+ old_stdout = $stdout
+ old_stderr = $stderr
+ out = StringIO.new
+ $stdout = out
+ old_stderr = StringIO.new
+ begin
+ block.call if block
+ ensure
+ $stdout = old_stdout
+ $stderr = old_stderr
+ end
+ out.string
+ end
-def stub_keypair_searchable_paths
- Keypair.searchable_paths << fixtures_dir/"keys"
-end
+ def stub_keypair_searchable_paths
+ Keypair.searchable_paths << File.join(FIXTURES_PATH, "keys")
+ end
+
+ def read_fixture(path)
+ open(File.join(FIXTURES_PATH, "ec2", path)).read
+ end
-def stub_ec2_calls(&block)
- stub_keypair_searchable_paths
+ def stub_ec2_calls(&block)
+ stub_keypair_searchable_paths
+
+ modify_env_with_hash(
+ "EC2_ACCESS_KEY" => "fake_access_key",
+ "EC2_SECRET_KEY" => "fake_secret_key",
+ "EC2_PRIVATE_KEY" => ::File.dirname(__FILE__) + "/fixtures/keys/test_key",
+ "EC2_CERT" => ::File.dirname(__FILE__) + "/fixtures/keys/test_key",
+ "EC2_USER_ID" => '1234567890'
+ )
- require 'fakeweb'
- FakeWeb.allow_net_connect=false
+ # FakeWeb.allow_net_connect=false
+ stub_request(:get, /.*Action=DescribeInstances.*/).
+ to_return(:status => 200, :body => read_fixture('ec2-describe-instances_response_body.xml'))
- FakeWeb.register_uri(:get, /.*Action=DescribeInstances.*/, :status => ["200", "OK"],
- :body => open(fixtures_dir/"ec2/ec2-describe-instances_response_body.xml").read)
+ stub_request(:get, /.*Action=RunInstances.*/).
+ to_return(:status => 200, :body => read_fixture('ec2-run-instances_response_body.xml'))
- FakeWeb.register_uri(:get, /.*Action=RunInstances.*/, :status => ["200", "OK"],
- :body => open(fixtures_dir/"ec2/ec2-run-instances_response_body.xml").read)
- FakeWeb.register_uri(:get, /.*Action=TerminateInstances.*/, :status => ["200", "OK"],
- :body => open(fixtures_dir/"ec2/ec2-terminate-instances_response_body.xml").read)
-
- FakeWeb.register_uri(:post, /elasticloadbalancing\.amazonaws\.com/, :status => ["200", "OK"],
- :body => open(fixtures_dir/"ec2/elb-describe-load-balancers.xml").read)
-
- FakeWeb.register_uri(:post, /\//, :status => ["200", "OK"],
- :body => open(fixtures_dir/"ec2/ec2-describe-instances_response_body.xml").read)
+ stub_request(:get, /.*Action=TerminateInstances.*/).
+ to_return(:status => 200, :body => read_fixture('ec2-terminate-instances_response_body.xml'))
+
+ stub_request(:post, /elasticloadbalancing\.amazonaws\.com/).
+ to_return(:status => 200, :body => read_fixture('elb-describe-load-balancers.xml'))
+
+ stub_request(:post, /\//).
+ to_return(:status => 200, :body => read_fixture('ec2-describe-instances_response_body.xml'))
+
+ # FakeWeb.register_uri(:get, /.*Action=TerminateInstances.*/, :status => ["200", "OK"],
+ # :body => open(FIXTURES_PATH/"ec2/ec2-terminate-instances_response_body.xml").read)
+ #
+ # FakeWeb.register_uri(:post, /elasticloadbalancing\.amazonaws\.com/, :status => ["200", "OK"],
+ # :body => open(FIXTURES_PATH/"ec2/elb-describe-load-balancers.xml").read)
+ #
+ # FakeWeb.register_uri(:post, /\//, :status => ["200", "OK"],
+ # :body => open(FIXTURES_PATH/"ec2/ec2-describe-instances_response_body.xml").read)
- instance_eval &block if block
+ instance_eval &block if block
+ end
end
View
4 vendor/gems/git-style-binaries/test/test_helper.rb
@@ -13,7 +13,7 @@
GitStyleBinary.run = true
class Test::Unit::TestCase
- def fixtures_dir
+ def FIXTURES_PATH
File.join(File.dirname(__FILE__), "fixtures")
end
end
@@ -21,7 +21,7 @@ def fixtures_dir
module RunsBinaryFixtures
# run the specified cmd returning the string values of [stdout,stderr]
def bin(cmd)
- stdin, stdout, stderr = Open3.popen3("#{fixtures_dir}/#{cmd}")
+ stdin, stdout, stderr = Open3.popen3("#{FIXTURES_PATH}/#{cmd}")
[stdout.read, stderr.read]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.