vlad 1.0.0

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/test/test_vlad.rb ADDED
@@ -0,0 +1,219 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+
4
+ class TestVlad < VladTestCase
5
+ def test_all_hosts
6
+ util_set_hosts
7
+ assert_equal %w[app.example.com db.example.com], @vlad.all_hosts
8
+ end
9
+
10
+ def test_fetch
11
+ set :foo, 5
12
+ assert_equal 5, @vlad.fetch(:foo)
13
+ end
14
+
15
+ def test_fetch_with_default
16
+ assert_equal 5, @vlad.fetch(:not_here, 5)
17
+ end
18
+
19
+ def test_host
20
+ @vlad.host "test.example.com", :app, :db
21
+ expected = {"test.example.com" => {}}
22
+ assert_equal expected, @vlad.roles[:app]
23
+ assert_equal expected, @vlad.roles[:db]
24
+ end
25
+
26
+ def test_host_invalid
27
+ assert_raise(ArgumentError) { @vlad.host "", :app, :db }
28
+ assert_raise(ArgumentError) { @vlad.host nil, :web }
29
+ end
30
+
31
+ def test_host_multiple_hosts
32
+ @vlad.host "test.example.com", :app, :db
33
+ @vlad.host "yarr.example.com", :app, :db, :no_release => true
34
+
35
+ expected = {
36
+ "test.example.com" => {},
37
+ "yarr.example.com" => {:no_release => true}
38
+ }
39
+
40
+ assert_equal expected, @vlad.roles[:app]
41
+ assert_equal expected, @vlad.roles[:db]
42
+ assert_not_equal(@vlad.roles[:db]["test.example.com"].object_id,
43
+ @vlad.roles[:app]["test.example.com"].object_id)
44
+ end
45
+
46
+ def test_hosts_for_array_of_roles
47
+ util_set_hosts
48
+ assert_equal %w[app.example.com db.example.com], @vlad.hosts_for([:app, :db])
49
+ end
50
+
51
+ def test_hosts_for_one_role
52
+ util_set_hosts
53
+ @vlad.host "app2.example.com", :app
54
+ assert_equal %w[app.example.com app2.example.com], @vlad.hosts_for(:app)
55
+ end
56
+
57
+ def test_hosts_for_multiple_roles
58
+ util_set_hosts
59
+ assert_equal %w[app.example.com db.example.com], @vlad.hosts_for(:app, :db)
60
+ end
61
+
62
+ def test_hosts_for_unique
63
+ util_set_hosts
64
+ @vlad.host "app.example.com", :web
65
+ assert_equal %w[app.example.com db.example.com], @vlad.hosts_for(:app, :db, :web)
66
+ end
67
+
68
+ def test_initialize
69
+ assert_raise(Vlad::ConfigurationError) { @vlad.application }
70
+ assert_raise(Vlad::ConfigurationError) { @vlad.repository }
71
+ end
72
+
73
+ def test_role
74
+ @vlad.role :app, "test.example.com"
75
+ expected = {"test.example.com" => {}}
76
+ assert_equal expected, @vlad.roles[:app]
77
+ end
78
+
79
+ def test_role_multiple_hosts
80
+ @vlad.role :app, "test.example.com"
81
+ @vlad.role :app, "yarr.example.com", :no_release => true
82
+ expected = {
83
+ "test.example.com" => {},
84
+ "yarr.example.com" => {:no_release => true}
85
+ }
86
+ assert_equal expected, @vlad.roles[:app]
87
+ end
88
+
89
+ def test_role_multiple_roles
90
+ @vlad.role :app, "test.example.com", :primary => true
91
+ @vlad.role :db, "yarr.example.com", :no_release => true
92
+ expected_db = { "yarr.example.com" => {:no_release => true} }
93
+ assert_equal expected_db, @vlad.roles[:db]
94
+ expected_app = { "test.example.com" => {:primary => true} }
95
+ assert_equal expected_app, @vlad.roles[:app]
96
+ end
97
+
98
+ def test_remote_task
99
+ t = @vlad.remote_task(:test_task) { 5 }
100
+ assert_equal @task_count + 1, Rake.application.tasks.size
101
+ assert_equal Hash.new, t.options
102
+ end
103
+
104
+ def test_remote_task_all_hosts_by_default
105
+ util_set_hosts
106
+ t = @vlad.remote_task(:test_task) { 5 }
107
+ assert_equal %w[app.example.com db.example.com], t.target_hosts
108
+ end
109
+
110
+ def test_remote_task_environment_override
111
+ old_env_hosts = ENV["HOSTS"]
112
+ ENV["HOSTS"] = 'other1.example.com, other2.example.com'
113
+ util_set_hosts
114
+ t = @vlad.remote_task(:test_task) { 5 }
115
+ assert_equal %w[other1.example.com other2.example.com], t.target_hosts
116
+ ensure
117
+ ENV["HOSTS"] = old_env_hosts
118
+ end
119
+
120
+ def test_remote_task_body_set
121
+ set(:some_variable, 5)
122
+ @vlad.host 'www.example.com', :app
123
+ @vlad.remote_task(:some_task) do $some_task_result = some_variable end
124
+
125
+ Rake::Task['some_task'].execute
126
+ assert_equal @vlad.fetch(:some_variable), $some_task_result
127
+ end
128
+
129
+ def test_remote_task_with_options
130
+ t = @vlad.remote_task :test_task, :roles => [:app, :db] do
131
+ fail "should not run"
132
+ end
133
+ assert_equal({:roles => [:app, :db]}, t.options)
134
+ end
135
+
136
+ def test_remote_task_before_host_declaration
137
+ t = @vlad.remote_task :test_task, :roles => :web do 5 end
138
+ @vlad.host 'www.example.com', :web
139
+ assert_equal %w[www.example.com], t.target_hosts
140
+ end
141
+
142
+ def test_remote_task_role_override
143
+ host "db1", :db
144
+ host "db2", :db
145
+ host "db3", :db
146
+ host "master", :master_db
147
+
148
+ remote_task(:migrate_the_db, :roles => [:db]) { flunk "bad!" }
149
+ task = Rake::Task["migrate_the_db"]
150
+ assert_equal %w[db1 db2 db3], task.target_hosts
151
+
152
+ task.options[:roles] = :master_db
153
+ assert_equal %w[master], task.target_hosts
154
+
155
+ task.options[:roles] = [:master_db]
156
+ assert_equal %w[master], task.target_hosts
157
+ end
158
+
159
+ def test_source
160
+ set :scm, :perforce
161
+ assert_equal "Vlad::Perforce", @vlad.source.class.name
162
+ end
163
+
164
+ def test_source_default
165
+ assert_equal "Vlad::Subversion", @vlad.source.class.name
166
+ end
167
+
168
+ def test_source_singleton
169
+ s1 = @vlad.source
170
+ s2 = @vlad.source
171
+ assert_equal s1.object_id, s2.object_id
172
+ end
173
+
174
+ def test_set
175
+ set :test, 5
176
+ assert_equal 5, @vlad.test
177
+ end
178
+
179
+ def test_set_lazy_block_evaluation
180
+ set(:test) { fail "lose" }
181
+ assert_raise(RuntimeError) { @vlad.test }
182
+ end
183
+
184
+ def test_set_with_block
185
+ x = 1
186
+ set(:test) { x += 2 }
187
+
188
+ assert_equal 3, @vlad.test
189
+ assert_equal 3, @vlad.test
190
+ end
191
+
192
+ def test_set_with_reference
193
+ @vlad.instance_eval do
194
+ set(:var_one) { var_two }
195
+ set(:var_two) { var_three }
196
+ set(:var_three) { 5 }
197
+ end
198
+
199
+ assert_equal 5, @vlad.var_one
200
+ end
201
+
202
+ def test_set_with_block_and_value
203
+ e = assert_raise(ArgumentError) do
204
+ set(:test, 5) { 6 }
205
+ end
206
+ assert_equal "cannot provide both a value and a block", e.message
207
+ end
208
+
209
+ def test_set_with_nil
210
+ set(:test, nil)
211
+ assert_equal nil, @vlad.test
212
+ end
213
+
214
+ def test_set_with_reserved_name
215
+ e = assert_raise(ArgumentError) { set(:all_hosts, []) }
216
+ assert_equal "cannot set reserved name: 'all_hosts'", e.message
217
+ end
218
+ end
219
+
@@ -0,0 +1,38 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/perforce'
4
+
5
+ class TestVladPerforce < VladTestCase
6
+ def setup
7
+ super
8
+ @scm = Vlad::Perforce.new
9
+ Vlad::Perforce.reset
10
+ end
11
+
12
+ def test_checkout
13
+ cmd = @scm.checkout 'head', '/the/place'
14
+ assert_equal 'p4 sync ...#head', cmd
15
+ end
16
+
17
+ def test_checkout_revision
18
+ cmd = @scm.checkout 555, '/the/place'
19
+ assert_equal 'p4 sync ...@555', cmd
20
+ end
21
+
22
+ def test_export
23
+ cmd = @scm.export 'head', '/the/place'
24
+ assert_equal '(cd /the/place && p4 sync ...#head)', cmd
25
+ end
26
+
27
+ def test_revision
28
+ cmd = @scm.revision('head')
29
+ assert_equal '`p4 changes -s submitted -m 1 ...#head | cut -f 2 -d\\ `', cmd
30
+ end
31
+
32
+ def test_rev_no
33
+ assert_equal "@555", @scm.rev_no(555)
34
+ assert_equal "#head", @scm.rev_no('head')
35
+ assert_equal "#head", @scm.rev_no('HEAD')
36
+ assert_equal "@666", @scm.rev_no("@666")
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/subversion'
4
+
5
+ class TestVladSubversion < Test::Unit::TestCase
6
+ def setup
7
+ @scm = Vlad::Subversion.new
8
+ set :repository, "svn+ssh://repo/myproject"
9
+ end
10
+
11
+ def test_checkout
12
+ cmd = @scm.checkout 'HEAD', '/the/place'
13
+ assert_equal 'svn co -r HEAD svn+ssh://repo/myproject /the/place', cmd
14
+ end
15
+
16
+ def test_export
17
+ cmd = @scm.export 'HEAD', '/the/place'
18
+ assert_equal 'svn export -r HEAD svn+ssh://repo/myproject /the/place', cmd
19
+ end
20
+
21
+ def test_revision
22
+ cmd = @scm.revision('HEAD')
23
+ expected = "`svn info svn+ssh://repo/myproject | grep 'Revision:' | cut -f2 -d\\ `"
24
+ assert_equal expected, cmd
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+ require 'vlad'
4
+
5
+ class StringIO
6
+ def readpartial(size) read end # suck!
7
+ end
8
+
9
+ class Rake::RemoteTask
10
+ attr_accessor :commands, :action, :input, :output, :error
11
+
12
+ Status = Struct.new :exitstatus
13
+
14
+ class Status
15
+ def success?() exitstatus == 0 end
16
+ end
17
+
18
+ def system *command
19
+ @commands << command
20
+ self.action ? self.action[command.join(' ')] : true
21
+ end
22
+
23
+ def popen4 *command
24
+ @commands << command
25
+
26
+ @input = StringIO.new
27
+ out = StringIO.new @output.shift.to_s
28
+ err = StringIO.new @error.shift.to_s
29
+
30
+ yield 42, @input, out, err
31
+
32
+ status = self.action ? self.action[command.join(' ')] : 0
33
+ Status.new status
34
+ end
35
+
36
+ def select reads, writes, errs, timeout
37
+ [reads, writes, errs]
38
+ end
39
+
40
+ end
41
+
42
+ class VladTestCase < Test::Unit::TestCase
43
+ undef_method :default_test
44
+
45
+ def setup
46
+ @vlad = Rake::RemoteTask
47
+ Rake.application.clear
48
+ @task_count = Rake.application.tasks.size
49
+ @vlad.set :domain, "example.com"
50
+ end
51
+
52
+ def teardown
53
+ @vlad.env.keys.each { |k| Object.send(:remove_method, k) if @vlad.respond_to?(k) }
54
+ @vlad.reset
55
+ end
56
+
57
+ def util_set_hosts
58
+ @vlad.host "app.example.com", :app
59
+ @vlad.host "db.example.com", :db
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: vlad
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-08-13 00:00:00 -07:00
8
+ summary: The author was too lazy to write a summary
9
+ require_paths:
10
+ - lib
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: http://rubyhitsquad.com/
13
+ rubyforge_project: hitsquad
14
+ description: "Vlad the Deployer is pragmatic application deployment automation, without mercy. Much like Capistrano, but with 1/10th the complexity. Vlad integrates seamlessly with Rake, and uses familiar and standard tools like ssh and rsync. Impale your application on the heartless spike of the Deployer. == FEATURES/PROBLEMS: * Full deployment automation stack. * Supports single server deployment with just 4 variables defined. * Very few dependencies. All simple. * Uses ssh with your ssh settings already in place. * Uses rsync for efficient transfers. * Run remote commands on one or more servers. * Syncs files to one or more servers. * Mix and match local and remote tasks. * Built on rake. easy. * Compatible with all of your tab completion shell script rake-tastic goodness. * Ships with tests that actually pass. * Engine is under 500 lines of code. * Super uper simple. * Does NOT support Windows right now. Coming soon in 1.1. * This is 1.0.0... expect rough edges."
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ryan Davis
31
+ - Eric Hodel
32
+ - Wilson Bilkovich
33
+ files:
34
+ - History.txt
35
+ - Manifest.txt
36
+ - README.txt
37
+ - Rakefile
38
+ - considerations.txt
39
+ - doco/getting_started.txt
40
+ - doco/migration.txt
41
+ - doco/perforce.txt
42
+ - doco/variables.txt
43
+ - lib/rake_remote_task.rb
44
+ - lib/vlad.rb
45
+ - lib/vlad/perforce.rb
46
+ - lib/vlad/subversion.rb
47
+ - lib/vlad_tasks.rb
48
+ - test/test_rake_remote_task.rb
49
+ - test/test_vlad.rb
50
+ - test/test_vlad_perforce.rb
51
+ - test/test_vlad_subversion.rb
52
+ - test/vlad_test_case.rb
53
+ test_files:
54
+ - test/test_rake_remote_task.rb
55
+ - test/test_vlad.rb
56
+ - test/test_vlad_perforce.rb
57
+ - test/test_vlad_subversion.rb
58
+ rdoc_options:
59
+ - --main
60
+ - README.txt
61
+ extra_rdoc_files:
62
+ - History.txt
63
+ - Manifest.txt
64
+ - README.txt
65
+ - considerations.txt
66
+ - doco/getting_started.txt
67
+ - doco/migration.txt
68
+ - doco/perforce.txt
69
+ - doco/variables.txt
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ requirements: []
75
+
76
+ dependencies:
77
+ - !ruby/object:Gem::Dependency
78
+ name: rake
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Version::Requirement
81
+ requirements:
82
+ - - ">"
83
+ - !ruby/object:Gem::Version
84
+ version: 0.0.0
85
+ version:
86
+ - !ruby/object:Gem::Dependency
87
+ name: open4
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Version::Requirement
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.0.0
94
+ version:
95
+ - !ruby/object:Gem::Dependency
96
+ name: hoe
97
+ version_requirement:
98
+ version_requirements: !ruby/object:Gem::Version::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.0
103
+ version: