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
@@ -0,0 +1,17 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'test_helpers'
5
+ require 'tdd_deploy'
6
+
7
+ class TestTddDeployTestCase < Test::Unit::TestCase
8
+
9
+ def test_tdd_deploy
10
+ assert defined?(TddDeploy::Assertions), "TddDeploy::Assertions should be defined"
11
+ assert defined?(TddDeploy::Base), "TddDeploy::Base should be defined"
12
+ assert defined?(TddDeploy::DeployTestMethods), "TddDeploy::DeployTestMethods should be defined"
13
+ assert defined?(TddDeploy::Environ), "TddDeploy::Environ should be defined"
14
+ assert defined?(TddDeploy::RunMethods), "TddDeploy::RunMethods should be defined"
15
+ assert defined?(TddDeploy::VERSION), "TddDeploy::VERSION should be defined"
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'tdd_deploy/environ'
5
+ require 'tdd_deploy/run_methods'
6
+
7
+ class TestTddDeployContextTestCase < Test::Unit::TestCase
8
+ GEM_ROOT = File.expand_path('../..', __FILE__)
9
+ BIN_DIR = File.join(GEM_ROOT, 'bin')
10
+
11
+ include TddDeploy::RunMethods
12
+
13
+ def test_set_env_rb_exists
14
+ assert File.exists?(File.join(BIN_DIR, 'tdd_deploy_context')), "tdd_deploy_context exists"
15
+ end
16
+
17
+ def test_run_context_editor
18
+ stdout, stderr, cmd = run_locally 'quit' do
19
+ "#{File.join(BIN_DIR, 'tdd_deploy_context')}"
20
+ end
21
+ assert_not_nil stdout, "tdd_deploy_context is runable. stderr: #{stderr}"
22
+ assert_nil stderr, "tdd_deploy_context does not generate errors"
23
+ end
24
+
25
+ def test_changing_env
26
+ command = "web_hosts frog toad turtle\nssh_timeout 12\nsave\n"
27
+ stdout, stderr, cmd = run_locally command do
28
+ "#{File.join(BIN_DIR, 'tdd_deploy_context')}"
29
+ end
30
+ assert_not_nil stdout, "successful run should not be nil: stderr: #{stderr}"
31
+ assert_match /"frog"/, stdout, "'frog' should be in stdout"
32
+ assert_match /abort/i, stderr, "tdd_deploy_context generates abort error"
33
+ refute_match /discard/i, stderr, "tdd_deploy_context should not discard edits"
34
+ end
35
+ end
@@ -0,0 +1,59 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'tdd_deploy/run_methods'
5
+
6
+ class TestTddDeployServerTestCase < 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/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_set_env_rb_exists
24
+ assert File.exists?(File.join(BIN_DIR, 'tdd_deploy_server.rb')), "tdd_deploy_server exists"
25
+ end
26
+ #
27
+ # def test_tester_accessors
28
+ # assert_equal PORT, @tester.port, "@tester.port should be #{PORT}"
29
+ # end
30
+ #
31
+ # def test_classes_array
32
+ # @tester.load_all_tests
33
+ # assert_not_nil @tester.test_classes, "@tester.test_classes should not be nil"
34
+ # assert @tester.test_classes.include?(TddDeploy::HostConnection), "@tester.test_classes should contain TddDeploy::HostConnection"
35
+ # end
36
+ #
37
+ # def test_run_all_tests
38
+ # ret = @tester.run_all_tests
39
+ # assert ret, "@tester should run all tests and return true: #{@tester.test_failures}"
40
+ # # puts @tester.test_results
41
+ # end
42
+ #
43
+ # def test_rack_interface
44
+ # code, headers, body = @tester.call({})
45
+ # assert_equal 200, code, "@tester always responds with 200"
46
+ # assert_not_nil body, "body should not be nil"
47
+ # assert_equal 'text/html', headers['Content-Type'], "Content-Type is text/html"
48
+ # assert_equal headers['Content-Length'].to_i, body.join('').length, "Content-Length is the size of body"
49
+ # end
50
+
51
+ # def test_run_server
52
+ # stdout, stderr, cmd = run_locally 'quit' do
53
+ # "#{File.join(BIN_DIR, 'tdd_deploy_server')}"
54
+ # end
55
+ # assert_not_nil stdout, "tdd_deploy_server is runable. stderr: #{stderr}"
56
+ # assert_nil stderr, "tdd_deploy_server does not generate errors"
57
+ # end
58
+
59
+ end
@@ -0,0 +1,97 @@
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/deploy_test_methods'
6
+
7
+ # NOTES: These tests require a host to talk to. I run an Arch Linux server on my local
8
+ # machine as a virtual host. Set up your own with appropriate accounts if you need to run
9
+ # these tests.
10
+
11
+ class DeployTester
12
+ include TddDeploy::Assertions
13
+ include TddDeploy::Environ
14
+ include TddDeploy::RunMethods
15
+ include TddDeploy::DeployTestMethods
16
+
17
+ def initialize env_hash
18
+ self.reset_env
19
+ self.set_env env_hash
20
+ end
21
+ end
22
+
23
+ class DeployTestMethodsTestCase < Test::Unit::TestCase
24
+ def setup
25
+ @tester = DeployTester.new( { :host_admin => 'mike', :local_admin => 'mike', :db_hosts => 'arch',
26
+ :web_hosts => 'arch', :ssh_timeout => 2 } )
27
+ end
28
+
29
+ def teardown
30
+ @tester = nil
31
+ end
32
+
33
+ def test_default_env
34
+ @tester.reset_env
35
+ assert_equal 'host_admin', @tester.host_admin, "host_admin should be 'host_admin'"
36
+ assert_equal 'local_admin', @tester.local_admin, "local_admin should be 'local_admin'"
37
+ assert_equal 'local_admin@bogus.tld', @tester.local_admin_email, "local_admin_email should be 'local_admin@bogus.tld'"
38
+ # assert_equal 'hosts', @tester.hosts, "hosts should be 'arch'"
39
+ assert_equal ['bar', 'foo'], @tester.hosts, "hosts should be 'bar,foo'"
40
+ end
41
+
42
+ def test_custom_env
43
+ @tester.set_env 'host_admin' => 'mike', :local_admin => 'mike', :local_admin_email => 'mike@clove.com'
44
+ assert_equal 'mike', @tester.host_admin, "host_admin should be 'mike'"
45
+ assert_equal 'mike', @tester.local_admin, "local_admin should be 'mike'"
46
+ assert_equal 'mike@clove.com', @tester.local_admin_email, "local_admin_email should be 'mike@clove.com'"
47
+ assert_equal ['arch'], @tester.hosts, "hosts should be 'arch'"
48
+ end
49
+
50
+ def test_force_failure
51
+ result = @tester.deploy_test_in_ssh_session_as 'no-user', @tester.hosts.first, '/home/no-user', 'should fail with bad user' do
52
+ 'pwd'
53
+ end
54
+ refute result, "refute version: should fail with bad userid #{result}"
55
+ end
56
+
57
+ def test_deploy_test_in_ssh_session_as
58
+ assert_raises ArgumentError do
59
+ @tester.deploy_test_in_ssh_session_as 'root', @tester.hosts.first, '', 'session catches empty match expression' do
60
+ 'uname -a'
61
+ end
62
+ @tester.reset_tests
63
+ end
64
+
65
+ tmp = @tester.deploy_test_in_ssh_session_as 'root', @tester.hosts.first, 'no-file-exists', 'generate an error' do
66
+ 'ls /usr/no-file-exists'
67
+ end
68
+ # @tester.announce_test_results
69
+ @tester.reset_tests
70
+ refute tmp, "run as root should fail when accessing a non-existent file"
71
+
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
+ 'pwd'
74
+ end
75
+ # @tester.announce_test_results
76
+ @tester.reset_tests
77
+ assert tmp, "should be able to run on #{@tester.hosts.first} as root"
78
+ end
79
+
80
+ def test_deploy_test_in_ssh_session
81
+ @tester.deploy_test_in_ssh_session @tester.hosts.first, "/home/#{@tester.host_admin}", "can't run as #{@tester.host_admin} on host" do
82
+ 'pwd'
83
+ end
84
+ end
85
+
86
+ def test_deploy_test_on_all_hosts_as
87
+ @tester.deploy_test_on_all_hosts_as 'root', '/root', "can't run as root on all hosts" do
88
+ 'pwd'
89
+ end
90
+ end
91
+
92
+ def test_deploy_test_on_all_hosts
93
+ @tester.deploy_test_on_all_hosts "/home/#{@tester.host_admin}", 'can\'t run on some hosts' do
94
+ 'pwd'
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tdd_deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Howard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &2165185440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2165185440
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-ping
27
+ requirement: &2165184940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2165184940
36
+ - !ruby/object:Gem::Dependency
37
+ name: net-ssh
38
+ requirement: &2165184400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2165184400
47
+ - !ruby/object:Gem::Dependency
48
+ name: ZenTest
49
+ requirement: &2165183760 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 4.5.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2165183760
58
+ - !ruby/object:Gem::Dependency
59
+ name: autotest-growl
60
+ requirement: &2165183240 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2165183240
69
+ description: Test driven support for host provisioning & Capistrano deployment - for
70
+ those who don't want to bother learning too much
71
+ email: ! ' mike@clove.com '
72
+ executables:
73
+ - tdd_deploy_context
74
+ - tdd_deploy_server.rb
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - Capfile
79
+ - Gemfile
80
+ - config.ru
81
+ - bin/tdd_deploy_context
82
+ - bin/tdd_deploy_server.rb
83
+ - lib/tdd_deploy/assertions.rb
84
+ - lib/tdd_deploy/base.rb
85
+ - lib/tdd_deploy/deploy_test_methods.rb
86
+ - lib/tdd_deploy/environ.rb
87
+ - lib/tdd_deploy/host_tests/host_connection.rb
88
+ - lib/tdd_deploy/host_tests/remote_ip_tables.rb
89
+ - lib/tdd_deploy/host_tests/remote_monit.rb
90
+ - lib/tdd_deploy/host_tests/remote_nginx.rb
91
+ - lib/tdd_deploy/host_tests/remote_postfix.rb
92
+ - lib/tdd_deploy/host_tests/remote_postgresql.rb
93
+ - lib/tdd_deploy/railengine.rb
94
+ - lib/tdd_deploy/run_methods.rb
95
+ - lib/tdd_deploy/server.rb
96
+ - lib/tdd_deploy/site_tests/site_layout.rb
97
+ - lib/tdd_deploy/site_tests/site_user.rb
98
+ - lib/tdd_deploy/version.rb
99
+ - lib/tdd_deploy.rb
100
+ - tests/test_assertions.rb
101
+ - tests/test_base.rb
102
+ - tests/test_colored_tests.rb
103
+ - tests/test_environ.rb
104
+ - tests/test_helpers.rb
105
+ - tests/test_host_tests.rb
106
+ - tests/test_remote_ip_tables.rb
107
+ - tests/test_remote_monit.rb
108
+ - tests/test_remote_nginx.rb
109
+ - tests/test_remote_postfix.rb
110
+ - tests/test_remote_postgresql.rb
111
+ - tests/test_run_methods.rb
112
+ - tests/test_server.rb
113
+ - tests/test_site_layout.rb
114
+ - tests/test_site_user.rb
115
+ - tests/test_tdd_deploy.rb
116
+ - tests/test_tdd_deploy_context.rb
117
+ - tests/test_tdd_deploy_server.rb
118
+ - tests/test_test_deploy_methods.rb
119
+ - lib/tasks/tdd_deploy.rake
120
+ homepage: https://github.com/mikehoward/tdd_deploy
121
+ licenses:
122
+ - GPL3
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: 1.9.2
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.6
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Test driven support for host provisioning & Capistrano deployment - for those
145
+ who don't want to bother learning too much
146
+ test_files: []