tdd_deploy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Capfile +12 -0
  2. data/Gemfile +9 -0
  3. data/bin/tdd_deploy_context +132 -0
  4. data/bin/tdd_deploy_server.rb +6 -0
  5. data/config.ru +6 -0
  6. data/lib/tasks/tdd_deploy.rake +24 -0
  7. data/lib/tdd_deploy/assertions.rb +146 -0
  8. data/lib/tdd_deploy/base.rb +62 -0
  9. data/lib/tdd_deploy/deploy_test_methods.rb +65 -0
  10. data/lib/tdd_deploy/environ.rb +272 -0
  11. data/lib/tdd_deploy/host_tests/host_connection.rb +29 -0
  12. data/lib/tdd_deploy/host_tests/remote_ip_tables.rb +34 -0
  13. data/lib/tdd_deploy/host_tests/remote_monit.rb +17 -0
  14. data/lib/tdd_deploy/host_tests/remote_nginx.rb +17 -0
  15. data/lib/tdd_deploy/host_tests/remote_postfix.rb +23 -0
  16. data/lib/tdd_deploy/host_tests/remote_postgresql.rb +17 -0
  17. data/lib/tdd_deploy/railengine.rb +10 -0
  18. data/lib/tdd_deploy/run_methods.rb +126 -0
  19. data/lib/tdd_deploy/server.rb +58 -0
  20. data/lib/tdd_deploy/site_tests/site_layout.rb +46 -0
  21. data/lib/tdd_deploy/site_tests/site_user.rb +14 -0
  22. data/lib/tdd_deploy/version.rb +3 -0
  23. data/lib/tdd_deploy.rb +12 -0
  24. data/tests/test_assertions.rb +62 -0
  25. data/tests/test_base.rb +20 -0
  26. data/tests/test_colored_tests.rb +47 -0
  27. data/tests/test_environ.rb +153 -0
  28. data/tests/test_helpers.rb +10 -0
  29. data/tests/test_host_tests.rb +31 -0
  30. data/tests/test_remote_ip_tables.rb +27 -0
  31. data/tests/test_remote_monit.rb +27 -0
  32. data/tests/test_remote_nginx.rb +27 -0
  33. data/tests/test_remote_postfix.rb +27 -0
  34. data/tests/test_remote_postgresql.rb +27 -0
  35. data/tests/test_run_methods.rb +89 -0
  36. data/tests/test_server.rb +46 -0
  37. data/tests/test_site_layout.rb +34 -0
  38. data/tests/test_site_user.rb +21 -0
  39. data/tests/test_tdd_deploy.rb +17 -0
  40. data/tests/test_tdd_deploy_context.rb +35 -0
  41. data/tests/test_tdd_deploy_server.rb +59 -0
  42. data/tests/test_test_deploy_methods.rb +97 -0
  43. metadata +146 -0
