le1t0-capistrano 2.5.18.001
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/CHANGELOG +843 -0
- data/README +102 -0
- data/Rakefile +36 -0
- data/VERSION +1 -0
- data/bin/cap +4 -0
- data/bin/capify +86 -0
- data/lib/capistrano.rb +2 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/cli/execute.rb +85 -0
- data/lib/capistrano/cli/help.rb +125 -0
- data/lib/capistrano/cli/help.txt +78 -0
- data/lib/capistrano/cli/options.rb +243 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/command.rb +283 -0
- data/lib/capistrano/configuration.rb +44 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +52 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +295 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +204 -0
- data/lib/capistrano/configuration/execution.rb +143 -0
- data/lib/capistrano/configuration/loading.rb +197 -0
- data/lib/capistrano/configuration/namespaces.rb +197 -0
- data/lib/capistrano/configuration/roles.rb +73 -0
- data/lib/capistrano/configuration/servers.rb +98 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +19 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/logger.rb +59 -0
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +589 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +278 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +138 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +218 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +260 -0
- data/lib/capistrano/ssh.rb +99 -0
- data/lib/capistrano/task_definition.rb +75 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +329 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +286 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +65 -0
- data/test/configuration/actions/invocation_test.rb +225 -0
- data/test/configuration/callbacks_test.rb +220 -0
- data/test/configuration/connections_test.rb +349 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +132 -0
- data/test/configuration/namespace_dsl_test.rb +311 -0
- data/test/configuration/roles_test.rb +144 -0
- data/test/configuration/servers_test.rb +158 -0
- data/test/configuration/variables_test.rb +184 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +114 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/bzr_test.rb +51 -0
- data/test/deploy/scm/darcs_test.rb +37 -0
- data/test/deploy/scm/git_test.rb +184 -0
- data/test/deploy/scm/mercurial_test.rb +134 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/scm/subversion_test.rb +32 -0
- data/test/deploy/strategy/copy_test.rb +302 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_test.rb +123 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +90 -0
- data/test/ssh_test.rb +104 -0
- data/test/task_definition_test.rb +116 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +39 -0
- metadata +289 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/recipes/deploy/scm/git'
|
3
|
+
|
4
|
+
class DeploySCMGitTest < Test::Unit::TestCase
|
5
|
+
class TestSCM < Capistrano::Deploy::SCM::Git
|
6
|
+
default_command "git"
|
7
|
+
end
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@config = { :repository => "." }
|
11
|
+
def @config.exists?(name); key?(name); end
|
12
|
+
|
13
|
+
@source = TestSCM.new(@config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_head
|
17
|
+
assert_equal "HEAD", @source.head
|
18
|
+
|
19
|
+
# With :branch
|
20
|
+
@config[:branch] = "master"
|
21
|
+
assert_equal "master", @source.head
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_origin
|
25
|
+
assert_equal "origin", @source.origin
|
26
|
+
@config[:remote] = "username"
|
27
|
+
assert_equal "username", @source.origin
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_checkout
|
31
|
+
@config[:repository] = "git@somehost.com:project.git"
|
32
|
+
dest = "/var/www"
|
33
|
+
rev = 'c2d9e79'
|
34
|
+
assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
35
|
+
|
36
|
+
# With :scm_command
|
37
|
+
git = "/opt/local/bin/git"
|
38
|
+
@config[:scm_command] = git
|
39
|
+
assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
40
|
+
|
41
|
+
# with submodules
|
42
|
+
@config[:git_enable_submodules] = true
|
43
|
+
assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev} && #{git} submodule -q init && #{git} submodule -q sync && #{git} submodule -q update", @source.checkout(rev, dest)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_checkout_with_verbose_should_not_use_q_switch
|
47
|
+
@config[:repository] = "git@somehost.com:project.git"
|
48
|
+
@config[:scm_verbose] = true
|
49
|
+
dest = "/var/www"
|
50
|
+
rev = 'c2d9e79'
|
51
|
+
assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_diff
|
55
|
+
assert_equal "git diff master", @source.diff('master')
|
56
|
+
assert_equal "git diff master..branch", @source.diff('master', 'branch')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_log
|
60
|
+
assert_equal "git log master..", @source.log('master')
|
61
|
+
assert_equal "git log master..branch", @source.log('master', 'branch')
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_query_revision
|
65
|
+
revision = @source.query_revision('HEAD') do |o|
|
66
|
+
assert_equal "git ls-remote . HEAD", o
|
67
|
+
"d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD"
|
68
|
+
end
|
69
|
+
assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_query_revision_has_whitespace
|
73
|
+
revision = @source.query_revision('HEAD') do |o|
|
74
|
+
assert_equal "git ls-remote . HEAD", o
|
75
|
+
"d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD\r"
|
76
|
+
end
|
77
|
+
assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_query_revision_deprecation_error
|
81
|
+
assert_raise(ArgumentError) do
|
82
|
+
revision = @source.query_revision('origin/release') {}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_command_should_be_backwards_compatible
|
87
|
+
# 1.x version of this module used ":git", not ":scm_command"
|
88
|
+
@config[:git] = "/srv/bin/git"
|
89
|
+
assert_equal "/srv/bin/git", @source.command
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_sync
|
93
|
+
dest = "/var/www"
|
94
|
+
rev = 'c2d9e79'
|
95
|
+
assert_equal "cd #{dest} && git fetch -q origin && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
|
96
|
+
|
97
|
+
# With :scm_command
|
98
|
+
git = "/opt/local/bin/git"
|
99
|
+
@config[:scm_command] = git
|
100
|
+
assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} reset -q --hard #{rev} && #{git} clean -q -d -x -f", @source.sync(rev, dest)
|
101
|
+
|
102
|
+
# with submodules
|
103
|
+
@config[:git_enable_submodules] = true
|
104
|
+
assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && for mod in `#{git} submodule status | awk '{ print $2 }'`; do #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url` && echo Synced $mod; done && #{git} submodule -q sync && #{git} submodule -q update && #{git} clean -q -d -x -f", @source.sync(rev, dest)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_sync_with_remote
|
108
|
+
dest = "/var/www"
|
109
|
+
rev = 'c2d9e79'
|
110
|
+
remote = "username"
|
111
|
+
repository = "git@somehost.com:project.git"
|
112
|
+
|
113
|
+
@config[:repository] = repository
|
114
|
+
@config[:remote] = remote
|
115
|
+
|
116
|
+
assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch -q #{remote} && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_shallow_clone
|
120
|
+
@config[:repository] = "git@somehost.com:project.git"
|
121
|
+
@config[:git_shallow_clone] = 1
|
122
|
+
dest = "/var/www"
|
123
|
+
rev = 'c2d9e79'
|
124
|
+
assert_equal "git clone -q --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_remote_clone
|
128
|
+
@config[:repository] = "git@somehost.com:project.git"
|
129
|
+
@config[:remote] = "username"
|
130
|
+
dest = "/var/www"
|
131
|
+
rev = 'c2d9e79'
|
132
|
+
assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_remote_clone_with_submodules
|
136
|
+
@config[:repository] = "git@somehost.com:project.git"
|
137
|
+
@config[:remote] = "username"
|
138
|
+
@config[:git_enable_submodules] = true
|
139
|
+
dest = "/var/www"
|
140
|
+
rev = 'c2d9e79'
|
141
|
+
assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev} && git submodule -q init && git submodule -q sync && git submodule -q update", @source.checkout(rev, dest)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Tests from base_test.rb, makin' sure we didn't break anything up there!
|
145
|
+
def test_command_should_default_to_default_command
|
146
|
+
assert_equal "git", @source.command
|
147
|
+
@source.local { assert_equal "git", @source.command }
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_command_should_use_scm_command_if_available
|
151
|
+
@config[:scm_command] = "/opt/local/bin/git"
|
152
|
+
assert_equal "/opt/local/bin/git", @source.command
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
|
156
|
+
@config[:scm_command] = "/opt/local/bin/git"
|
157
|
+
@source.local { assert_equal "/opt/local/bin/git", @source.command }
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
|
161
|
+
@config[:scm_command] = "/opt/local/bin/git"
|
162
|
+
@config[:local_scm_command] = "/usr/local/bin/git"
|
163
|
+
assert_equal "/opt/local/bin/git", @source.command
|
164
|
+
@source.local { assert_equal "/usr/local/bin/git", @source.command }
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_command_should_use_default_if_scm_command_is_default
|
168
|
+
@config[:scm_command] = :default
|
169
|
+
assert_equal "git", @source.command
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
|
173
|
+
@config[:scm_command] = "/foo/bar/git"
|
174
|
+
@config[:local_scm_command] = :default
|
175
|
+
@source.local { assert_equal "git", @source.command }
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
|
179
|
+
@config[:scm_command] = "/foo/bar/git"
|
180
|
+
@config[:local_scm_command] = :default
|
181
|
+
assert_equal "git", @source.local.command
|
182
|
+
assert_equal "/foo/bar/git", @source.command
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/recipes/deploy/scm/mercurial'
|
3
|
+
|
4
|
+
class DeploySCMMercurialTest < Test::Unit::TestCase
|
5
|
+
class TestSCM < Capistrano::Deploy::SCM::Mercurial
|
6
|
+
default_command "hg"
|
7
|
+
end
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@config = { }
|
11
|
+
def @config.exists?(name); key?(name); end
|
12
|
+
|
13
|
+
@source = TestSCM.new(@config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_head
|
17
|
+
assert_equal "tip", @source.head
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_different_head
|
21
|
+
@config[:branch] = "staging"
|
22
|
+
assert_equal "staging", @source.head
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_checkout
|
26
|
+
@config[:repository] = "http://example.com/project-hg"
|
27
|
+
dest = "/var/www"
|
28
|
+
assert_equal "hg clone --noupdate http://example.com/project-hg /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.checkout('8a8e00b8f11b', dest)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_diff
|
32
|
+
assert_equal "hg diff --rev tip", @source.diff('tip')
|
33
|
+
assert_equal "hg diff --rev 1 --rev 2", @source.diff('1', '2')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_log
|
37
|
+
assert_equal "hg log --rev 8a8e00b8f11b", @source.log('8a8e00b8f11b')
|
38
|
+
assert_equal "hg log --rev 0:3", @source.log('0', '3')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_query_revision
|
42
|
+
assert_equal "hg log -r 8a8e00b8f11b --template '{node|short}'", @source.query_revision('8a8e00b8f11b') { |o| o }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_username_should_be_backwards_compatible
|
46
|
+
# older versions of this module required :scm_user var instead
|
47
|
+
# of the currently preferred :scm_username
|
48
|
+
require 'capistrano/logger'
|
49
|
+
@config[:scm_user] = "fred"
|
50
|
+
text = "user:"
|
51
|
+
assert_equal "fred\n", @source.handle_data(mock_state, :test_stream, text)
|
52
|
+
# :scm_username takes priority
|
53
|
+
@config[:scm_username] = "wilma"
|
54
|
+
assert_equal "wilma\n", @source.handle_data(mock_state, :test_stream, text)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_sync
|
58
|
+
dest = "/var/www"
|
59
|
+
assert_equal "hg pull --repository /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
|
60
|
+
|
61
|
+
# With :scm_command
|
62
|
+
@config[:scm_command] = "/opt/local/bin/hg"
|
63
|
+
assert_equal "/opt/local/bin/hg pull --repository /var/www && /opt/local/bin/hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_export
|
67
|
+
dest = "/var/www"
|
68
|
+
assert_raise(NotImplementedError) { @source.export('8a8e00b8f11b', dest) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_sends_password_if_set
|
72
|
+
require 'capistrano/logger'
|
73
|
+
text = "password:"
|
74
|
+
@config[:scm_password] = "opensesame"
|
75
|
+
assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_prompts_for_password_if_preferred
|
79
|
+
require 'capistrano/logger'
|
80
|
+
require 'capistrano/cli'
|
81
|
+
Capistrano::CLI.stubs(:password_prompt).with("hg password: ").returns("opensesame")
|
82
|
+
@config[:scm_prefer_prompt] = true
|
83
|
+
text = "password:"
|
84
|
+
assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# Tests from base_test.rb, makin' sure we didn't break anything up there!
|
89
|
+
def test_command_should_default_to_default_command
|
90
|
+
assert_equal "hg", @source.command
|
91
|
+
@source.local { assert_equal "hg", @source.command }
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_command_should_use_scm_command_if_available
|
95
|
+
@config[:scm_command] = "/opt/local/bin/hg"
|
96
|
+
assert_equal "/opt/local/bin/hg", @source.command
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
|
100
|
+
@config[:scm_command] = "/opt/local/bin/hg"
|
101
|
+
@source.local { assert_equal "/opt/local/bin/hg", @source.command }
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
|
105
|
+
@config[:scm_command] = "/opt/local/bin/hg"
|
106
|
+
@config[:local_scm_command] = "/usr/local/bin/hg"
|
107
|
+
assert_equal "/opt/local/bin/hg", @source.command
|
108
|
+
@source.local { assert_equal "/usr/local/bin/hg", @source.command }
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_command_should_use_default_if_scm_command_is_default
|
112
|
+
@config[:scm_command] = :default
|
113
|
+
assert_equal "hg", @source.command
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
|
117
|
+
@config[:scm_command] = "/foo/bar/hg"
|
118
|
+
@config[:local_scm_command] = :default
|
119
|
+
@source.local { assert_equal "hg", @source.command }
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
|
123
|
+
@config[:scm_command] = "/foo/bar/hg"
|
124
|
+
@config[:local_scm_command] = :default
|
125
|
+
assert_equal "hg", @source.local.command
|
126
|
+
assert_equal "/foo/bar/hg", @source.command
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def mock_state
|
132
|
+
{ :channel => { :host => "abc" } }
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'utils'
|
2
|
+
require 'capistrano/recipes/deploy/scm/none'
|
3
|
+
|
4
|
+
class DeploySCMNoneTest < Test::Unit::TestCase
|
5
|
+
class TestSCM < Capistrano::Deploy::SCM::None
|
6
|
+
default_command 'none'
|
7
|
+
end
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@config = {}
|
11
|
+
def @config.exists?(name); key?(name); end
|
12
|
+
@source = TestSCM.new(@config)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_the_truth
|
16
|
+
assert true
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_checkout_on_linux
|
20
|
+
Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(false)
|
21
|
+
@config[:repository] = '.'
|
22
|
+
rev = ''
|
23
|
+
dest = '/var/www'
|
24
|
+
assert_equal "cp -R . /var/www", @source.checkout(rev, dest)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_checkout_on_windows
|
28
|
+
Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(true)
|
29
|
+
@config[:repository] = '.'
|
30
|
+
rev = ''
|
31
|
+
dest = 'c:/Documents and settings/admin/tmp'
|
32
|
+
assert_equal "xcopy . \"c:/Documents and settings/admin/tmp\" /S/I/Y/Q/E", @source.checkout(rev, dest)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/recipes/deploy/scm/subversion'
|
3
|
+
|
4
|
+
class DeploySCMSubversionTest < Test::Unit::TestCase
|
5
|
+
class TestSCM < Capistrano::Deploy::SCM::Subversion
|
6
|
+
default_command "svn"
|
7
|
+
end
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@config = { :repository => "." }
|
11
|
+
def @config.exists?(name); key?(name); end
|
12
|
+
|
13
|
+
@source = TestSCM.new(@config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_query_revision
|
17
|
+
revision = @source.query_revision('HEAD') do |o|
|
18
|
+
assert_equal "svn info . -rHEAD", o
|
19
|
+
%Q{Path: rails_2_3
|
20
|
+
URL: svn+ssh://example.com/var/repos/project/branches/rails_2_3
|
21
|
+
Repository Root: svn+ssh://example.com/var/repos
|
22
|
+
Repository UUID: 2d86388d-c40f-0410-ad6a-a69da6a65d20
|
23
|
+
Revision: 2095
|
24
|
+
Node Kind: directory
|
25
|
+
Last Changed Author: sw
|
26
|
+
Last Changed Rev: 2064
|
27
|
+
Last Changed Date: 2009-03-11 11:04:25 -0700 (Wed, 11 Mar 2009)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
assert_equal 2095, revision
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/logger'
|
3
|
+
require 'capistrano/recipes/deploy/strategy/copy'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
class DeployStrategyCopyTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@config = { :application => "captest",
|
9
|
+
:logger => Capistrano::Logger.new(:output => StringIO.new),
|
10
|
+
:releases_path => "/u/apps/test/releases",
|
11
|
+
:release_path => "/u/apps/test/releases/1234567890",
|
12
|
+
:real_revision => "154" }
|
13
|
+
@source = mock("source")
|
14
|
+
@config.stubs(:source).returns(@source)
|
15
|
+
@strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_deploy_with_defaults_should_use_remote_gtar
|
19
|
+
@config[:copy_remote_tar] = 'gtar'
|
20
|
+
|
21
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
22
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
23
|
+
@strategy.expects(:system).with(:local_checkout)
|
24
|
+
|
25
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
26
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
27
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
28
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && gtar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
29
|
+
|
30
|
+
mock_file = mock("file")
|
31
|
+
mock_file.expects(:puts).with("154")
|
32
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
33
|
+
|
34
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
35
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
36
|
+
|
37
|
+
@strategy.deploy!
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_deploy_with_defaults_should_use_local_gtar
|
41
|
+
@config[:copy_local_tar] = 'gtar'
|
42
|
+
|
43
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
44
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
45
|
+
@strategy.expects(:system).with(:local_checkout)
|
46
|
+
|
47
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
48
|
+
@strategy.expects(:system).with("gtar czf 1234567890.tar.gz 1234567890")
|
49
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
50
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
51
|
+
|
52
|
+
mock_file = mock("file")
|
53
|
+
mock_file.expects(:puts).with("154")
|
54
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
55
|
+
|
56
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
57
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
58
|
+
|
59
|
+
@strategy.deploy!
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_deploy_with_defaults_should_use_tar_gz_and_checkout
|
63
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
64
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
65
|
+
@strategy.expects(:system).with(:local_checkout)
|
66
|
+
|
67
|
+
prepare_standard_compress_and_copy!
|
68
|
+
@strategy.deploy!
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_deploy_with_exclusions_should_remove_patterns_from_destination
|
72
|
+
@config[:copy_exclude] = ".git"
|
73
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
74
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
75
|
+
@strategy.expects(:system).with(:local_checkout)
|
76
|
+
Dir.expects(:glob).with("/temp/dir/1234567890/.git", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
|
77
|
+
|
78
|
+
FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
|
79
|
+
prepare_standard_compress_and_copy!
|
80
|
+
@strategy.deploy!
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_deploy_with_exclusions_should_remove_glob_patterns_from_destination
|
84
|
+
@config[:copy_exclude] = ".gi*"
|
85
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
86
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
87
|
+
@strategy.expects(:system).with(:local_checkout)
|
88
|
+
Dir.expects(:glob).with("/temp/dir/1234567890/.gi*", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
|
89
|
+
|
90
|
+
FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
|
91
|
+
prepare_standard_compress_and_copy!
|
92
|
+
@strategy.deploy!
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_deploy_with_export_should_use_tar_gz_and_export
|
96
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
97
|
+
@config[:copy_strategy] = :export
|
98
|
+
@source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export)
|
99
|
+
@strategy.expects(:system).with(:local_export)
|
100
|
+
|
101
|
+
prepare_standard_compress_and_copy!
|
102
|
+
@strategy.deploy!
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_deploy_with_zip_should_use_zip_and_checkout
|
106
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
107
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
108
|
+
@config[:copy_compression] = :zip
|
109
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
110
|
+
|
111
|
+
@strategy.expects(:system).with(:local_checkout)
|
112
|
+
@strategy.expects(:system).with("zip -qr 1234567890.zip 1234567890")
|
113
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.zip", "/tmp/1234567890.zip")
|
114
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
|
115
|
+
|
116
|
+
mock_file = mock("file")
|
117
|
+
mock_file.expects(:puts).with("154")
|
118
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
119
|
+
|
120
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
|
121
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
122
|
+
|
123
|
+
@strategy.deploy!
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_deploy_with_bzip2_should_use_bz2_and_checkout
|
127
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
128
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
129
|
+
@config[:copy_compression] = :bzip2
|
130
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
131
|
+
|
132
|
+
@strategy.expects(:system).with(:local_checkout)
|
133
|
+
@strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
|
134
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.bz2", "/tmp/1234567890.tar.bz2")
|
135
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
|
136
|
+
|
137
|
+
mock_file = mock("file")
|
138
|
+
mock_file.expects(:puts).with("154")
|
139
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
140
|
+
|
141
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
|
142
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
143
|
+
|
144
|
+
@strategy.deploy!
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_deploy_with_unknown_compression_type_should_error
|
148
|
+
@config[:copy_compression] = :bogus
|
149
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
150
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
151
|
+
@strategy.stubs(:system)
|
152
|
+
File.stubs(:open)
|
153
|
+
|
154
|
+
assert_raises(ArgumentError) { @strategy.deploy! }
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
|
158
|
+
Dir.expects(:tmpdir).never
|
159
|
+
Dir.expects(:chdir).with("/other/path").yields
|
160
|
+
@config[:copy_dir] = "/other/path"
|
161
|
+
@source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout)
|
162
|
+
|
163
|
+
@strategy.expects(:system).with(:local_checkout)
|
164
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
165
|
+
@strategy.expects(:upload).with("/other/path/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
166
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
167
|
+
|
168
|
+
mock_file = mock("file")
|
169
|
+
mock_file.expects(:puts).with("154")
|
170
|
+
File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
|
171
|
+
|
172
|
+
FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
|
173
|
+
FileUtils.expects(:rm_rf).with("/other/path/1234567890")
|
174
|
+
|
175
|
+
@strategy.deploy!
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
|
179
|
+
@config[:copy_remote_dir] = "/somewhere/else"
|
180
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
181
|
+
Dir.expects(:chdir).yields
|
182
|
+
@source.expects(:checkout).returns(:local_checkout)
|
183
|
+
|
184
|
+
@strategy.expects(:system).with(:local_checkout)
|
185
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
186
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/somewhere/else/1234567890.tar.gz")
|
187
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")
|
188
|
+
|
189
|
+
mock_file = mock("file")
|
190
|
+
mock_file.expects(:puts).with("154")
|
191
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
192
|
+
|
193
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
194
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
195
|
+
|
196
|
+
@strategy.deploy!
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_with_copy_cache_should_checkout_to_cache_if_cache_does_not_exist_and_then_copy
|
200
|
+
@config[:copy_cache] = true
|
201
|
+
|
202
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
203
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(false)
|
204
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
205
|
+
|
206
|
+
@source.expects(:checkout).with("154", "/temp/dir/captest").returns(:local_checkout)
|
207
|
+
@strategy.expects(:system).with(:local_checkout)
|
208
|
+
|
209
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
210
|
+
|
211
|
+
prepare_directory_tree!("/temp/dir/captest")
|
212
|
+
|
213
|
+
prepare_standard_compress_and_copy!
|
214
|
+
@strategy.deploy!
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_with_copy_cache_should_update_cache_if_cache_exists_and_then_copy
|
218
|
+
@config[:copy_cache] = true
|
219
|
+
|
220
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
221
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(true)
|
222
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
223
|
+
|
224
|
+
@source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
|
225
|
+
@strategy.expects(:system).with(:local_sync)
|
226
|
+
|
227
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
228
|
+
|
229
|
+
prepare_directory_tree!("/temp/dir/captest")
|
230
|
+
|
231
|
+
prepare_standard_compress_and_copy!
|
232
|
+
@strategy.deploy!
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_with_copy_cache_with_custom_cache_dir_should_use_specified_cache_dir
|
236
|
+
@config[:copy_cache] = "/u/caches/captest"
|
237
|
+
|
238
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
239
|
+
File.expects(:exists?).with("/u/caches/captest").returns(true)
|
240
|
+
Dir.expects(:chdir).with("/u/caches/captest").yields
|
241
|
+
|
242
|
+
@source.expects(:sync).with("154", "/u/caches/captest").returns(:local_sync)
|
243
|
+
@strategy.expects(:system).with(:local_sync)
|
244
|
+
|
245
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
246
|
+
|
247
|
+
prepare_directory_tree!("/u/caches/captest")
|
248
|
+
|
249
|
+
prepare_standard_compress_and_copy!
|
250
|
+
@strategy.deploy!
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_with_copy_cache_with_excludes_should_not_copy_excluded_files
|
254
|
+
@config[:copy_cache] = true
|
255
|
+
@config[:copy_exclude] = "*/bar.txt"
|
256
|
+
|
257
|
+
Dir.stubs(:tmpdir).returns("/temp/dir")
|
258
|
+
File.expects(:exists?).with("/temp/dir/captest").returns(true)
|
259
|
+
Dir.expects(:chdir).with("/temp/dir/captest").yields
|
260
|
+
|
261
|
+
@source.expects(:sync).with("154", "/temp/dir/captest").returns(:local_sync)
|
262
|
+
@strategy.expects(:system).with(:local_sync)
|
263
|
+
|
264
|
+
FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
|
265
|
+
|
266
|
+
prepare_directory_tree!("/temp/dir/captest", true)
|
267
|
+
|
268
|
+
prepare_standard_compress_and_copy!
|
269
|
+
@strategy.deploy!
|
270
|
+
end
|
271
|
+
|
272
|
+
private
|
273
|
+
|
274
|
+
def prepare_directory_tree!(cache, exclude=false)
|
275
|
+
Dir.expects(:glob).with("*", File::FNM_DOTMATCH).returns([".", "..", "app", "foo.txt"])
|
276
|
+
File.expects(:directory?).with("app").returns(true)
|
277
|
+
FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app")
|
278
|
+
File.expects(:directory?).with("foo.txt").returns(false)
|
279
|
+
FileUtils.expects(:ln).with("#{cache}/foo.txt", "/temp/dir/1234567890/foo.txt")
|
280
|
+
|
281
|
+
Dir.expects(:glob).with("app/*", File::FNM_DOTMATCH).returns(["app/.", "app/..", "app/bar.txt"])
|
282
|
+
|
283
|
+
unless exclude
|
284
|
+
File.expects(:directory?).with("app/bar.txt").returns(false)
|
285
|
+
FileUtils.expects(:ln).with("#{cache}/app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def prepare_standard_compress_and_copy!
|
290
|
+
Dir.expects(:chdir).with("/temp/dir").yields
|
291
|
+
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
292
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
293
|
+
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
294
|
+
|
295
|
+
mock_file = mock("file")
|
296
|
+
mock_file.expects(:puts).with("154")
|
297
|
+
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
298
|
+
|
299
|
+
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
300
|
+
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
301
|
+
end
|
302
|
+
end
|