summaryrefslogtreecommitdiff
path: root/vendor/supply_drop/test
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-10-23 03:50:52 -0700
committerelijah <elijah@riseup.net>2012-10-23 03:50:52 -0700
commitd385da49ef6c17c64cf8be66002f5744c1ee38f7 (patch)
tree6e19772d6adf2b302e73dbd9229eb3618d19bab0 /vendor/supply_drop/test
parent3a27d87e6a28e4b58842ca4cb7a1ddc4e6637b36 (diff)
patched supply_drop gem and vendored it
Diffstat (limited to 'vendor/supply_drop/test')
-rw-r--r--vendor/supply_drop/test/async_test.rb67
-rw-r--r--vendor/supply_drop/test/files/manifests/invalid.pp1
-rw-r--r--vendor/supply_drop/test/files/manifests/valid.pp9
-rw-r--r--vendor/supply_drop/test/files/templates/invalid.erb1
-rw-r--r--vendor/supply_drop/test/files/templates/valid.erb1
-rw-r--r--vendor/supply_drop/test/rsync_test.rb57
-rw-r--r--vendor/supply_drop/test/syntax_checker_test.rb23
7 files changed, 159 insertions, 0 deletions
diff --git a/vendor/supply_drop/test/async_test.rb b/vendor/supply_drop/test/async_test.rb
new file mode 100644
index 0000000..0b9bc3a
--- /dev/null
+++ b/vendor/supply_drop/test/async_test.rb
@@ -0,0 +1,67 @@
+require 'test/unit'
+require File.expand_path('../../lib/supply_drop/util', __FILE__)
+require File.expand_path('../../lib/supply_drop/async_enumerable', __FILE__)
+require File.expand_path('../../lib/supply_drop/thread_pool', __FILE__)
+
+class AsyncTest < Test::Unit::TestCase
+ def teardown
+ SupplyDrop::Util.thread_pool_size = SupplyDrop::Util::DEFAULT_THREAD_POOL_SIZE
+ end
+
+ def test_can_enumerate_asynchronously
+ collection = (1..10).to_a
+ elapsed = timed do
+ SupplyDrop::Util.optionally_async(collection, true).each do |item|
+ sleep 0.1
+ end
+ end
+ assert elapsed < 1
+ end
+
+ def test_can_enumerate_asynchronously_with_map
+ collection = (1..10).to_a
+ returned_values = nil
+ elapsed = timed do
+ returned_values = SupplyDrop::Util.optionally_async(collection, true).map do |item|
+ sleep 0.1
+ :somevalue
+ end
+ end
+ assert returned_values == Array.new(10, :somevalue)
+ assert elapsed < 1
+ end
+
+ def test_can_enumerate_normally_and_does_not_leak_after_extending
+ collection = (1..10).to_a
+ elapsed = timed do
+ SupplyDrop::Util.optionally_async(collection, true).each do |item|
+ sleep 0.1
+ end
+ end
+ assert elapsed < 1
+
+ elapsed = timed do
+ SupplyDrop::Util.optionally_async(collection, false).each do |item|
+ sleep 0.1
+ end
+ end
+ assert elapsed >= 1
+ end
+
+ def test_can_configure_thread_pool_size
+ collection = (1..10).to_a
+ SupplyDrop::Util.thread_pool_size = 1
+ elapsed = timed do
+ returned_values = SupplyDrop::Util.optionally_async(collection, true).map do |item|
+ sleep 0.1
+ end
+ end
+ assert elapsed >= 1
+ end
+
+ def timed
+ start = Time.now
+ yield
+ Time.now - start
+ end
+end
diff --git a/vendor/supply_drop/test/files/manifests/invalid.pp b/vendor/supply_drop/test/files/manifests/invalid.pp
new file mode 100644
index 0000000..5ca851c
--- /dev/null
+++ b/vendor/supply_drop/test/files/manifests/invalid.pp
@@ -0,0 +1 @@
+class example {
diff --git a/vendor/supply_drop/test/files/manifests/valid.pp b/vendor/supply_drop/test/files/manifests/valid.pp
new file mode 100644
index 0000000..d8e6486
--- /dev/null
+++ b/vendor/supply_drop/test/files/manifests/valid.pp
@@ -0,0 +1,9 @@
+class valid {
+ file { "/etc/hosts":
+ ensure => present,
+ content => "127.0.0.1 localhost",
+ owner => root,
+ group => root,
+ mode => "0644"
+ }
+}
diff --git a/vendor/supply_drop/test/files/templates/invalid.erb b/vendor/supply_drop/test/files/templates/invalid.erb
new file mode 100644
index 0000000..615887c
--- /dev/null
+++ b/vendor/supply_drop/test/files/templates/invalid.erb
@@ -0,0 +1 @@
+this is a <%= if true %> template
diff --git a/vendor/supply_drop/test/files/templates/valid.erb b/vendor/supply_drop/test/files/templates/valid.erb
new file mode 100644
index 0000000..722efea
--- /dev/null
+++ b/vendor/supply_drop/test/files/templates/valid.erb
@@ -0,0 +1 @@
+this is a <%= "good" %> template
diff --git a/vendor/supply_drop/test/rsync_test.rb b/vendor/supply_drop/test/rsync_test.rb
new file mode 100644
index 0000000..b51a6b3
--- /dev/null
+++ b/vendor/supply_drop/test/rsync_test.rb
@@ -0,0 +1,57 @@
+require 'test/unit'
+require File.expand_path('../../lib/supply_drop/rsync', __FILE__)
+
+class RsyncTest < Test::Unit::TestCase
+
+ def test_build_simple_command
+ command = SupplyDrop::Rsync.command('bar', 'foo')
+ assert_equal 'rsync -az bar foo', command
+ end
+
+ def test_allows_passing_delete
+ command = SupplyDrop::Rsync.command('bar', 'foo', :delete => true)
+ assert_equal 'rsync -az --delete bar foo', command
+ end
+
+ def test_allows_specifying_an_exclude
+ command = SupplyDrop::Rsync.command('bar', 'foo', :excludes => '.git')
+ assert_equal 'rsync -az --exclude=.git bar foo', command
+ end
+
+ def test_ssh_options_keys_only_lists_existing_files
+ command = SupplyDrop::Rsync.command('.', 'foo', :ssh => { :keys => [__FILE__, "#{__FILE__}dadijofs"] })
+ assert_match /-i #{__FILE__}/, command
+ end
+
+ def test_ssh_options_ignores_keys_if_nil
+ command = SupplyDrop::Rsync.command('.', 'foo', :ssh => { :keys => nil })
+ assert_equal 'rsync -az . foo', command
+ command = SupplyDrop::Rsync.command('bar', 'foo')
+ assert_equal 'rsync -az bar foo', command
+ end
+
+ def test_ssh_options_config_adds_flag
+ command = SupplyDrop::Rsync.command('.', 'foo', :ssh => { :config => __FILE__ })
+ assert_equal %Q[rsync -az -e "ssh -F #{__FILE__}" . foo], command
+ end
+
+ def test_ssh_options_port_adds_port
+ command = SupplyDrop::Rsync.command('.', 'foo', :ssh => { :port => '30022' })
+ assert_equal %Q[rsync -az -e "ssh -p 30022" . foo], command
+ end
+
+ def test_ssh_options_ignores_config_if_nil_or_false
+ command = SupplyDrop::Rsync.command('.', 'foo', :ssh => { :config => nil })
+ assert_equal 'rsync -az . foo', command
+ command = SupplyDrop::Rsync.command('.', 'foo', :ssh => { :config => false })
+ assert_equal 'rsync -az . foo', command
+ end
+
+ def test_remote_address_concatinates_things_correctly
+ assert_equal "user@box.local:/tmp", SupplyDrop::Rsync.remote_address('user', 'box.local', '/tmp')
+ end
+
+ def test_remote_address_drops_at_when_user_is_nil
+ assert_equal 'box.local:/tmp', SupplyDrop::Rsync.remote_address(nil, 'box.local', '/tmp')
+ end
+end
diff --git a/vendor/supply_drop/test/syntax_checker_test.rb b/vendor/supply_drop/test/syntax_checker_test.rb
new file mode 100644
index 0000000..15f6e73
--- /dev/null
+++ b/vendor/supply_drop/test/syntax_checker_test.rb
@@ -0,0 +1,23 @@
+require 'test/unit'
+require File.expand_path('../../lib/supply_drop/syntax_checker', __FILE__)
+
+class SyntaxCheckerTest < Test::Unit::TestCase
+
+ def test_syntax_checks_puppet_files
+ checker = SupplyDrop::SyntaxChecker.new(File.expand_path('../files', __FILE__))
+ errors = checker.validate_puppet_files
+ assert_equal 1, errors.count
+ file, error = errors.first
+ assert_match %r[manifests/invalid.pp$], file
+ assert_match %r[expected '\}'], error
+ end
+
+ def test_synatx_checks_erb_files
+ checker = SupplyDrop::SyntaxChecker.new(File.expand_path('../files', __FILE__))
+ errors = checker.validate_templates
+ assert_equal 1, errors.count
+ file, error = errors.first
+ assert_match %r[templates/invalid.erb$], file
+ assert_match %r[syntax error], error
+ end
+end