startapp 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/COPYRIGHT +1 -0
  3. data/LICENSE +11 -0
  4. data/README.md +95 -0
  5. data/Rakefile +6 -0
  6. data/autocomplete/rhc_bash +1672 -0
  7. data/bin/app +37 -0
  8. data/conf/express.conf +8 -0
  9. data/features/assets/deploy.tar.gz +0 -0
  10. data/features/core_feature.rb +191 -0
  11. data/features/deployments_feature.rb +129 -0
  12. data/features/domains_feature.rb +58 -0
  13. data/features/keys_feature.rb +37 -0
  14. data/features/members_feature.rb +166 -0
  15. data/lib/rhc/auth/basic.rb +64 -0
  16. data/lib/rhc/auth/token.rb +102 -0
  17. data/lib/rhc/auth/token_store.rb +53 -0
  18. data/lib/rhc/auth.rb +5 -0
  19. data/lib/rhc/autocomplete.rb +66 -0
  20. data/lib/rhc/autocomplete_templates/bash.erb +39 -0
  21. data/lib/rhc/cartridge_helpers.rb +118 -0
  22. data/lib/rhc/cli.rb +40 -0
  23. data/lib/rhc/command_runner.rb +185 -0
  24. data/lib/rhc/commands/account.rb +25 -0
  25. data/lib/rhc/commands/alias.rb +124 -0
  26. data/lib/rhc/commands/app.rb +726 -0
  27. data/lib/rhc/commands/apps.rb +20 -0
  28. data/lib/rhc/commands/authorization.rb +115 -0
  29. data/lib/rhc/commands/base.rb +174 -0
  30. data/lib/rhc/commands/cartridge.rb +329 -0
  31. data/lib/rhc/commands/clone.rb +66 -0
  32. data/lib/rhc/commands/configure.rb +20 -0
  33. data/lib/rhc/commands/create.rb +100 -0
  34. data/lib/rhc/commands/delete.rb +19 -0
  35. data/lib/rhc/commands/deploy.rb +32 -0
  36. data/lib/rhc/commands/deployment.rb +82 -0
  37. data/lib/rhc/commands/domain.rb +172 -0
  38. data/lib/rhc/commands/env.rb +142 -0
  39. data/lib/rhc/commands/force_stop.rb +17 -0
  40. data/lib/rhc/commands/git_clone.rb +34 -0
  41. data/lib/rhc/commands/logout.rb +51 -0
  42. data/lib/rhc/commands/logs.rb +21 -0
  43. data/lib/rhc/commands/member.rb +148 -0
  44. data/lib/rhc/commands/port_forward.rb +197 -0
  45. data/lib/rhc/commands/reload.rb +17 -0
  46. data/lib/rhc/commands/restart.rb +17 -0
  47. data/lib/rhc/commands/scp.rb +54 -0
  48. data/lib/rhc/commands/server.rb +40 -0
  49. data/lib/rhc/commands/setup.rb +60 -0
  50. data/lib/rhc/commands/show.rb +43 -0
  51. data/lib/rhc/commands/snapshot.rb +137 -0
  52. data/lib/rhc/commands/ssh.rb +51 -0
  53. data/lib/rhc/commands/sshkey.rb +97 -0
  54. data/lib/rhc/commands/start.rb +17 -0
  55. data/lib/rhc/commands/stop.rb +17 -0
  56. data/lib/rhc/commands/tail.rb +47 -0
  57. data/lib/rhc/commands/threaddump.rb +14 -0
  58. data/lib/rhc/commands/tidy.rb +17 -0
  59. data/lib/rhc/commands.rb +396 -0
  60. data/lib/rhc/config.rb +321 -0
  61. data/lib/rhc/context_helper.rb +121 -0
  62. data/lib/rhc/core_ext.rb +202 -0
  63. data/lib/rhc/coverage_helper.rb +33 -0
  64. data/lib/rhc/deployment_helpers.rb +111 -0
  65. data/lib/rhc/exceptions.rb +256 -0
  66. data/lib/rhc/git_helpers.rb +106 -0
  67. data/lib/rhc/help_formatter.rb +55 -0
  68. data/lib/rhc/helpers.rb +481 -0
  69. data/lib/rhc/highline_extensions.rb +479 -0
  70. data/lib/rhc/json.rb +51 -0
  71. data/lib/rhc/output_helpers.rb +260 -0
  72. data/lib/rhc/rest/activation.rb +11 -0
  73. data/lib/rhc/rest/alias.rb +42 -0
  74. data/lib/rhc/rest/api.rb +87 -0
  75. data/lib/rhc/rest/application.rb +348 -0
  76. data/lib/rhc/rest/attributes.rb +36 -0
  77. data/lib/rhc/rest/authorization.rb +8 -0
  78. data/lib/rhc/rest/base.rb +79 -0
  79. data/lib/rhc/rest/cartridge.rb +162 -0
  80. data/lib/rhc/rest/client.rb +650 -0
  81. data/lib/rhc/rest/deployment.rb +18 -0
  82. data/lib/rhc/rest/domain.rb +98 -0
  83. data/lib/rhc/rest/environment_variable.rb +15 -0
  84. data/lib/rhc/rest/gear_group.rb +16 -0
  85. data/lib/rhc/rest/httpclient.rb +145 -0
  86. data/lib/rhc/rest/key.rb +44 -0
  87. data/lib/rhc/rest/membership.rb +105 -0
  88. data/lib/rhc/rest/mock.rb +1042 -0
  89. data/lib/rhc/rest/user.rb +32 -0
  90. data/lib/rhc/rest.rb +148 -0
  91. data/lib/rhc/scp_helpers.rb +27 -0
  92. data/lib/rhc/ssh_helpers.rb +380 -0
  93. data/lib/rhc/tar_gz.rb +51 -0
  94. data/lib/rhc/usage_templates/command_help.erb +51 -0
  95. data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
  96. data/lib/rhc/usage_templates/help.erb +61 -0
  97. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  98. data/lib/rhc/usage_templates/options_help.erb +12 -0
  99. data/lib/rhc/vendor/okjson.rb +600 -0
  100. data/lib/rhc/vendor/parseconfig.rb +178 -0
  101. data/lib/rhc/vendor/sshkey.rb +253 -0
  102. data/lib/rhc/vendor/zliby.rb +628 -0
  103. data/lib/rhc/version.rb +5 -0
  104. data/lib/rhc/wizard.rb +637 -0
  105. data/lib/rhc.rb +34 -0
  106. data/spec/coverage_helper.rb +82 -0
  107. data/spec/direct_execution_helper.rb +339 -0
  108. data/spec/keys/example.pem +23 -0
  109. data/spec/keys/example_private.pem +27 -0
  110. data/spec/keys/server.pem +19 -0
  111. data/spec/rest_spec_helper.rb +31 -0
  112. data/spec/rhc/assets/cert.crt +22 -0
  113. data/spec/rhc/assets/cert_key_rsa +27 -0
  114. data/spec/rhc/assets/empty.txt +0 -0
  115. data/spec/rhc/assets/env_vars.txt +7 -0
  116. data/spec/rhc/assets/env_vars_2.txt +1 -0
  117. data/spec/rhc/assets/foo.txt +1 -0
  118. data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
  119. data/spec/rhc/assets/targz_sample.tar.gz +0 -0
  120. data/spec/rhc/auth_spec.rb +442 -0
  121. data/spec/rhc/cli_spec.rb +186 -0
  122. data/spec/rhc/command_spec.rb +435 -0
  123. data/spec/rhc/commands/account_spec.rb +42 -0
  124. data/spec/rhc/commands/alias_spec.rb +333 -0
  125. data/spec/rhc/commands/app_spec.rb +777 -0
  126. data/spec/rhc/commands/apps_spec.rb +39 -0
  127. data/spec/rhc/commands/authorization_spec.rb +157 -0
  128. data/spec/rhc/commands/cartridge_spec.rb +665 -0
  129. data/spec/rhc/commands/clone_spec.rb +41 -0
  130. data/spec/rhc/commands/deployment_spec.rb +327 -0
  131. data/spec/rhc/commands/domain_spec.rb +401 -0
  132. data/spec/rhc/commands/env_spec.rb +493 -0
  133. data/spec/rhc/commands/git_clone_spec.rb +102 -0
  134. data/spec/rhc/commands/logout_spec.rb +86 -0
  135. data/spec/rhc/commands/member_spec.rb +247 -0
  136. data/spec/rhc/commands/port_forward_spec.rb +217 -0
  137. data/spec/rhc/commands/scp_spec.rb +77 -0
  138. data/spec/rhc/commands/server_spec.rb +69 -0
  139. data/spec/rhc/commands/setup_spec.rb +118 -0
  140. data/spec/rhc/commands/snapshot_spec.rb +179 -0
  141. data/spec/rhc/commands/ssh_spec.rb +163 -0
  142. data/spec/rhc/commands/sshkey_spec.rb +188 -0
  143. data/spec/rhc/commands/tail_spec.rb +81 -0
  144. data/spec/rhc/commands/threaddump_spec.rb +84 -0
  145. data/spec/rhc/config_spec.rb +407 -0
  146. data/spec/rhc/helpers_spec.rb +531 -0
  147. data/spec/rhc/highline_extensions_spec.rb +314 -0
  148. data/spec/rhc/json_spec.rb +30 -0
  149. data/spec/rhc/rest_application_spec.rb +258 -0
  150. data/spec/rhc/rest_client_spec.rb +752 -0
  151. data/spec/rhc/rest_spec.rb +740 -0
  152. data/spec/rhc/targz_spec.rb +55 -0
  153. data/spec/rhc/wizard_spec.rb +756 -0
  154. data/spec/spec_helper.rb +575 -0
  155. data/spec/wizard_spec_helper.rb +330 -0
  156. metadata +469 -0
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc/commands/clone'
4
+
5
+ describe RHC::Commands::Clone do
6
+ before{ user_config }
7
+ let!(:rest_client){ MockRestClient.new }
8
+
9
+ describe 'run' do
10
+
11
+ context 'clone invalid url' do
12
+ let(:arguments) { ['clone','http://someivalidurl.com'] }
13
+
14
+ it { run_output.should match(/URL is invalid. To clone app your url must be something/) }
15
+ end
16
+
17
+ context 'with valid url and no domains' do
18
+ let(:arguments) { ['clone','http://myapp-mydomain.startapp.bg'] }
19
+
20
+ it { expect { run }.to exit_with_code(127) }
21
+ it { run_output.should match(/Domain *mydomain* not found/) }
22
+ end
23
+
24
+ context 'with valid url and domain' do
25
+ let(:arguments) { ['clone','http://myapp-myfirsrdomain.startapp.bg'] }
26
+ let!(:domain){ rest_client.add_domain("myfirsrdomain") }
27
+
28
+ it { expect { run }.to exit_with_code(101) }
29
+ it { run_output.should match(/Application myapp does not exist/) }
30
+
31
+ context 'with apps' do
32
+ let(:arguments) { ['clone','http://myapp-myfirsrdomain.startapp.bg'] }
33
+ before{ domain.add_application('myapp') }
34
+
35
+ it { expect { run }.to exit_with_code(216) }
36
+ it { run_output.should match(/Cloning into 'myapp'/) }
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,327 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc/commands/deployment'
4
+
5
+ describe RHC::Commands::Deployment do
6
+
7
+ DEPLOYMENT_APP_NAME = 'mock_app_deploy'
8
+
9
+ let!(:rest_client) { MockRestClient.new }
10
+
11
+ before do
12
+ user_config
13
+ @rest_app = rest_client.add_domain("mock_domain").add_application(DEPLOYMENT_APP_NAME, 'ruby-1.8.7')
14
+ @rest_app.stub(:ssh_url).and_return("ssh://user@test.domain.com")
15
+ @targz_filename = File.dirname(__FILE__) + '/' + DEPLOYMENT_APP_NAME + '.tar.gz'
16
+ FileUtils.cp(File.expand_path('../../assets/targz_sample.tar.gz', __FILE__), @targz_filename)
17
+ File.chmod 0644, @targz_filename unless File.executable? @targz_filename
18
+ end
19
+
20
+ after do
21
+ File.delete @targz_filename if File.exist? @targz_filename
22
+ end
23
+
24
+ describe "configure app" do
25
+ context "manual deployment keeping a history of 10" do
26
+ let(:arguments) {['app', 'configure', '--app', DEPLOYMENT_APP_NAME, '--no-auto-deploy', '--keep-deployments', '10']}
27
+ it "should succeed" do
28
+ expect{ run }.to exit_with_code(0)
29
+ run_output.should match(/Configuring application '#{DEPLOYMENT_APP_NAME}' .../)
30
+ run_output.should match(/done/)
31
+ @rest_app.auto_deploy.should == false
32
+ @rest_app.keep_deployments.should == 10
33
+ run_output.should match(/Your application '#{DEPLOYMENT_APP_NAME}' is now configured as listed above/)
34
+ end
35
+ end
36
+
37
+ context "with no configuration options" do
38
+ let(:arguments) {['app', 'configure', '--app', DEPLOYMENT_APP_NAME]}
39
+ it "should display the current configuration" do
40
+ expect{ run }.to exit_with_code(0)
41
+ run_output.should_not match(/Configuring application '#{DEPLOYMENT_APP_NAME}' .../)
42
+ run_output.should_not match(/done/)
43
+ run_output.should match(/Your application '#{DEPLOYMENT_APP_NAME}' is configured as listed above/)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "deploy" do
49
+ context "git ref successfully" do
50
+ before { Net::SSH.should_receive(:start).exactly(3).times.with('test.domain.com', 'user', :compression=>false) }
51
+ let(:arguments) {['app', 'deploy', 'master', '--app', DEPLOYMENT_APP_NAME]}
52
+ it "should succeed" do
53
+ expect{ run }.to exit_with_code(0)
54
+ run_output.should match(/Deployment of git ref 'master' in progress for application #{DEPLOYMENT_APP_NAME} .../)
55
+ run_output.should match(/Success/)
56
+ end
57
+ end
58
+
59
+ context "binary file successfully" do
60
+ before do
61
+ @rest_app.stub(:deployment_type).and_return('binary')
62
+ ssh = double(Net::SSH)
63
+ session = double(Net::SSH::Connection::Session)
64
+ channel = double(Net::SSH::Connection::Channel)
65
+ exit_status = double(Net::SSH::Buffer)
66
+ exit_status.stub(:read_long).and_return(0)
67
+ Net::SSH.should_receive(:start).exactly(3).times.with('test.domain.com', 'user', :compression=>false).and_yield(session)
68
+ session.should_receive(:open_channel).exactly(3).times.and_yield(channel)
69
+ channel.should_receive(:exec).exactly(3).times.with("oo-binary-deploy").and_yield(nil, nil)
70
+ channel.should_receive(:on_data).exactly(3).times.and_yield(nil, 'foo')
71
+ channel.should_receive(:on_extended_data).exactly(3).times.and_yield(nil, nil, '')
72
+ channel.should_receive(:on_close).exactly(3).times.and_yield(nil)
73
+ channel.should_receive(:on_request).exactly(3).times.with("exit-status").and_yield(nil, exit_status)
74
+ lines = ''
75
+ File.open(@targz_filename, 'rb') do |file|
76
+ file.chunk(1024) do |chunk|
77
+ lines << chunk
78
+ end
79
+ end
80
+ channel.should_receive(:send_data).exactly(3).times.with(lines)
81
+ channel.should_receive(:eof!).exactly(3).times
82
+ session.should_receive(:loop).exactly(3).times
83
+ end
84
+ let(:arguments) {['app', 'deploy', @targz_filename, '--app', DEPLOYMENT_APP_NAME]}
85
+ it "should succeed" do
86
+ expect{ run }.to exit_with_code(0)
87
+ run_output.should match(/Deployment of file '#{@targz_filename}' in progress for application #{DEPLOYMENT_APP_NAME} .../)
88
+ run_output.should match(/Success/)
89
+ end
90
+ end
91
+
92
+ [URI('http://foo.com/path/to/file/' + DEPLOYMENT_APP_NAME + '.tar.gz'),
93
+ URI('https://foo.com/path/to/file/' + DEPLOYMENT_APP_NAME + '.tar.gz')].each do |uri|
94
+ context "url file successfully" do
95
+ before do
96
+ @rest_app.stub(:deployment_type).and_return('binary')
97
+ ssh = double(Net::SSH)
98
+ session = double(Net::SSH::Connection::Session)
99
+ channel = double(Net::SSH::Connection::Channel)
100
+ exit_status = double(Net::SSH::Buffer)
101
+ exit_status.stub(:read_long).and_return(0)
102
+ Net::SSH.should_receive(:start).exactly(3).times.with('test.domain.com', 'user', :compression=>false).and_yield(session)
103
+ session.should_receive(:open_channel).exactly(3).times.and_yield(channel)
104
+ channel.should_receive(:exec).exactly(3).times.with("oo-binary-deploy").and_yield(nil, nil)
105
+ channel.should_receive(:on_data).exactly(3).times.and_yield(nil, 'foo')
106
+ channel.should_receive(:on_extended_data).exactly(3).times.and_yield(nil, nil, '')
107
+ channel.should_receive(:on_close).exactly(3).times.and_yield(nil)
108
+ channel.should_receive(:on_request).exactly(3).times.with("exit-status").and_yield(nil, exit_status)
109
+ lines = ''
110
+ File.open(@targz_filename, 'rb') do |file|
111
+ file.chunk(1024) do |chunk|
112
+ lines << chunk
113
+ end
114
+ end
115
+ stub_request(:get, uri.to_s).to_return(:status => 200, :body => lines, :headers => {})
116
+ channel.should_receive(:send_data).exactly(3).times.with(lines)
117
+ channel.should_receive(:eof!).exactly(3).times
118
+ session.should_receive(:loop).exactly(3).times
119
+ end
120
+ let(:arguments) {['app', 'deploy', uri.to_s, '--app', DEPLOYMENT_APP_NAME]}
121
+ it "should succeed" do
122
+ expect{ run }.to exit_with_code(0)
123
+ run_output.should match(/Deployment of file '#{uri.to_s}' in progress for application #{DEPLOYMENT_APP_NAME} .../)
124
+ run_output.should match(/Success/)
125
+ end
126
+ end
127
+ end
128
+
129
+ context "binary file with corrupted file" do
130
+ before do
131
+ @rest_app.stub(:deployment_type).and_return('binary')
132
+ ssh = double(Net::SSH)
133
+ session = double(Net::SSH::Connection::Session)
134
+ channel = double(Net::SSH::Connection::Channel)
135
+ exit_status = double(Net::SSH::Buffer)
136
+ exit_status.stub(:read_long).and_return(255)
137
+ Net::SSH.should_receive(:start).exactly(3).times.with('test.domain.com', 'user', :compression=>false).and_yield(session)
138
+ session.should_receive(:open_channel).exactly(3).times.and_yield(channel)
139
+ channel.should_receive(:exec).exactly(3).times.with("oo-binary-deploy").and_yield(nil, nil)
140
+ channel.should_receive(:on_data).exactly(3).times.and_yield(nil, 'foo')
141
+ channel.should_receive(:on_extended_data).exactly(3).times.and_yield(nil, nil, 'Invalid file')
142
+ channel.should_receive(:on_close).exactly(3).times.and_yield(nil)
143
+ channel.should_receive(:on_request).exactly(3).times.with("exit-status").and_yield(nil, exit_status)
144
+ lines = ''
145
+ File.open(@targz_filename, 'rb') do |file|
146
+ file.chunk(1024) do |chunk|
147
+ lines << chunk
148
+ end
149
+ end
150
+ channel.should_receive(:send_data).exactly(3).times.with(lines)
151
+ channel.should_receive(:eof!).exactly(3).times
152
+ session.should_receive(:loop).exactly(3).times
153
+ end
154
+ let(:arguments) {['app', 'deploy', @targz_filename, '--app', DEPLOYMENT_APP_NAME]}
155
+ it "should not succeed" do
156
+ expect{ run }.to exit_with_code(133)
157
+ run_output.should match(/Deployment of file '#{@targz_filename}' in progress for application #{DEPLOYMENT_APP_NAME} .../)
158
+ run_output.should match(/Invalid file/)
159
+ end
160
+ end
161
+
162
+ context "fails when deploying git ref" do
163
+ before (:each) { Net::SSH.should_receive(:start).and_raise(Errno::ECONNREFUSED) }
164
+ let(:arguments) {['app', 'deploy', 'master', '--app', DEPLOYMENT_APP_NAME]}
165
+ it "should exit with error" do
166
+ expect{ run }.to exit_with_code(1)
167
+ end
168
+ end
169
+
170
+ context "fails when deploying binary file" do
171
+ before (:each) do
172
+ @rest_app.stub(:deployment_type).and_return('binary')
173
+ Net::SSH.should_receive(:start).and_raise(Errno::ECONNREFUSED)
174
+ end
175
+ let(:arguments) {['app', 'deploy', @targz_filename, '--app', DEPLOYMENT_APP_NAME]}
176
+ it "should exit with error" do
177
+ expect{ run }.to exit_with_code(1)
178
+ end
179
+ end
180
+
181
+ context "fails when deploying binary file" do
182
+ before (:each) do
183
+ @rest_app.stub(:deployment_type).and_return('binary')
184
+ Net::SSH.should_receive(:start).and_raise(SocketError)
185
+ end
186
+ let(:arguments) {['app', 'deploy', @targz_filename, '--app', DEPLOYMENT_APP_NAME]}
187
+ it "should exit with error" do
188
+ expect{ run }.to exit_with_code(1)
189
+ end
190
+ end
191
+
192
+ context "fails when deploying url file" do
193
+ before (:each) do
194
+ @rest_app.stub(:deployment_type).and_return('binary')
195
+ Net::SSH.should_receive(:start).and_raise(Errno::ECONNREFUSED)
196
+ end
197
+ let(:arguments) {['app', 'deploy', 'http://foo.com/deploy.tar.gz', '--app', DEPLOYMENT_APP_NAME]}
198
+ it "should exit with error" do
199
+ expect{ run }.to exit_with_code(1)
200
+ end
201
+ end
202
+
203
+ context "fails when deploying url file" do
204
+ before (:each) do
205
+ @rest_app.stub(:deployment_type).and_return('binary')
206
+ Net::SSH.should_receive(:start).and_raise(SocketError)
207
+ end
208
+ let(:arguments) {['app', 'deploy', 'http://foo.com/deploy.tar.gz', '--app', DEPLOYMENT_APP_NAME]}
209
+ it "should exit with error" do
210
+ expect{ run }.to exit_with_code(1)
211
+ end
212
+ end
213
+
214
+ context 'when run against an unsupported server' do
215
+ before {
216
+ @rest_app.links.delete 'UPDATE'
217
+ @rest_app.links.delete 'DEPLOY'
218
+ }
219
+ let(:arguments) {['app', 'deploy', 'master', '--app', DEPLOYMENT_APP_NAME]}
220
+ it "should raise not supported exception" do
221
+ expect{ run }.to exit_with_code(132)
222
+ run_output.should match(/The server does not support deployments/)
223
+ end
224
+ end
225
+
226
+ context "ssh authentication failure" do
227
+ before (:each) { Net::SSH.should_receive(:start).exactly(2).times.and_raise(Net::SSH::AuthenticationFailed) }
228
+ let(:arguments) {['app', 'deploy', 'master', '--app', DEPLOYMENT_APP_NAME]}
229
+ it "should exit with error" do
230
+ expect{ run }.to exit_with_code(1)
231
+ run_output.should match(/Authentication to server test.domain.com with user user failed/)
232
+ end
233
+ end
234
+
235
+ context "fails when deploying git reference on an app configured to deployment_type = binary" do
236
+ before { @rest_app.stub(:deployment_type).and_return('binary') }
237
+ let(:arguments) {['app', 'deploy', 'master', '--app', DEPLOYMENT_APP_NAME]}
238
+ it "should exit with error" do
239
+ expect{ run }.to exit_with_code(133)
240
+ end
241
+ end
242
+
243
+ context "fails when deploying file on an app configured to deployment_type = git" do
244
+ before { @rest_app.stub(:deployment_type).and_return('git') }
245
+ let(:arguments) {['app', 'deploy', @targz_filename, '--app', DEPLOYMENT_APP_NAME]}
246
+ it "should exit with error" do
247
+ expect{ run }.to exit_with_code(133)
248
+ end
249
+ end
250
+
251
+ [URI('http://foo.com/path/to/file/' + DEPLOYMENT_APP_NAME + '.tar.gz'),
252
+ URI('https://foo.com/path/to/file/' + DEPLOYMENT_APP_NAME + '.tar.gz')].each do |uri|
253
+ context "fails when deploying url on an app configured to deployment_type = git" do
254
+ before { @rest_app.stub(:deployment_type).and_return('git') }
255
+ let(:arguments) {['app', 'deploy', uri.to_s, '--app', DEPLOYMENT_APP_NAME]}
256
+ it "should exit with error" do
257
+ expect{ run }.to exit_with_code(133)
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ describe "activate deployment" do
264
+ context "activates 123456" do
265
+ before { Net::SSH.should_receive(:start).exactly(3).times.with('test.domain.com', 'user', :compression => false) }
266
+ let(:arguments) {['deployment', 'activate', '123456', '--app', DEPLOYMENT_APP_NAME]}
267
+ it "should succeed" do
268
+ expect{ run }.to exit_with_code(0)
269
+ run_output.should match(/Activating deployment '123456' on application #{DEPLOYMENT_APP_NAME} .../)
270
+ run_output.should match(/Success/)
271
+ end
272
+ end
273
+
274
+ context "fails with ssh error" do
275
+ before (:each) { Net::SSH.should_receive(:start).and_raise(Errno::ECONNREFUSED) }
276
+ let(:arguments) {['deployment', 'activate', '123456', '--app', DEPLOYMENT_APP_NAME]}
277
+ it "should exit with error" do
278
+ expect{ run }.to exit_with_code(1)
279
+ end
280
+ end
281
+ end
282
+
283
+ describe "list deployments" do
284
+ context "simple" do
285
+ let(:arguments) {['deployment', 'list', DEPLOYMENT_APP_NAME]}
286
+ it "should succeed" do
287
+ expect{ run }.to exit_with_code(0)
288
+ run_output.should match(/Jan 01\, 2000 1\:00 AM\, deployment 0000001/)
289
+ run_output.should match(/Jan 01\, 2000 2\:00 AM\, deployment 0000002/)
290
+ run_output.should match(/Jan 01\, 2000 3\:00 AM\, deployment 0000003 \(rolled back\)/)
291
+ run_output.should match(/Jan 01\, 2000 4\:00 AM\, deployment 0000004 \(rolled back\)/)
292
+ run_output.should match(/Jan 01\, 2000 5\:00 AM\, deployment 0000003 \(rollback to Jan 01\, 2000 3\:00 AM\, rolled back\)/)
293
+ run_output.should match(/Jan 01\, 2000 5\:00 AM\, deployment 0000005 \(rolled back\)/)
294
+ run_output.should match(/Jan 01\, 2000 6\:00 AM\, deployment 0000002 \(rollback to Jan 01\, 2000 2\:00 AM\)/)
295
+ end
296
+ end
297
+ end
298
+
299
+ describe "show deployment" do
300
+ context "simple" do
301
+ let(:arguments) {['deployment', 'show', '0000001', '--app', DEPLOYMENT_APP_NAME]}
302
+ it "should succeed" do
303
+ expect{ run }.to exit_with_code(0)
304
+ run_output.should match(/Deployment ID 0000001/)
305
+ end
306
+ end
307
+
308
+ context "fails when deployment is not found" do
309
+ let(:arguments) {['deployment', 'show', 'zee', '--app', DEPLOYMENT_APP_NAME]}
310
+ it "should succeed" do
311
+ expect{ run }.to exit_with_code(131)
312
+ run_output.should match(/Deployment ID 'zee' not found for application #{DEPLOYMENT_APP_NAME}/)
313
+ end
314
+ end
315
+ end
316
+
317
+ describe "show configuration" do
318
+ context "simple" do
319
+ let(:arguments) {['app', 'show', '--app', DEPLOYMENT_APP_NAME, '--configuration']}
320
+ it "should succeed" do
321
+ expect{ run }.to exit_with_code(0)
322
+ #run_output.should match(/Deployment ID 1/)
323
+ end
324
+ end
325
+ end
326
+
327
+ end