data/lib/tdd_deploy.rb ADDED
@@ -0,0 +1,12 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+
3
+ require 'tdd_deploy/base'
4
+ require 'tdd_deploy/assertions'
5
+ require 'tdd_deploy/deploy_test_methods'
6
+ require 'tdd_deploy/environ'
7
+ require 'tdd_deploy/run_methods'
8
+ require 'tdd_deploy/version'
9
+
10
+ if defined? Rails
11
+ require 'tdd_deploy/railengine'
12
+ end
@@ -0,0 +1,62 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/assertions'
4
+
5
+ class AssertionHelper
6
+ include TddDeploy::Assertions
7
+ end
8
+
9
+ class TestTddDeployAssertionsTestCase < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @assertion_helper = AssertionHelper.new
13
+ @assertion_helper.reset_tests
14
+ end
15
+
16
+ def teardown
17
+ @assertion_helper = nil
18
+ end
19
+
20
+ def test_assert_true_passes
21
+ assert @assertion_helper.assert(true, 'true is true'), 'true tests true'
22
+ assert_match /Pass/i, @assertion_helper.test_results, "test messagess should include 'Pass'"
23
+ end
24
+
25
+ def test_assert_false_fails
26
+ refute @assertion_helper.assert(false, 'true is true'), "false tests false"
27
+ assert_match /Fail/i, @assertion_helper.test_results, "test messages should include 'Fail'"
28
+ assert_match /1 Failed/, @assertion_helper.test_results, "test messages should count 1 failure (#{@assertion_helper.test_messages})"
29
+ end
30
+
31
+ def test_assert_equal
32
+ assert @assertion_helper.assert_equal(true, true, "true is still true"), "true is true"
33
+ end
34
+
35
+ def test_assert_match
36
+ assert @assertion_helper.assert_match('^foo$', 'foo', 'foo is not bar'), 'foo is not bar'
37
+ end
38
+
39
+ def test_assert_nil
40
+ assert @assertion_helper.assert_nil(nil, "nil is nil"), "nil is nil"
41
+ end
42
+
43
+ def test_assert_not_nil
44
+ assert @assertion_helper.assert_not_nil('foo', 'foo is not nil'), 'foo is not nil'
45
+ end
46
+
47
+ def test_assert_raises
48
+ assert @assertion_helper.assert_raises(Exception, '1/0 raises something') { 1/0 }, '1/0 raises something'
49
+ end
50
+
51
+ def test_refute
52
+ assert @assertion_helper.refute(false, 'false is false'), 'false is false'
53
+ end
54
+
55
+ def test_refute_equal
56
+ assert @assertion_helper.refute_equal(false, true, "false is not true"), "false is not true"
57
+ end
58
+
59
+ def test_fail
60
+ refute @assertion_helper.fail('fail returns false'), 'fail returns false'
61
+ end
62
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('../', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'test_helpers'
5
+ require 'tdd_deploy/base'
6
+
7
+ module TestBase
8
+ class Foo < TddDeploy::Base
9
+ end
10
+
11
+ class Bar < TddDeploy::Base
12
+ end
13
+ end
14
+
15
+ class TestBaseTestCase < Test::Unit::TestCase
16
+ def test_tdd_deploy_base_children
17
+ assert TddDeploy::Base.children.include?(TestBase::Foo), "TddDeploy::Base.children should contain TestBase::Foo"
18
+ assert TddDeploy::Base.children.include?(TestBase::Bar), "TddDeploy::Base.children should contain TestBase::Bar"
19
+ end
20
+ end
@@ -0,0 +1,47 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/base'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class ColoredResult < TddDeploy::Base
10
+ def passing_test
11
+ deploy_test_on_all_hosts 'true', 'true always passes' do
12
+ 'echo "true"'
13
+ end
14
+ end
15
+
16
+ def failing_test
17
+ deploy_test_on_all_hosts 'false', 'false always fails' do
18
+ 'echo "true"'
19
+ end
20
+ end
21
+ end
22
+
23
+ class ColoredResultTestCase < Test::Unit::TestCase
24
+ def setup
25
+ @tester = ColoredResult.new( { :host_admin => 'mike', :local_admin => 'mike', :db_hosts => 'arch',
26
+ :web_hosts => 'arch', :ssh_timeout => 2 } )
27
+ @tester.reset_tests
28
+ end
29
+
30
+ def teardown
31
+ @tester = nil
32
+ # we need to delete this guy so it doesn't mess up the testing of server.rb
33
+ TddDeploy::Base.children.delete ColoredResult
34
+ end
35
+
36
+ def test_passing_result
37
+ @tester.passing_test
38
+ test_results = @tester.test_results
39
+ assert_match 'style="color:#0c0"', test_results, "Passing Test result should be colored Green: color:#0c0"
40
+ end
41
+
42
+ def test_failing_result
43
+ @tester.failing_test
44
+ test_results = @tester.test_results
45
+ assert_match 'style="color:#c00"', test_results, "Passing Test result should be colored Red: color:#c00"
46
+ end
47
+ end
@@ -0,0 +1,153 @@
1
+ $:.unshift File.expand_path('../', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'test_helpers'
5
+ require 'tdd_deploy/environ'
6
+
7
+ module TestEnviron
8
+ class Base
9
+ include TddDeploy::Environ
10
+ end
11
+
12
+ class Foo < Base
13
+ end
14
+
15
+ class Bar < Base
16
+ end
17
+ end
18
+
19
+ class TestEnvironTestCase < Test::Unit::TestCase
20
+ include TddDeploy::Environ
21
+
22
+ def setup
23
+ @foo = TestEnviron::Foo.new
24
+ @foo.reset_env
25
+ end
26
+
27
+ def teardown
28
+ @foo.reset_env
29
+ @foo.save_env
30
+ end
31
+
32
+ def test_exsistence_of_public_methods
33
+ [:reset_env, :read_env, :reset_env].each do |meth|
34
+ assert @foo.respond_to?(meth), "@foo should respond to #{meth}"
35
+ end
36
+ end
37
+ def test_response_to_accessors
38
+ [:env_hash].each do |meth|
39
+ assert @foo.respond_to?("#{meth}".to_sym), "@foo should respond to #{meth}"
40
+ assert @foo.respond_to?("#{meth}=".to_sym), "@foo should respond to #{meth}="
41
+ refute_nil @foo.send(meth), "@foo.#{meth} should not be nil"
42
+ end
43
+ end
44
+ def test_response_to_readers
45
+ [:env_defaults, :env_types].each do |meth|
46
+ assert @foo.respond_to?("#{meth}".to_sym), "@foo should respond to #{meth}"
47
+ refute_nil @foo.send(meth), "@foo.#{meth} should not be nil"
48
+ end
49
+ end
50
+
51
+ def test_resonse_to_instance_assessors
52
+ [:env_hash, :ssh_timeout, :site_base_port, :site_num_servers,
53
+ :host_admin, :local_admin, :local_admin_email, :site, :site_user,
54
+ :hosts, :balance_hosts, :db_hosts, :web_hosts].each do |meth|
55
+ assert @foo.respond_to?(meth), "@foo should respond to #{meth}"
56
+ assert @foo.respond_to?("#{meth}".to_sym), "@foo should respond to #{meth}="
57
+ end
58
+ end
59
+
60
+ def test_env_type
61
+ ["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
+ assert @foo.env_types.keys.include?(sym.to_s), "@foo.env_types.keys includes #{sym}"
64
+ end
65
+ ["ssh_timeout", "site_base_port", "site_num_servers"].each do |key|
66
+ assert_equal :int, @foo.env_types[key], "@foo.env_types[#{key}] should be :int"
67
+ end
68
+ ["host_admin", "local_admin", "local_admin_email", "site", "site_user"].each do |key|
69
+ assert_equal :string, @foo.env_types[key], "@foo.env_types[#{key}] should be :string"
70
+ end
71
+ ["balance_hosts", "db_hosts", "web_hosts"].each do |key|
72
+ assert_equal :list, @foo.env_types[key], "@foo.env_types[#{key}] should be :list"
73
+ end
74
+ end
75
+
76
+ def test_hosts_pseudokey
77
+ @foo.set_env :web_hosts => '', :db_hosts => ''
78
+ assert_equal [], @foo.web_hosts, "assigning '' to web_hosts should create empty list"
79
+ assert_equal [], @foo.db_hosts, "assigning '' to db_hosts should create empty list"
80
+ @foo.set_env :hosts => 'foo,bar'
81
+ assert_equal ['bar', 'foo'], @foo.hosts, "assigning foo,bar to hosts should create ['bar', 'foo']"
82
+ end
83
+
84
+ def test_env_hash
85
+ ["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|
87
+ assert_not_nil @foo.env_hash[key], "@foo.env_hash[#{key}] should not be nil"
88
+ end
89
+ end
90
+
91
+ def test_env_defaults
92
+ ["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|
94
+ assert_not_nil @foo.env_defaults[key], "@foo.env_defaults[#{key}] should not be nil"
95
+ end
96
+ end
97
+
98
+ def test_instance_assignment_accessors
99
+ assert_equal @foo.env_hash['ssh_timeout'], @foo.ssh_timeout, "@foo.ssh_timeout == @foo.env_hash['ssh_timeout']"
100
+ ssh_timeout = @foo.ssh_timeout
101
+ @foo.ssh_timeout += 12
102
+ assert_equal(ssh_timeout + 12, @foo.ssh_timeout, "@foo.ssh_timeout == #{ssh_timeout + 12}")
103
+ ["ssh_timeout", "site_base_port", "site_num_servers"].each do |key|
104
+ tmp = @foo.send(key.to_sym) + 12
105
+ @foo.send "#{key}=", tmp
106
+ assert_equal tmp, @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
107
+ end
108
+ ["host_admin", "local_admin", "local_admin_email", "site", "site_user"].each do |key|
109
+ tmp = "#{key}-changed"
110
+ @foo.send "#{key}=", tmp
111
+ assert_equal tmp, @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
112
+ end
113
+ ["balance_hosts", "db_hosts", "web_hosts"].each do |key|
114
+ tmp = @foo.send(key.to_sym).join(',') + ',new,values'
115
+ @foo.send "#{key}=", tmp
116
+ assert_equal tmp.split(/,/), @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
117
+ end
118
+ end
119
+
120
+ def test_instance_level_reset_env
121
+ tmp = @foo.env_hash['ssh_timeout']
122
+ @foo.set_env 'ssh_timeout' => 12
123
+ assert_equal 12, @foo.env_hash['ssh_timeout'], "reset_env should change env_hash"
124
+ assert_equal 12, @foo.ssh_timeout, "reset_env change should show up in instance method"
125
+ end
126
+
127
+ def test_instance_env_hash_assign
128
+ assert_raises(ArgumentError) { @foo.env_hash = 'a string' }
129
+ assert_raises(ArgumentError) {@foo.env_hash = {'foo' => 'bar'}}
130
+ end
131
+
132
+ def test_save_env
133
+ zap_hash = Hash[ @foo.env_types.keys.map { |k| [k, nil] } ]
134
+ @foo.env_hash = zap_hash
135
+ @foo.save_env
136
+ @foo.read_env
137
+ @foo.env_hash.each do |k, v|
138
+ case @foo.env_types[k]
139
+ when :int then expect = 0
140
+ when :string then expect = ''
141
+ when :list then expect = []
142
+ end
143
+ assert_equal expect, @foo.env_hash[k], "After Zapping, env_hash['#{k}'] should be #{expect}"
144
+ assert_equal expect, @foo.send(k.to_sym), "After Zapping, @foo.#{k} should be #{expect}"
145
+ end
146
+ end
147
+
148
+ def test_transfer_env
149
+ @foo.ssh_timeout = 401
150
+ bar = TestEnviron::Bar.new
151
+ assert_equal 401, bar.ssh_timeout, "Setting env in one object should transfer to another"
152
+ end
153
+ end
@@ -0,0 +1,10 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # Add bundler setup to load path
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ # $:.each { |x| puts x }
7
+
8
+ require 'test/unit'
9
+ require 'net/ssh'
10
+ require 'capistrano'
@@ -0,0 +1,31 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/host_tests/host_connection'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class HostTestsTestCase < Test::Unit::TestCase
10
+ def setup
11
+ @tester = TddDeploy::HostConnection.new
12
+ @tester.reset_env
13
+ @tester.set_env :web_hosts => 'arch', :db_hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
14
+ end
15
+
16
+ def teardown
17
+ @tester = nil
18
+ end
19
+
20
+ def test_ping
21
+ assert @tester.ping, "Can ping #{@tester.hosts.join(',')}"
22
+ end
23
+
24
+ def test_ssh_login
25
+ assert @tester.ssh_login, "Can login #{@tester.hosts.join(',')} as #{@tester.host_admin}"
26
+ end
27
+
28
+ def test_ssh_login_as_root
29
+ assert @tester.ssh_login_as_root, "Can login to #{@tester.hosts.join(',')} as root"
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/host_tests/remote_ip_tables'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class RemoteIptablesTestCase < Test::Unit::TestCase
10
+ def setup
11
+ @tester = TddDeploy::RemoteIpTables.new
12
+ @tester.reset_env
13
+ @tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
14
+ end
15
+
16
+ def teardown
17
+ @tester = nil
18
+ end
19
+
20
+ def test_tcp_some_blocked_ports
21
+ assert @tester.tcp_some_blocked_ports
22
+ end
23
+
24
+ def test_udp_some_blocked_ports
25
+ assert @tester.udp_some_blocked_ports
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/host_tests/remote_monit'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class RemoteMonitTestCase < Test::Unit::TestCase
10
+ def setup
11
+ @tester = TddDeploy::RemoteMonit.new
12
+ @tester.reset_env
13
+ @tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
14
+ end
15
+
16
+ def teardown
17
+ @tester = nil
18
+ end
19
+
20
+ def test_monit_installed
21
+ assert @tester.test_monit_installed, "monit is installed"
22
+ end
23
+
24
+ def test_monit_running
25
+ assert @tester.test_monit_running, "monit is running"
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/host_tests/remote_nginx'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class RemoteNginxTestCase < Test::Unit::TestCase
10
+ def setup
11
+ @tester = TddDeploy::RemoteNginx.new
12
+ @tester.reset_env
13
+ @tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
14
+ end
15
+
16
+ def teardown
17
+ @tester = nil
18
+ end
19
+
20
+ def test_nginx_installed
21
+ assert @tester.test_nginx_installed, 'nginx installed'
22
+ end
23
+
24
+ def test_nginx_running
25
+ assert @tester.test_nginx_running, 'nginx is running'
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/host_tests/remote_postfix'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class RemotePostfixTestCase < Test::Unit::TestCase
10
+ def setup
11
+ @tester = TddDeploy::RemotePostfix.new
12
+ @tester.reset_env
13
+ @tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
14
+ end
15
+
16
+ def teardown
17
+ @tester = nil
18
+ end
19
+
20
+ def test_postfix_installed
21
+ assert @tester.test_postfix_installed, "postfix is installed"
22
+ end
23
+
24
+ def test_postfix_running
25
+ assert @tester.test_postfix_running, "postfix is running"
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/host_tests/remote_postgresql'
4
+
5
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
6
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
7
+ # these tests.
8
+
9
+ class RemotePostgresqlTestCase < Test::Unit::TestCase
10
+ def setup
11
+ @tester = TddDeploy::RemotePostgresql.new
12
+ @tester.reset_env
13
+ @tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
14
+ end
15
+
16
+ def teardown
17
+ @tester = nil
18
+ end
19
+
20
+ def test_postgresql_installed
21
+ assert @tester.test_postgresql_installed, "postgresql is installed"
22
+ end
23
+
24
+ def test_postgreql_running
25
+ assert @tester.test_postgresql_running, "postgresql is running"
26
+ end
27
+ end
@@ -0,0 +1,89 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/environ'
4
+ require 'tdd_deploy/run_methods'
5
+
6
+ class RunMethodsTestCase < Test::Unit::TestCase
7
+ include TddDeploy::Environ
8
+ include TddDeploy::RunMethods
9
+
10
+ def setup
11
+ self.reset_env
12
+ self.set_env :hosts => 'arch,ubuntu', :host_admin => 'mike', :ssh_timeout => 2
13
+ end
14
+
15
+ def test_run_in_ssh_session_as
16
+ stdout, stderr, cmd = run_in_ssh_session_as 'mike', 'arch' do
17
+ 'pwd'
18
+ end
19
+ assert_equal "/home/mike\n", stdout, "should be able to run as mike on host arch"
20
+ assert_nil stderr, "should not return error if can connect to host"
21
+ assert_equal 'pwd', cmd, 'cmd should be pwd'
22
+
23
+ stdout, stderr = run_in_ssh_session_as 'mike', 'no-host' do
24
+ 'pwd'
25
+ end
26
+ refute_equal "/home/mike\n", stdout, "should not return home directory for bad host name"
27
+ refute_nil stderr, "should return an error message for bad host name"
28
+ assert_equal 'pwd', cmd, 'cmd should be pwd'
29
+
30
+ stdout, stderr = run_in_ssh_session_as 'no-user', 'arch' do
31
+ 'pwd'
32
+ end
33
+ refute_equal "/home/mike\n", stdout, "should not return home directory for bad user name"
34
+ refute_nil stderr, "should return an error message for bad user name"
35
+ end
36
+
37
+ def test_run_in_ssh_session
38
+ stdout, stderr, cmd = run_in_ssh_session('arch') { 'pwd' }
39
+ assert_equal "/home/mike\n", stdout, "should be able to run as mike on host arch"
40
+ assert_nil stderr, "should not return error if can connect to host"
41
+ assert_equal 'pwd', cmd, 'cmd should be pwd'
42
+ end
43
+
44
+ def test_run_on_all_hosts_as
45
+ results = run_on_all_hosts_as('root') { 'pwd'}
46
+ refute_nil results, "results should not be nil"
47
+ assert results.is_a?(Hash), "results should be a Hash"
48
+ assert_equal 2, results.size, "results should have two entries"
49
+
50
+ assert_equal "/root\n", results['arch'][0], "should run correctly on arch"
51
+ assert_nil results['arch'][1], "no errors on arch"
52
+ assert_equal results['arch'][2], 'pwd', 'cmd should be pwd'
53
+
54
+ assert_nil results['ubuntu'][0], "no stdout for ubuntu"
55
+ refute_nil results['ubuntu'][1], 'failure message for ubuntu'
56
+ assert_equal results['ubuntu'][2], 'pwd', 'cmd should be pwd'
57
+ end
58
+
59
+ def test_run_on_all_hosts
60
+ results = run_on_all_hosts { 'pwd' }
61
+
62
+ assert_equal "/home/mike\n", results['arch'][0], "should run correctly on arch"
63
+ assert_nil results['arch'][1], "no errors on arch"
64
+ assert_equal results['arch'][2], 'pwd', 'cmd should be pwd'
65
+
66
+ assert_nil results['ubuntu'][0], "no stdout for ubuntu"
67
+ refute_nil results['ubuntu'][1], 'failure message for ubuntu'
68
+ assert_equal results['ubuntu'][2], 'pwd', 'cmd should be pwd'
69
+ end
70
+
71
+ def test_run_locally
72
+ stdout, stderr, cmd = run_locally { 'echo foo' }
73
+ assert_equal "foo\n", stdout, "echo foo should echo foo\\n"
74
+ assert_nil stderr, "stderr should be nil"
75
+ assert_equal 'echo foo', cmd, "cmd should be 'echo foo'"
76
+
77
+ stdout, stderr, cmd = run_locally { 'bad-command foo' }
78
+ assert_nil stdout, "stdout should be nil for bad command"
79
+ refute_nil stderr, "stderr should not be nil"
80
+ assert_equal 'bad-command foo', cmd, "cmd should be 'bad-command foo'"
81
+ end
82
+
83
+ def test_run_locally_with_input
84
+ input_text = "one line of text\n"
85
+ stdout, stderr, cmd = run_locally(input_text) { 'cat -' }
86
+ assert_equal input_text, stdout, "command should echo input: '#{input_text}"
87
+ assert_nil stderr, "command should not generate errs"
88
+ end
89
+ end
@@ -0,0 +1,46 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'tdd_deploy/run_methods'
5
+
6
+ class TestServerTestCase < Test::Unit::TestCase
7
+ GEM_ROOT = File.expand_path('../..', __FILE__)
8
+ BIN_DIR = File.join(GEM_ROOT, 'bin')
9
+ PORT = 8809
10
+
11
+ include TddDeploy::RunMethods
12
+
13
+ def setup
14
+ require 'tdd_deploy/server'
15
+ @tester = TddDeploy::Server.new(PORT, :web_hosts => 'arch', :db_hosts => 'arch',
16
+ :host_admin => 'mike', :local_admin => 'mike', :ssh_timeout => 2)
17
+ end
18
+
19
+ def teardown
20
+ @tester = nil
21
+ end
22
+
23
+ def test_tester_accessors
24
+ assert_equal PORT, @tester.port, "@tester.port should be #{PORT}"
25
+ end
26
+
27
+ def test_classes_array
28
+ @tester.load_all_tests
29
+ assert_not_nil @tester.test_classes, "@tester.test_classes should not be nil"
30
+ assert @tester.test_classes.include?(TddDeploy::HostConnection), "@tester.test_classes should contain TddDeploy::HostConnection"
31
+ end
32
+
33
+ def test_run_all_tests
34
+ ret = @tester.run_all_tests
35
+ assert ret, "@tester should run all tests and return true: #{@tester.test_failures}"
36
+ # puts @tester.test_results
37
+ end
38
+
39
+ def test_rack_interface
40
+ code, headers, body = @tester.call({})
41
+ assert_equal 200, code, "@tester always responds with 200"
42
+ assert_not_nil body, "body should not be nil"
43
+ assert_equal 'text/html', headers['Content-Type'], "Content-Type is text/html"
44
+ assert_equal headers['Content-Length'].to_i, body.join('').length, "Content-Length is the size of body"
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/site_tests/site_layout'
4
+
5
+ class TestSiteLayoutTestCase < Test::Unit::TestCase
6
+ def setup
7
+ @tester = TddDeploy::SiteLayout.new
8
+ @tester.reset_env
9
+ @tester.set_env :hosts => 'arch'
10
+ @tester.reset_tests
11
+ end
12
+
13
+ def teardown
14
+ @tester = nil
15
+ end
16
+
17
+ def test_site_home
18
+ assert @tester.test_site_subdir, "Directory /home/#{@tester.site_user}/#{@tester.site} should exist"
19
+ end
20
+
21
+ def test_site_releases
22
+ assert @tester.test_releases_subdir, "Directory /home/#{@tester.site_user}/#{@tester.site}/releases should exist"
23
+ end
24
+
25
+ def test_site_nginx_conf
26
+ assert @tester.test_nginx_conf, "Directory /home/#{@tester.site_user}/nginx_conf should exist"
27
+ end
28
+
29
+ def test_site_monitrc
30
+ assert @tester.test_monitrc, "Directory /home/#{@tester.site_user}/monitrc should exist"
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,21 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ require 'test_helpers'
3
+ require 'tdd_deploy/site_tests/site_user'
4
+
5
+ class TestSiteUserTestCase < Test::Unit::TestCase
6
+ def setup
7
+ @tester = TddDeploy::SiteUser.new
8
+ @tester.reset_env
9
+ @tester.set_env :hosts => 'arch', :host_admin => 'mike', :local_admin => 'mike'
10
+ end
11
+
12
+ def teardown
13
+ @tester = nil
14
+ end
15
+
16
+ def test_login_as_site_user
17
+ assert @tester.test_login_as_site_user, "Unable to login to some hosts as #{@tester.site_user}"
18
+ end
19
+ end
20
+
21
+