tdd_deploy 0.0.3 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/tdd_deploy_site_installer +7 -0
- data/lib/tasks/tdd_deploy_site_install.rake +17 -0
- data/lib/tdd_deploy/assertions.rb +114 -77
- data/lib/tdd_deploy/base.rb +1 -1
- data/lib/tdd_deploy/configurator.rb +78 -0
- data/lib/tdd_deploy/copy_methods.rb +54 -0
- data/lib/tdd_deploy/deploy_test_methods.rb +20 -22
- data/lib/tdd_deploy/environ.rb +12 -6
- data/lib/tdd_deploy/host_tests/host_connection.rb +3 -4
- data/lib/tdd_deploy/host_tests/remote_ip_tables.rb +21 -13
- data/lib/tdd_deploy/host_tests/remote_monit.rb +2 -6
- data/lib/tdd_deploy/host_tests/remote_nginx.rb +2 -6
- data/lib/tdd_deploy/host_tests/remote_postfix.rb +3 -7
- data/lib/tdd_deploy/host_tests/remote_postgresql.rb +2 -6
- data/lib/tdd_deploy/run_methods.rb +25 -18
- data/lib/tdd_deploy/server.rb +92 -12
- data/lib/tdd_deploy/site_tests/site_database.rb +1 -1
- data/lib/tdd_deploy/site_tests/site_layout.rb +24 -20
- data/lib/tdd_deploy/site_tests/site_user.rb +1 -1
- data/lib/tdd_deploy/version.rb +1 -1
- data/tests/test_assertions.rb +59 -14
- data/tests/test_configurator.rb +34 -0
- data/tests/test_copy_methods.rb +106 -0
- data/tests/{test_test_deploy_methods.rb → test_deploy_test_methods.rb} +23 -11
- data/tests/test_environ.rb +12 -7
- data/tests/test_remote_ip_tables.rb +11 -4
- data/tests/test_run_methods.rb +32 -15
- data/tests/test_server.rb +6 -9
- data/tests/test_site_database.rb +21 -0
- data/tests/test_site_layout.rb +20 -5
- data/tests/test_tdd_deploy_context.rb +16 -0
- data/tests/test_tdd_deploy_server.rb +3 -3
- metadata +20 -13
- data/tests/test_colored_tests.rb +0 -47
@@ -6,7 +6,7 @@ module TddDeploy
|
|
6
6
|
# tests all hosts to make sure that the local user can log on as *site_user*
|
7
7
|
class SiteUser < TddDeploy::Base
|
8
8
|
def test_login_as_site_user
|
9
|
-
|
9
|
+
deploy_test_on_hosts_as self.site_user, self.hosts, "/home/#{self.site_user}", "should be able to log into host as #{self.site_user}" do
|
10
10
|
'pwd'
|
11
11
|
end
|
12
12
|
end
|
data/lib/tdd_deploy/version.rb
CHANGED
data/tests/test_assertions.rb
CHANGED
@@ -17,31 +17,67 @@ class TestTddDeployAssertionsTestCase < Test::Unit::TestCase
|
|
17
17
|
@assertion_helper = nil
|
18
18
|
end
|
19
19
|
|
20
|
+
def test_pass_passes
|
21
|
+
assert @assertion_helper.pass('key', 'passing message'), 'pass passes'
|
22
|
+
assert @assertion_helper.test_results['key'].is_a?(Array), "test_results[key] should be an Array"
|
23
|
+
assert_equal 1, @assertion_helper.test_results['key'].length, "There should be a test_results[key]"
|
24
|
+
assert_equal true, @assertion_helper.test_results['key'].first[0], "pass should be a passing result"
|
25
|
+
assert_match /passing message/, @assertion_helper.test_results['key'].first[1], "pass should have the right success message"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_fail_fails
|
29
|
+
refute @assertion_helper.fail('key', 'failing message'), 'fail fails'
|
30
|
+
assert @assertion_helper.test_results['key'].is_a?(Array), "test_results[key] should be an Array"
|
31
|
+
assert_equal 1, @assertion_helper.test_results['key'].length, "There should be a test_results[key]"
|
32
|
+
assert_equal false, @assertion_helper.test_results['key'].first[0], "pass should be a passing result"
|
33
|
+
assert_match /failing message/, @assertion_helper.test_results['key'].first[1], "pass should have the right success message"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_keying_tests
|
37
|
+
@assertion_helper.pass('key1', 'key1 assertion message')
|
38
|
+
@assertion_helper.fail('key2', 'key2 assertion message')
|
39
|
+
|
40
|
+
assert @assertion_helper.test_results.keys.include?('key1'), "test messages includes key1"
|
41
|
+
assert @assertion_helper.test_results.keys.include?('key2'), "test messages includes key2"
|
42
|
+
|
43
|
+
assert_equal 1, @assertion_helper.test_count('key1'), "one test recorded under 'key1'"
|
44
|
+
assert_equal 0, @assertion_helper.failure_count('key1'), "0 failures recorded under 'key1'"
|
45
|
+
|
46
|
+
assert_equal 1, @assertion_helper.test_count('key2'), "one test recorded under 'key2'"
|
47
|
+
assert_equal 1, @assertion_helper.failure_count('key2'), "1 failure recorded under 'key2'"
|
48
|
+
|
49
|
+
assert_equal [], @assertion_helper.failure_messages('key1'), "falure_messages('key1') is nil"
|
50
|
+
assert_not_equal [], @assertion_helper.failure_messages('key2'), "falure_messages('key1') is not an empty array"
|
51
|
+
|
52
|
+
assert_no_match(/key1/, @assertion_helper.test_results['key2'].join('\n'), 'test messages for key2 do not contain key1')
|
53
|
+
end
|
54
|
+
|
20
55
|
def test_assert_true_passes
|
21
|
-
assert @assertion_helper.assert(true, 'true is true'), 'true tests true'
|
22
|
-
|
56
|
+
assert @assertion_helper.assert('key', true, 'true is true'), 'true tests true'
|
57
|
+
assert @assertion_helper.test_messages('key').first[0], "asserting 'true' passes"
|
58
|
+
assert_match(/Pass/i, @assertion_helper.formatted_test_results, "test messagess should include 'Pass'")
|
23
59
|
end
|
24
60
|
|
25
61
|
def test_assert_false_fails
|
26
|
-
refute @assertion_helper.assert(false, 'true is true'), "false tests false"
|
27
|
-
|
28
|
-
assert_match /
|
62
|
+
refute @assertion_helper.assert('key', false, 'true is true'), "false tests false"
|
63
|
+
refute @assertion_helper.test_messages('key').first[0], "asserting 'false' fails"
|
64
|
+
assert_match /Fail/i, @assertion_helper.formatted_test_results, "test messages should include 'Fail'"
|
29
65
|
end
|
30
66
|
|
31
67
|
def test_assert_equal
|
32
|
-
assert @assertion_helper.assert_equal(true, true, "true is still true"), "true is true"
|
68
|
+
assert @assertion_helper.assert_equal('key', true, true, "true is still true"), "true is true"
|
33
69
|
end
|
34
70
|
|
35
71
|
def test_assert_match
|
36
|
-
assert @assertion_helper.assert_match('^foo$', 'foo', 'foo is not bar'), 'foo is not bar'
|
72
|
+
assert @assertion_helper.assert_match('key', '^foo$', 'foo', 'foo is not bar'), 'foo is not bar'
|
37
73
|
end
|
38
74
|
|
39
75
|
def test_assert_nil
|
40
|
-
assert @assertion_helper.assert_nil(nil, "nil is nil"), "nil is nil"
|
76
|
+
assert @assertion_helper.assert_nil('key', nil, "nil is nil"), "nil is nil"
|
41
77
|
end
|
42
78
|
|
43
79
|
def test_assert_not_nil
|
44
|
-
assert @assertion_helper.assert_not_nil('foo', 'foo is not nil'), 'foo is not nil'
|
80
|
+
assert @assertion_helper.assert_not_nil('key', 'foo', 'foo is not nil'), 'foo is not nil'
|
45
81
|
end
|
46
82
|
|
47
83
|
def test_assert_raises
|
@@ -49,14 +85,23 @@ class TestTddDeployAssertionsTestCase < Test::Unit::TestCase
|
|
49
85
|
end
|
50
86
|
|
51
87
|
def test_refute
|
52
|
-
assert @assertion_helper.refute(false, 'false is false'), 'false is false'
|
88
|
+
assert @assertion_helper.refute('key', false, 'false is false'), 'false is false'
|
53
89
|
end
|
54
|
-
|
90
|
+
|
55
91
|
def test_refute_equal
|
56
|
-
assert @assertion_helper.refute_equal(false, true, "false is not true"), "false is not true"
|
92
|
+
assert @assertion_helper.refute_equal('key', false, true, "false is not true"), "false is not true"
|
57
93
|
end
|
58
94
|
|
59
|
-
def
|
60
|
-
|
95
|
+
def test_total_failures
|
96
|
+
assert_equal 0, @assertion_helper.total_failures, "no tests results in 0 total failures"
|
97
|
+
@assertion_helper.fail 'key', 'forcing a failure'
|
98
|
+
assert_equal 1, @assertion_helper.total_failures, "failing creates a failure"
|
99
|
+
assert_equal @assertion_helper.total_failures, @assertion_helper.total_tests, "failures == tests"
|
100
|
+
@assertion_helper.fail 'key', 'forcing a failure'
|
101
|
+
assert_equal 2, @assertion_helper.total_failures, "failing creates a failure"
|
102
|
+
|
103
|
+
@assertion_helper.pass 'key', 'forcing a pass'
|
104
|
+
assert_equal 2, @assertion_helper.total_failures, "failing creates a failure"
|
105
|
+
assert_equal 3, @assertion_helper.total_tests, "passing creates another test"
|
61
106
|
end
|
62
107
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'tdd_deploy/configurator'
|
6
|
+
|
7
|
+
class TestTddDeployConfiguratorTestCase < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@configurator = TddDeploy::Configurator.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@configurator = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_configurator_is_an_object
|
17
|
+
assert @configurator.is_a?(TddDeploy::Configurator), "@configurator shold be a TddDeploy::Configurator object"
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_configurator_creates_files
|
21
|
+
FileUtils.rm_rf 'tdd_deploy_configs'
|
22
|
+
@configurator.make_configuration_files
|
23
|
+
assert File.exists?('tdd_deploy_configs'), "tdd_deploy_configs/ exists"
|
24
|
+
[ 'balance_hosts', 'db_hosts', 'web_hosts'].each do |host_dir|
|
25
|
+
host_path = File.join('tdd_deploy_configs', host_dir)
|
26
|
+
assert File.exists?(host_path), "#{host_path} exists"
|
27
|
+
['config', 'site'].each do |subdir|
|
28
|
+
subdir_path = File.join(host_path, subdir)
|
29
|
+
assert File.exists?(subdir_path), "#{subdir_path} exists"
|
30
|
+
assert Dir.new(subdir_path).entries.length > 2, "#{subdir_path} has 3 or more entries"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
require 'test_helpers'
|
3
|
+
require 'tdd_deploy/environ'
|
4
|
+
require 'tdd_deploy/run_methods'
|
5
|
+
require 'tdd_deploy/copy_methods'
|
6
|
+
|
7
|
+
class RunMethodsTestCase < Test::Unit::TestCase
|
8
|
+
include TddDeploy::Environ
|
9
|
+
include TddDeploy::RunMethods
|
10
|
+
|
11
|
+
def setup
|
12
|
+
self.reset_env
|
13
|
+
self.set_env :hosts => 'arch,ubuntu', :host_admin => 'mike', :ssh_timeout => 2
|
14
|
+
run_on_hosts_as 'site_user', 'arch', 'rm -f test-file'
|
15
|
+
run_on_hosts_as 'site_user', 'arch', 'rmdir test-dir'
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
run_on_hosts_as 'site_user', 'arch', 'rm -f test-file'
|
20
|
+
run_on_hosts_as 'site_user', 'arch', 'rmdir test-dir'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_mkdir_on_remote_as
|
24
|
+
result = mkdir_on_remote_as 'site_user', 'arch', 'test-dir'
|
25
|
+
assert result, "mkdir_on_remote_as site_user on arch returns true"
|
26
|
+
stdout, stderr, cmd = run_in_ssh_session_on_host_as 'site_user', 'arch', 'test -d test-dir && echo "success"'
|
27
|
+
assert_equal "success\n", stdout, "deploy_test_file_exists_on_hosts_as says 'test-dir' exists"
|
28
|
+
|
29
|
+
stdout, stderr, cmd = run_in_ssh_session_on_host_as 'site_user', 'arch', 'rmdir test-dir ; test -d test-dir || echo "success"'
|
30
|
+
assert_equal "success\n", stdout, "deploy_test_file_exists_on_hosts_as says 'test-dir' removed"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_copy_string_to_remote_file_as
|
34
|
+
str = "line 1\nline 2\nline 3\n"
|
35
|
+
result = copy_string_to_remote_file_as 'site_user', 'arch', str, 'test-file'
|
36
|
+
assert result, "copy_string_to_remote_file_as returns true on success"
|
37
|
+
|
38
|
+
stdout, stderr, cmd = run_in_ssh_session_on_host_as('site_user', 'arch', 'cat test-file')
|
39
|
+
assert_equal str, stdout, "test-file should exist on arch"
|
40
|
+
assert_nil stderr, "stderr should be nil"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_copy_file_to_remote_as
|
44
|
+
require 'tempfile'
|
45
|
+
tmp_file = Tempfile.new('foo')
|
46
|
+
begin
|
47
|
+
input_text = "line one\nline two\nline 3\n"
|
48
|
+
tmp_file.write input_text
|
49
|
+
tmp_file.close
|
50
|
+
result = copy_file_to_remote_as 'site_user', 'arch', tmp_file.path, 'test-file'
|
51
|
+
|
52
|
+
stdout, stderr, cmd = run_in_ssh_session_on_host_as 'site_user', 'arch', 'cat test-file'
|
53
|
+
assert_equal input_text, stdout, "remote file should contain input_text"
|
54
|
+
|
55
|
+
assert result, "copy should return true"
|
56
|
+
ensure
|
57
|
+
tmp_file.unlink
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_copy_string_to_remote_on_hosts_as
|
62
|
+
host_list = ['arch']
|
63
|
+
str = "line 1\nline 2\nline 3\n"
|
64
|
+
result = copy_string_to_remote_file_on_hosts_as 'site_user', host_list, str, 'test-file'
|
65
|
+
assert result, "copy_string_to_remote_file_as returns true on success"
|
66
|
+
|
67
|
+
result = run_on_hosts_as('site_user', host_list, 'cat test-file')
|
68
|
+
refute_nil result, "run_on_hosts_as ran on #{host_list.inspect}"
|
69
|
+
assert_equal str, result['arch'][0], "test-file should exist on arch"
|
70
|
+
assert_nil result['arch'][1], "stderr should be nil"
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def test_copy_string_to_remote_on_hosts_as_with_host_list_as_str
|
75
|
+
host_list = 'arch'
|
76
|
+
str = "line 1\nline 2\nline 3\n"
|
77
|
+
result = copy_string_to_remote_file_on_hosts_as 'site_user', host_list, str, 'test-file'
|
78
|
+
assert result, "copy_string_to_remote_file_as returns true on success"
|
79
|
+
|
80
|
+
result = run_on_hosts_as('site_user', host_list, 'cat test-file')
|
81
|
+
refute_nil result, "run_on_hosts_as ran on #{host_list.inspect}"
|
82
|
+
assert_equal str, result['arch'][0], "test-file should exist on arch"
|
83
|
+
assert_nil result['arch'][1], "stderr should be nil"
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def test_copy_file_to_remote_on_hosts_as
|
88
|
+
host_list = ['arch']
|
89
|
+
require 'tempfile'
|
90
|
+
tmp_file = Tempfile.new('foo')
|
91
|
+
begin
|
92
|
+
input_text = "line one\nline two\nline 3\n"
|
93
|
+
tmp_file.write input_text
|
94
|
+
tmp_file.close
|
95
|
+
result = copy_file_to_remote_on_hosts_as 'site_user', host_list, tmp_file.path, 'test-file'
|
96
|
+
|
97
|
+
results = run_on_hosts_as 'site_user', host_list, 'cat test-file'
|
98
|
+
assert_equal input_text, results['arch'][0], "remote file should contain input_text"
|
99
|
+
|
100
|
+
assert result, "copy should return true"
|
101
|
+
ensure
|
102
|
+
tmp_file.unlink
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -36,7 +36,7 @@ class DeployTestMethodsTestCase < Test::Unit::TestCase
|
|
36
36
|
assert_equal 'local_admin', @tester.local_admin, "local_admin should be 'local_admin'"
|
37
37
|
assert_equal 'local_admin@bogus.tld', @tester.local_admin_email, "local_admin_email should be 'local_admin@bogus.tld'"
|
38
38
|
# assert_equal 'hosts', @tester.hosts, "hosts should be 'arch'"
|
39
|
-
assert_equal ['
|
39
|
+
assert_equal ['arch'], @tester.hosts, "hosts should be 'arch'"
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_custom_env
|
@@ -65,33 +65,45 @@ class DeployTestMethodsTestCase < Test::Unit::TestCase
|
|
65
65
|
tmp = @tester.deploy_test_in_ssh_session_as 'root', @tester.hosts.first, 'no-file-exists', 'generate an error' do
|
66
66
|
'ls /usr/no-file-exists'
|
67
67
|
end
|
68
|
-
# @tester.
|
68
|
+
# @tester.announce_formatted_test_results
|
69
69
|
@tester.reset_tests
|
70
70
|
refute tmp, "run as root should fail when accessing a non-existent file"
|
71
71
|
|
72
72
|
tmp = @tester.deploy_test_in_ssh_session_as 'root', @tester.hosts.first, "/root", "should run as root on host #{@tester.hosts.first}" do
|
73
73
|
'pwd'
|
74
74
|
end
|
75
|
-
# @tester.
|
75
|
+
# @tester.announce_formatted_test_results
|
76
76
|
@tester.reset_tests
|
77
77
|
assert tmp, "should be able to run on #{@tester.hosts.first} as root"
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
@tester.
|
80
|
+
def test_deploy_test_on_hosts_as
|
81
|
+
result = @tester.deploy_test_on_hosts_as 'root', @tester.hosts, '/root', "can't run as root on all hosts" do
|
82
82
|
'pwd'
|
83
83
|
end
|
84
|
+
assert result, "deploy_test_on_hosts_as works as root on all hosts"
|
84
85
|
end
|
85
86
|
|
86
|
-
def
|
87
|
-
@tester.
|
87
|
+
def test_deploy_test_on_hosts_as_with_string_for_host_list
|
88
|
+
result = @tester.deploy_test_on_hosts_as 'root', 'arch', '/root', "can't run as root on all hosts" do
|
88
89
|
'pwd'
|
89
90
|
end
|
91
|
+
assert result, "deploy_test_on_hosts_as works as root on with string for host_list"
|
90
92
|
end
|
93
|
+
|
94
|
+
def test_file_exists_on_hosts_as
|
95
|
+
result = @tester.deploy_test_file_exists_on_hosts_as "root", 'arch', '/no-such-file', "/no-such-file exists on all hosts"
|
96
|
+
refute result, "test_file_exists_on_hosts_as works on arch as root: #{@tester.formatted_test_results}"
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
98
|
+
result = @tester.deploy_test_file_exists_on_hosts_as "root", 'arch', '/etc/passwd', "/etc/passwd exists on all hosts"
|
99
|
+
assert result, "test_file_exists_on_hosts_as works on arch as root: #{@tester.formatted_test_results}"
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_process_running_on_hosts_as
|
103
|
+
result = @tester.deploy_test_process_running_on_hosts_as 'root', 'arch', '/var/run/no-such-pid', "no-such-pid is not running"
|
104
|
+
refute result, "test_process_running_on_hosts works on arch as roots: #{@tester.formatted_test_results}"
|
105
|
+
|
106
|
+
result = @tester.deploy_test_process_running_on_hosts_as 'root', 'arch','/var/run/crond.pid', "crond is running"
|
107
|
+
assert result, "test_process_running_on_hosts works on arch as root: #{@tester.formatted_test_results}"
|
96
108
|
end
|
97
109
|
end
|
data/tests/test_environ.rb
CHANGED
@@ -50,7 +50,8 @@ class TestEnvironTestCase < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
def test_resonse_to_instance_assessors
|
52
52
|
[:env_hash, :ssh_timeout, :site_base_port, :site_num_servers,
|
53
|
-
:host_admin, :local_admin, :local_admin_email,
|
53
|
+
:host_admin, :local_admin, :local_admin_email,
|
54
|
+
:site, :site_user, :site_path, :site_url,
|
54
55
|
:hosts, :balance_hosts, :db_hosts, :web_hosts].each do |meth|
|
55
56
|
assert @foo.respond_to?(meth), "@foo should respond to #{meth}"
|
56
57
|
assert @foo.respond_to?("#{meth}".to_sym), "@foo should respond to #{meth}="
|
@@ -59,13 +60,13 @@ class TestEnvironTestCase < Test::Unit::TestCase
|
|
59
60
|
|
60
61
|
def test_env_type
|
61
62
|
["ssh_timeout", "site_base_port", "site_num_servers", "host_admin", "local_admin", "local_admin_email",
|
62
|
-
"site", "site_user", "balance_hosts", "db_hosts", "web_hosts"].each do |sym|
|
63
|
+
"site", "site_user", "site_path", "site_url", "balance_hosts", "db_hosts", "web_hosts"].each do |sym|
|
63
64
|
assert @foo.env_types.keys.include?(sym.to_s), "@foo.env_types.keys includes #{sym}"
|
64
65
|
end
|
65
66
|
["ssh_timeout", "site_base_port", "site_num_servers"].each do |key|
|
66
67
|
assert_equal :int, @foo.env_types[key], "@foo.env_types[#{key}] should be :int"
|
67
68
|
end
|
68
|
-
["host_admin", "local_admin", "local_admin_email", "site", "site_user"].each do |key|
|
69
|
+
["host_admin", "local_admin", "local_admin_email", "site", "site_user", "site_path", "site_url"].each do |key|
|
69
70
|
assert_equal :string, @foo.env_types[key], "@foo.env_types[#{key}] should be :string"
|
70
71
|
end
|
71
72
|
["balance_hosts", "db_hosts", "web_hosts"].each do |key|
|
@@ -74,23 +75,27 @@ class TestEnvironTestCase < Test::Unit::TestCase
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def test_hosts_pseudokey
|
77
|
-
@foo.set_env :web_hosts => '', :db_hosts => ''
|
78
|
+
@foo.set_env :web_hosts => '', :db_hosts => '', :balance_hosts => ''
|
78
79
|
assert_equal [], @foo.web_hosts, "assigning '' to web_hosts should create empty list"
|
79
80
|
assert_equal [], @foo.db_hosts, "assigning '' to db_hosts should create empty list"
|
81
|
+
assert_equal [], @foo.balance_hosts, "assigning '' to balance_hosts should create empty list"
|
80
82
|
@foo.set_env :hosts => 'foo,bar'
|
81
83
|
assert_equal ['bar', 'foo'], @foo.hosts, "assigning foo,bar to hosts should create ['bar', 'foo']"
|
84
|
+
['web_hosts', 'db_hosts', 'balance_hosts'].each do |hst|
|
85
|
+
assert_equal @foo.send(hst.to_sym), @foo.hosts, "hosts should be same as @foo.#{hst}"
|
86
|
+
end
|
82
87
|
end
|
83
88
|
|
84
89
|
def test_env_hash
|
85
90
|
["ssh_timeout", "site_base_port", "site_num_servers", "host_admin", "local_admin", "local_admin_email",
|
86
|
-
"site", "site_user", "balance_hosts", "db_hosts", "web_hosts"].each do |key|
|
91
|
+
"site", "site_user", "site_path", "site_url", "balance_hosts", "db_hosts", "web_hosts"].each do |key|
|
87
92
|
assert_not_nil @foo.env_hash[key], "@foo.env_hash[#{key}] should not be nil"
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
96
|
def test_env_defaults
|
92
97
|
["ssh_timeout", "site_base_port", "site_num_servers", "host_admin", "local_admin", "local_admin_email",
|
93
|
-
"site", "site_user", "balance_hosts", "db_hosts", "web_hosts"].each do |key|
|
98
|
+
"site", "site_user", "site_path", "site_url", "balance_hosts", "db_hosts", "web_hosts"].each do |key|
|
94
99
|
assert_not_nil @foo.env_defaults[key], "@foo.env_defaults[#{key}] should not be nil"
|
95
100
|
end
|
96
101
|
end
|
@@ -105,7 +110,7 @@ class TestEnvironTestCase < Test::Unit::TestCase
|
|
105
110
|
@foo.send "#{key}=", tmp
|
106
111
|
assert_equal tmp, @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
|
107
112
|
end
|
108
|
-
["host_admin", "local_admin", "local_admin_email", "site", "site_user"].each do |key|
|
113
|
+
["host_admin", "local_admin", "local_admin_email", "site", "site_user", "site_path", "site_url"].each do |key|
|
109
114
|
tmp = "#{key}-changed"
|
110
115
|
@foo.send "#{key}=", tmp
|
111
116
|
assert_equal tmp, @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
|
@@ -11,6 +11,7 @@ class RemoteIptablesTestCase < Test::Unit::TestCase
|
|
11
11
|
@tester = TddDeploy::RemoteIpTables.new
|
12
12
|
@tester.reset_env
|
13
13
|
@tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
|
14
|
+
@tester.reset_tests
|
14
15
|
end
|
15
16
|
|
16
17
|
def teardown
|
@@ -18,10 +19,16 @@ class RemoteIptablesTestCase < Test::Unit::TestCase
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def test_tcp_some_blocked_ports
|
21
|
-
|
22
|
+
@tester.tcp_some_blocked_ports
|
23
|
+
@tester.hosts.each do |host|
|
24
|
+
assert_equal 0, @tester.failure_count(host), "all tested ports blocked for host #{host}"
|
25
|
+
end
|
22
26
|
end
|
23
|
-
|
24
|
-
def
|
25
|
-
|
27
|
+
|
28
|
+
def test_tcp_some_blocked_ports_non_responsive_host
|
29
|
+
host = 'no-host'
|
30
|
+
@tester.set_env :hosts => host
|
31
|
+
@tester.tcp_some_blocked_ports
|
32
|
+
assert_equal 1, @tester.failure_count(host), "cannot test iptables on non-responding host"
|
26
33
|
end
|
27
34
|
end
|
data/tests/test_run_methods.rb
CHANGED
@@ -11,35 +11,52 @@ class RunMethodsTestCase < Test::Unit::TestCase
|
|
11
11
|
self.reset_env
|
12
12
|
self.set_env :hosts => 'arch,ubuntu', :host_admin => 'mike', :ssh_timeout => 2
|
13
13
|
end
|
14
|
-
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
|
15
|
+
def test_ping_host
|
16
|
+
assert ping_host('localhost'), 'can ping local host'
|
17
|
+
assert ping_host('arch'), 'can ping arch'
|
18
|
+
refute ping_host('ubuntu'), 'cannot ping non-running host'
|
19
|
+
refute ping_host('non-existent-host'), 'cannot ping non-existent-host'
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_run_in_ssh_session_on_host_as
|
23
|
+
stdout, stderr, cmd = run_in_ssh_session_on_host_as 'mike', 'arch', 'pwd'
|
19
24
|
assert_equal "/home/mike\n", stdout, "should be able to run as mike on host arch"
|
20
25
|
assert_nil stderr, "should not return error if can connect to host"
|
21
26
|
assert_equal 'pwd', cmd, 'cmd should be pwd'
|
22
|
-
|
23
|
-
stdout, stderr =
|
24
|
-
'pwd'
|
25
|
-
end
|
27
|
+
|
28
|
+
stdout, stderr = run_in_ssh_session_on_host_as 'mike', 'no-host', 'pwd'
|
26
29
|
refute_equal "/home/mike\n", stdout, "should not return home directory for bad host name"
|
27
30
|
refute_nil stderr, "should return an error message for bad host name"
|
28
31
|
assert_equal 'pwd', cmd, 'cmd should be pwd'
|
29
|
-
|
30
|
-
stdout, stderr =
|
31
|
-
'pwd'
|
32
|
-
end
|
32
|
+
|
33
|
+
stdout, stderr = run_in_ssh_session_on_host_as 'no-user', 'arch', 'pwd'
|
33
34
|
refute_equal "/home/mike\n", stdout, "should not return home directory for bad user name"
|
34
35
|
refute_nil stderr, "should return an error message for bad user name"
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
-
stdout, stderr, cmd =
|
38
|
+
def test_run_in_ssh_session_on_host_as
|
39
|
+
stdout, stderr, cmd = run_in_ssh_session_on_host_as 'mike', 'arch' do
|
40
|
+
'pwd'
|
41
|
+
end
|
39
42
|
assert_equal "/home/mike\n", stdout, "should be able to run as mike on host arch"
|
40
43
|
assert_nil stderr, "should not return error if can connect to host"
|
41
44
|
assert_equal 'pwd', cmd, 'cmd should be pwd'
|
42
45
|
end
|
46
|
+
|
47
|
+
def test_run_on_hosts_as
|
48
|
+
result = run_on_hosts_as 'mike', ['arch', 'arch'], 'pwd'
|
49
|
+
assert_not_nil result, "run_on_hosts_as should not return nil"
|
50
|
+
assert result.is_a?(Hash), "run_on_hosts_as should return an Hash"
|
51
|
+
assert_equal ["/home/mike\n", nil, 'pwd'], result['arch'], "Result['arch'] should have command results"
|
52
|
+
assert_equal 1, result.length, "result length should be 1, not 2"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_run_on_hosts_as_with_string_for_hosts_list
|
56
|
+
result = run_on_hosts_as 'mike', 'arch', 'pwd'
|
57
|
+
assert_not_nil result, "result should work with a single string for a host list"
|
58
|
+
assert_equal ["/home/mike\n", nil, 'pwd'], result['arch'], "run_on_all_hosts_as should work with string for host list"
|
59
|
+
end
|
43
60
|
|
44
61
|
def test_run_on_all_hosts_as
|
45
62
|
results = run_on_all_hosts_as('root') { 'pwd'}
|