pbox 1.17.2

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.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/COPYRIGHT +1 -0
  3. data/LICENSE +11 -0
  4. data/README.md +40 -0
  5. data/Rakefile +6 -0
  6. data/autocomplete/pbox_bash +1639 -0
  7. data/bin/pbox +37 -0
  8. data/conf/protonbox.conf +8 -0
  9. data/features/assets/deploy.tar.gz +0 -0
  10. data/features/core_feature.rb +178 -0
  11. data/features/deployments_feature.rb +127 -0
  12. data/features/domains_feature.rb +49 -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 +186 -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 +701 -0
  27. data/lib/rhc/commands/apps.rb +20 -0
  28. data/lib/rhc/commands/authorization.rb +96 -0
  29. data/lib/rhc/commands/base.rb +174 -0
  30. data/lib/rhc/commands/cartridge.rb +326 -0
  31. data/lib/rhc/commands/deployment.rb +82 -0
  32. data/lib/rhc/commands/domain.rb +167 -0
  33. data/lib/rhc/commands/env.rb +142 -0
  34. data/lib/rhc/commands/git_clone.rb +29 -0
  35. data/lib/rhc/commands/logout.rb +51 -0
  36. data/lib/rhc/commands/member.rb +148 -0
  37. data/lib/rhc/commands/port_forward.rb +197 -0
  38. data/lib/rhc/commands/server.rb +40 -0
  39. data/lib/rhc/commands/setup.rb +60 -0
  40. data/lib/rhc/commands/snapshot.rb +137 -0
  41. data/lib/rhc/commands/ssh.rb +51 -0
  42. data/lib/rhc/commands/sshkey.rb +97 -0
  43. data/lib/rhc/commands/tail.rb +47 -0
  44. data/lib/rhc/commands/threaddump.rb +14 -0
  45. data/lib/rhc/commands.rb +396 -0
  46. data/lib/rhc/config.rb +320 -0
  47. data/lib/rhc/context_helper.rb +121 -0
  48. data/lib/rhc/core_ext.rb +202 -0
  49. data/lib/rhc/coverage_helper.rb +33 -0
  50. data/lib/rhc/deployment_helpers.rb +88 -0
  51. data/lib/rhc/exceptions.rb +232 -0
  52. data/lib/rhc/git_helpers.rb +91 -0
  53. data/lib/rhc/help_formatter.rb +55 -0
  54. data/lib/rhc/helpers.rb +477 -0
  55. data/lib/rhc/highline_extensions.rb +479 -0
  56. data/lib/rhc/json.rb +51 -0
  57. data/lib/rhc/output_helpers.rb +260 -0
  58. data/lib/rhc/rest/activation.rb +11 -0
  59. data/lib/rhc/rest/alias.rb +42 -0
  60. data/lib/rhc/rest/api.rb +87 -0
  61. data/lib/rhc/rest/application.rb +332 -0
  62. data/lib/rhc/rest/attributes.rb +36 -0
  63. data/lib/rhc/rest/authorization.rb +8 -0
  64. data/lib/rhc/rest/base.rb +79 -0
  65. data/lib/rhc/rest/cartridge.rb +154 -0
  66. data/lib/rhc/rest/client.rb +650 -0
  67. data/lib/rhc/rest/deployment.rb +18 -0
  68. data/lib/rhc/rest/domain.rb +98 -0
  69. data/lib/rhc/rest/environment_variable.rb +15 -0
  70. data/lib/rhc/rest/gear_group.rb +16 -0
  71. data/lib/rhc/rest/httpclient.rb +145 -0
  72. data/lib/rhc/rest/key.rb +44 -0
  73. data/lib/rhc/rest/membership.rb +105 -0
  74. data/lib/rhc/rest/mock.rb +1024 -0
  75. data/lib/rhc/rest/user.rb +32 -0
  76. data/lib/rhc/rest.rb +148 -0
  77. data/lib/rhc/ssh_helpers.rb +378 -0
  78. data/lib/rhc/tar_gz.rb +51 -0
  79. data/lib/rhc/usage_templates/command_help.erb +51 -0
  80. data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
  81. data/lib/rhc/usage_templates/help.erb +35 -0
  82. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  83. data/lib/rhc/usage_templates/options_help.erb +12 -0
  84. data/lib/rhc/vendor/okjson.rb +600 -0
  85. data/lib/rhc/vendor/parseconfig.rb +178 -0
  86. data/lib/rhc/vendor/sshkey.rb +253 -0
  87. data/lib/rhc/vendor/zliby.rb +628 -0
  88. data/lib/rhc/version.rb +5 -0
  89. data/lib/rhc/wizard.rb +633 -0
  90. data/lib/rhc.rb +34 -0
  91. data/spec/coverage_helper.rb +89 -0
  92. data/spec/direct_execution_helper.rb +338 -0
  93. data/spec/keys/example.pem +23 -0
  94. data/spec/keys/example_private.pem +27 -0
  95. data/spec/keys/server.pem +19 -0
  96. data/spec/rest_spec_helper.rb +31 -0
  97. data/spec/rhc/assets/cert.crt +22 -0
  98. data/spec/rhc/assets/cert_key_rsa +27 -0
  99. data/spec/rhc/assets/empty.txt +0 -0
  100. data/spec/rhc/assets/env_vars.txt +7 -0
  101. data/spec/rhc/assets/env_vars_2.txt +1 -0
  102. data/spec/rhc/assets/foo.txt +1 -0
  103. data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
  104. data/spec/rhc/assets/targz_sample.tar.gz +0 -0
  105. data/spec/rhc/auth_spec.rb +442 -0
  106. data/spec/rhc/cli_spec.rb +188 -0
  107. data/spec/rhc/command_spec.rb +435 -0
  108. data/spec/rhc/commands/account_spec.rb +42 -0
  109. data/spec/rhc/commands/alias_spec.rb +333 -0
  110. data/spec/rhc/commands/app_spec.rb +754 -0
  111. data/spec/rhc/commands/apps_spec.rb +39 -0
  112. data/spec/rhc/commands/authorization_spec.rb +145 -0
  113. data/spec/rhc/commands/cartridge_spec.rb +641 -0
  114. data/spec/rhc/commands/deployment_spec.rb +286 -0
  115. data/spec/rhc/commands/domain_spec.rb +383 -0
  116. data/spec/rhc/commands/env_spec.rb +493 -0
  117. data/spec/rhc/commands/git_clone_spec.rb +80 -0
  118. data/spec/rhc/commands/logout_spec.rb +86 -0
  119. data/spec/rhc/commands/member_spec.rb +228 -0
  120. data/spec/rhc/commands/port_forward_spec.rb +217 -0
  121. data/spec/rhc/commands/server_spec.rb +69 -0
  122. data/spec/rhc/commands/setup_spec.rb +118 -0
  123. data/spec/rhc/commands/snapshot_spec.rb +179 -0
  124. data/spec/rhc/commands/ssh_spec.rb +163 -0
  125. data/spec/rhc/commands/sshkey_spec.rb +188 -0
  126. data/spec/rhc/commands/tail_spec.rb +81 -0
  127. data/spec/rhc/commands/threaddump_spec.rb +84 -0
  128. data/spec/rhc/config_spec.rb +407 -0
  129. data/spec/rhc/helpers_spec.rb +524 -0
  130. data/spec/rhc/highline_extensions_spec.rb +314 -0
  131. data/spec/rhc/json_spec.rb +30 -0
  132. data/spec/rhc/rest_application_spec.rb +248 -0
  133. data/spec/rhc/rest_client_spec.rb +752 -0
  134. data/spec/rhc/rest_spec.rb +740 -0
  135. data/spec/rhc/targz_spec.rb +55 -0
  136. data/spec/rhc/wizard_spec.rb +756 -0
  137. data/spec/spec_helper.rb +575 -0
  138. data/spec/wizard_spec_helper.rb +330 -0
  139. metadata +435 -0
@@ -0,0 +1,493 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc/commands/env'
4
+ require 'rhc/config'
5
+
6
+ describe RHC::Commands::Env do
7
+
8
+ def exit_with_code_and_message(code, message=nil)
9
+ expect{ run }.to exit_with_code(code)
10
+ run_output.should match(message) if message
11
+ end
12
+
13
+ def exit_with_code_and_without_message(code, message=nil)
14
+ expect{ run }.to exit_with_code(code)
15
+ run_output.should_not match(message) if message
16
+ end
17
+
18
+ def succeed_with_message(message="done")
19
+ exit_with_code_and_message(0, message)
20
+ end
21
+
22
+ def succeed_without_message(message="done")
23
+ exit_with_code_and_without_message(0, message)
24
+ end
25
+
26
+ let!(:rest_client) { MockRestClient.new }
27
+
28
+ before(:each) do
29
+ user_config
30
+ @rest_domain = rest_client.add_domain("mock_domain_0")
31
+ @rest_app = @rest_domain.add_application("mock_app_0", "ruby-1.8.7")
32
+ end
33
+
34
+ describe 'env help' do
35
+ let(:arguments) { ['env', '--help'] }
36
+ context 'help is run' do
37
+ it "should display help" do
38
+ expect { run }.to exit_with_code(0)
39
+ end
40
+ it('should output usage') { run_output.should match("Usage: pbox env <action>$") }
41
+ end
42
+ end
43
+
44
+ describe 'env set --help' do
45
+ [['env', 'set', '--help'],
46
+ ['env', 'add', '--help'],
47
+ ['set-env', '--help'],
48
+ ['env-set', '--help']
49
+ ].each_with_index do |args, i|
50
+ context "help is run run with arguments #{i}" do
51
+ let(:arguments) { args }
52
+ it "should display help" do
53
+ expect { run }.to exit_with_code(0)
54
+ end
55
+ it('should output usage') { run_output.should match("Usage: pbox env-set <VARIABLE=VALUE>") }
56
+ end
57
+ end
58
+ end
59
+
60
+ describe 'env unset --help' do
61
+ [['env', 'unset', '--help'],
62
+ ['env', 'remove', '--help'],
63
+ ['unset-env', '--help'],
64
+ ['env-unset', '--help']
65
+ ].each_with_index do |args, i|
66
+ context "help is run run with arguments #{i}" do
67
+ let(:arguments) { args }
68
+ it "should display help" do
69
+ expect { run }.to exit_with_code(0)
70
+ end
71
+ it('should output usage') { run_output.should match("Usage: pbox env-unset <VARIABLE>") }
72
+ end
73
+ end
74
+ end
75
+
76
+ describe 'env list --help' do
77
+ [['env', 'list', '--help'],
78
+ ['list-env', '--help'],
79
+ ['env-list', '--help']
80
+ ].each_with_index do |args, i|
81
+ context "help is run run with arguments #{i}" do
82
+ let(:arguments) { args }
83
+ it "should display help" do
84
+ expect { run }.to exit_with_code(0)
85
+ end
86
+ it('should output usage') { run_output.should match("Usage: pbox env-list <app> [--namespace NAME]") }
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'env show --help' do
92
+ [['env', 'show', '--help'],
93
+ ['show-env', '--help'],
94
+ ['env-show', '--help']
95
+ ].each_with_index do |args, i|
96
+ context "help is run run with arguments #{i}" do
97
+ let(:arguments) { args }
98
+ it "should display help" do
99
+ expect { run }.to exit_with_code(0)
100
+ end
101
+ it('should output usage') { run_output.should match("Usage: pbox env-show <VARIABLE>") }
102
+ end
103
+ end
104
+ end
105
+
106
+ describe 'set env' do
107
+
108
+ [['env', 'set', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
109
+ ['set-env', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
110
+ ['env', 'set', '-e', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
111
+ ['env', 'set', '--env', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
112
+ ['env', 'set', 'FOO_BAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
113
+ ['env', 'set', 'F1=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
114
+ ['env', 'set', 'F_=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
115
+ ['env', 'set', '_FOO=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
116
+ ['env', 'set', 'FOO=BAR=BAZ', '--app', 'mock_app_0', '--noprompt', '--confirm'],
117
+ ['env', 'set', 'FOO==', '--app', 'mock_app_0', '--noprompt', '--confirm'],
118
+ ['env', 'set', 'FOO=Test 1 2 3', '--app', 'mock_app_0', '--noprompt', '--confirm'],
119
+ ].each_with_index do |args, i|
120
+ context "when run with single env var #{i}" do
121
+ let(:arguments) { args }
122
+ it { succeed_with_message /Setting environment variable\(s\) \.\.\./ }
123
+ it { succeed_with_message /done/ }
124
+ it { succeed_without_message /TEST_ENV_VAR=1/ }
125
+ end
126
+ end
127
+
128
+
129
+ [['env', 'set', 'TEST_ENV_VAR1=1', 'TEST_ENV_VAR2=2', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
130
+ ['set-env', 'TEST_ENV_VAR1=1', 'TEST_ENV_VAR2=2', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
131
+ ['set-env', '-e', 'TEST_ENV_VAR1=1', '-e', 'TEST_ENV_VAR2=2', '-e', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
132
+ ['set-env', '--env', 'TEST_ENV_VAR1=1', '--env', 'TEST_ENV_VAR2=2', '--env', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ]
133
+ ].each_with_index do |args, i|
134
+ context "when run with multiple env vars #{i}" do
135
+ let(:arguments) { args }
136
+ it { succeed_with_message /Setting environment variable\(s\) \.\.\./ }
137
+ it { succeed_with_message /done/ }
138
+ it { succeed_without_message /TEST_ENV_VAR1=1/ }
139
+ it { succeed_without_message /TEST_ENV_VAR2=2/ }
140
+ it { succeed_without_message /TEST_ENV_VAR3=3/ }
141
+ end
142
+ end
143
+
144
+ [['env', 'set', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
145
+ ['set-env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
146
+ ['env', 'set', '-e', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
147
+ ['env', 'set', '--env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
148
+ ].each_with_index do |args, i|
149
+ context "when run with no env var provided #{i}" do
150
+ let(:arguments) { args }
151
+ it "should raise env var not provided exception" do
152
+ expect{ run }.to exit_with_code(159)
153
+ run_output.should match(/Environment variable\(s\) not provided\./)
154
+ run_output.should match(/Please provide at least one environment variable using the syntax VARIABLE=VALUE\./)
155
+ end
156
+ end
157
+ end
158
+
159
+ context 'when run with multiple env vars from file' do
160
+ let(:arguments) {['env', 'set', File.expand_path('../../assets/env_vars.txt', __FILE__), '--app', 'mock_app_0', '--noprompt', '--confirm' ]}
161
+ it { succeed_with_message /FOO=123/ }
162
+ it { succeed_with_message /BAR=456/ }
163
+ it { succeed_with_message /MY_PROTONBOX_ENV_VAR/ }
164
+ it { succeed_with_message /MY_EMPTY_ENV_VAR/ }
165
+ it { succeed_without_message /ZEE/ }
166
+ it { succeed_without_message /LOL/ }
167
+ it { succeed_without_message /MUST NOT BE INCLUDED/ }
168
+ end
169
+
170
+ context 'when run with multiple env vars from multiple files' do
171
+ let(:arguments) {['env', 'set', '-e', File.expand_path('../../assets/env_vars.txt', __FILE__), '-e', File.expand_path('../../assets/env_vars_2.txt', __FILE__), '--app', 'mock_app_0', '--noprompt', '--confirm' ]}
172
+ it { succeed_with_message /FOO=123/ }
173
+ it { succeed_with_message /BAR=456/ }
174
+ it { succeed_with_message /MY_PROTONBOX_ENV_VAR/ }
175
+ it { succeed_with_message /MY_EMPTY_ENV_VAR/ }
176
+ it { succeed_with_message /AND=123/ }
177
+ it { succeed_without_message /ZEE/ }
178
+ it { succeed_without_message /LOL/ }
179
+ it { succeed_without_message /MUST NOT BE INCLUDED/ }
180
+ end
181
+
182
+ context 'when run with empty file' do
183
+ let(:arguments) {['env', 'set', File.expand_path('../../assets/empty.txt', __FILE__), '--app', 'mock_app_0', '--noprompt', '--confirm' ]}
184
+ it "should raise env var not provided exception" do
185
+ expect{ run }.to exit_with_code(159)
186
+ run_output.should match(/Environment variable\(s\) not found in the provided file\(s\)\./)
187
+ run_output.should match(/Please provide at least one environment variable using the syntax VARIABLE=VALUE\./)
188
+ end
189
+ end
190
+
191
+ context 'when run with --noprompt and without --confirm' do
192
+ let(:arguments) { ['env', 'set', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt' ] }
193
+ it("should not ask for confirmation") { expect{ run }.to exit_with_code(0) }
194
+ it("should output confirmation") { run_output.should_not match("This action requires the --confirm option") }
195
+ end
196
+
197
+ context 'when run with --noprompt and without --confirm from file' do
198
+ let(:arguments) { ['env', 'set', File.expand_path('../../assets/env_vars.txt', __FILE__), '--app', 'mock_app_0', '--noprompt' ] }
199
+ it "should ask for confirmation" do
200
+ expect{ run }.to exit_with_code(1)
201
+ end
202
+ it("should output confirmation") { run_output.should match("This action requires the --confirm option") }
203
+ end
204
+
205
+ context 'when run against an unsupported server' do
206
+ before {
207
+ @rest_app.links.delete 'SET_UNSET_ENVIRONMENT_VARIABLES'
208
+ @rest_app.links.delete 'LIST_ENVIRONMENT_VARIABLES'
209
+ }
210
+ let(:arguments) { ['env', 'set', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm' ] }
211
+ it "should raise env var not found exception" do
212
+ expect{ run }.to exit_with_code(158)
213
+ run_output.should match(/Server does not support environment variables/)
214
+ end
215
+ end
216
+
217
+ [['env', 'set', 'FOO.Z=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
218
+ ['env', 'set', '2FOO=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
219
+ ['env', 'set', 'FO$O=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
220
+ ['env', 'set', 'FO%O=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
221
+ ['env', 'set', 'FO*O=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
222
+ ['env', 'set', 'FOO.=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
223
+ ['env', 'set', '=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
224
+ ['env', 'set', '==', '--app', 'mock_app_0', '--noprompt', '--confirm'],
225
+ ].each_with_index do |args, i|
226
+ context "when run with invalid env var names #{i}" do
227
+ let(:arguments) { args }
228
+ it "should raise env var not provided exception" do
229
+ expect{ run }.to exit_with_code(159)
230
+ run_output.should match(/Environment variable\(s\) not provided\./)
231
+ run_output.should match(/Please provide at least one environment variable using the syntax VARIABLE=VALUE\./)
232
+ end
233
+ end
234
+ end
235
+
236
+ end
237
+
238
+ describe 'unset env' do
239
+
240
+ [['env', 'unset', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
241
+ ['unset-env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
242
+ ['env', 'unset', '-e', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
243
+ ['env', 'unset', '--env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ]
244
+ ].each_with_index do |args, i|
245
+ context "when run with single env var #{i}" do
246
+ let(:arguments) { args }
247
+ it { succeed_with_message /TEST_ENV_VAR/ }
248
+ it { succeed_with_message /Removing environment variable\(s\) \.\.\./ }
249
+ it { succeed_with_message /removed/ }
250
+ end
251
+ end
252
+
253
+ [['env', 'unset', 'TEST_ENV_VAR1', 'TEST_ENV_VAR2', 'TEST_ENV_VAR3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
254
+ ['unset-env', 'TEST_ENV_VAR1', 'TEST_ENV_VAR2', 'TEST_ENV_VAR3', '--app', 'mock_app_0', '--noprompt', '--confirm' ]
255
+ ].each_with_index do |args, i|
256
+ context "when run with multiple env vars #{i}" do
257
+ let(:arguments) { args }
258
+ it { succeed_with_message /TEST_ENV_VAR1/ }
259
+ it { succeed_with_message /TEST_ENV_VAR2/ }
260
+ it { succeed_with_message /TEST_ENV_VAR3/ }
261
+ it { succeed_with_message /Removing environment variable\(s\) \.\.\./ }
262
+ it { succeed_with_message /removed/ }
263
+ end
264
+ end
265
+
266
+ context 'when run with --noprompt and without --confirm' do
267
+ let(:arguments) { ['env', 'unset', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt' ] }
268
+ it "should ask for confirmation" do
269
+ expect{ run }.to exit_with_code(1)
270
+ end
271
+ it("should output confirmation") { run_output.should match("This action requires the --confirm option") }
272
+ end
273
+ end
274
+
275
+ describe 'list env' do
276
+ context 'when list with default format' do
277
+ before(:each) do
278
+ @rest_app.set_environment_variables(
279
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
280
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
281
+ end
282
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0'] }
283
+ it { succeed_with_message /FOO=123/ }
284
+ it { succeed_with_message /BAR=456/ }
285
+ it "should contain the environment variables" do
286
+ @rest_app.environment_variables.length.should == 2
287
+ end
288
+ end
289
+
290
+ context 'when list with default format and empty env vars' do
291
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0'] }
292
+ it "should exit with no message" do
293
+ expect{ run }.to exit_with_code(0)
294
+ end
295
+ end
296
+
297
+ context 'when list with quotes format' do
298
+ before(:each) do
299
+ @rest_app.set_environment_variables(
300
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
301
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
302
+ end
303
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--quotes'] }
304
+ it { succeed_with_message /FOO="123"/ }
305
+ it { succeed_with_message /BAR="456"/ }
306
+ it "should contain the environment variables" do
307
+ @rest_app.environment_variables.length.should == 2
308
+ end
309
+ end
310
+
311
+ context 'when list with quotes format and empty env vars' do
312
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--quotes'] }
313
+ it "should exit with no message" do
314
+ expect{ run }.to exit_with_code(0)
315
+ end
316
+ end
317
+
318
+ context 'when list with table format' do
319
+ before(:each) do
320
+ @rest_app.set_environment_variables(
321
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
322
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
323
+ end
324
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--table'] }
325
+ it { succeed_with_message /Name\s+Value/ }
326
+ it { succeed_with_message /FOO\s+123/ }
327
+ it { succeed_with_message /BAR\s+456/ }
328
+ it "should contain the right number of env vars" do
329
+ @rest_app.environment_variables.length.should == 2
330
+ end
331
+ end
332
+
333
+ context 'when list with table and quotes format' do
334
+ before(:each) do
335
+ @rest_app.set_environment_variables(
336
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
337
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
338
+ end
339
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--table', '--quotes'] }
340
+ it { succeed_with_message /Name\s+Value/ }
341
+ it { succeed_with_message /FOO\s+"123"/ }
342
+ it { succeed_with_message /BAR\s+"456"/ }
343
+ it "should contain the right number of env vars" do
344
+ @rest_app.environment_variables.length.should == 2
345
+ end
346
+ end
347
+
348
+ context 'when list with table format and empty env vars' do
349
+ let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--table'] }
350
+ it "should exit with no message" do
351
+ expect{ run }.to exit_with_code(0)
352
+ end
353
+ end
354
+ end
355
+
356
+ describe 'show env' do
357
+ context 'when show with default format' do
358
+ before(:each) do
359
+ @rest_app.set_environment_variables(
360
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
361
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
362
+ end
363
+ let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0'] }
364
+ it { succeed_with_message /FOO=123/ }
365
+ it "should not contain env vars not specified to show" do
366
+ run_output.should_not match(/BAR=456/)
367
+ end
368
+ it "should contain the right number of env vars" do
369
+ @rest_app.environment_variables.length.should == 2
370
+ end
371
+ end
372
+
373
+ context 'when show with default format and not found env var' do
374
+ let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0'] }
375
+ it "should raise env var not found exception" do
376
+ expect{ run }.to exit_with_code(157)
377
+ run_output.should match(/Environment variable\(s\) FOO can't be found in application mock_app_0/)
378
+ end
379
+ end
380
+
381
+ context 'when show with default format and not found env var' do
382
+ before(:each) do
383
+ @rest_app.set_environment_variables(
384
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
385
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
386
+ end
387
+ let(:arguments) { ['env', 'show', 'ZEE', '--app', 'mock_app_0'] }
388
+ it "should contain the right number of env vars" do
389
+ @rest_app.environment_variables.length.should == 2
390
+ end
391
+ it "should not contain env vars not specified to show" do
392
+ run_output.should_not match(/FOO=123/)
393
+ run_output.should_not match(/BAR=456/)
394
+ end
395
+ it "should raise env var not found exception" do
396
+ expect{ run }.to exit_with_code(157)
397
+ run_output.should match(/Environment variable\(s\) ZEE can't be found in application mock_app_0/)
398
+ end
399
+ end
400
+
401
+ context 'when show with quotes format' do
402
+ before(:each) do
403
+ @rest_app.set_environment_variables(
404
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
405
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
406
+ end
407
+ let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0', '--quotes'] }
408
+ it { succeed_with_message /FOO="123"/ }
409
+ it "should not contain env vars not specified to show" do
410
+ run_output.should_not match(/BAR="456"/)
411
+ end
412
+ it "should contain the right number of env vars" do
413
+ @rest_app.environment_variables.length.should == 2
414
+ end
415
+ end
416
+
417
+ context 'when show with quotes format and not found env var' do
418
+ before(:each) do
419
+ @rest_app.set_environment_variables(
420
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
421
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
422
+ end
423
+ let(:arguments) { ['env', 'show', 'ZEE', '--app', 'mock_app_0', '--quotes'] }
424
+ it "should contain the right number of env vars" do
425
+ @rest_app.environment_variables.length.should == 2
426
+ end
427
+ it "should not contain env vars not specified to show" do
428
+ run_output.should_not match(/FOO=123/)
429
+ run_output.should_not match(/BAR=456/)
430
+ end
431
+ it "should raise env var not found exception" do
432
+ expect{ run }.to exit_with_code(157)
433
+ run_output.should match(/Environment variable\(s\) ZEE can't be found in application mock_app_0/)
434
+ end
435
+ end
436
+
437
+ context 'when show with table format' do
438
+ before(:each) do
439
+ @rest_app.set_environment_variables(
440
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
441
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
442
+ end
443
+ let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0', '--table'] }
444
+ it { succeed_with_message /Name\s+Value/ }
445
+ it { succeed_with_message /FOO\s+123/ }
446
+ it "should not contain env vars not specified to show" do
447
+ run_output.should_not match(/BAR/)
448
+ end
449
+ it "should contain the right number of env vars" do
450
+ @rest_app.environment_variables.length.should == 2
451
+ end
452
+ end
453
+
454
+ context 'when show with table and quotes format' do
455
+ before(:each) do
456
+ @rest_app.set_environment_variables(
457
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
458
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
459
+ end
460
+ let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0', '--table', '--quotes'] }
461
+ it { succeed_with_message /Name\s+Value/ }
462
+ it { succeed_with_message /FOO\s+"123"/ }
463
+ it "should not contain env vars not specified to show" do
464
+ run_output.should_not match(/BAR/)
465
+ end
466
+ it "should contain the right number of env vars" do
467
+ @rest_app.environment_variables.length.should == 2
468
+ end
469
+ end
470
+
471
+ context 'when show with table format and not found env var' do
472
+ before(:each) do
473
+ @rest_app.set_environment_variables(
474
+ [RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
475
+ RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
476
+ end
477
+ let(:arguments) { ['env', 'show', 'ZEE', '--app', 'mock_app_0', '--table'] }
478
+ it "should contain the right number of env vars" do
479
+ @rest_app.environment_variables.length.should == 2
480
+ end
481
+ it "should not contain env vars not specified to show" do
482
+ run_output.should_not match(/FOO/)
483
+ run_output.should_not match(/BAR/)
484
+ end
485
+ it "should raise env var not found exception" do
486
+ expect{ run }.to exit_with_code(157)
487
+ run_output.should match(/Environment variable\(s\) ZEE can't be found in application mock_app_0/)
488
+ end
489
+ end
490
+
491
+ end
492
+
493
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc/commands/git_clone'
4
+ require 'fileutils'
5
+
6
+ describe RHC::Commands::GitClone do
7
+ before(:each) do
8
+ FakeFS.activate!
9
+ FakeFS::FileSystem.clear
10
+ user_config
11
+ @instance = RHC::Commands::GitClone.new
12
+ RHC::Commands::GitClone.stub(:new) do
13
+ @instance.stub(:git_config_get) { "" }
14
+ @instance.stub(:git_config_set) { "" }
15
+ Kernel.stub(:sleep) { }
16
+ @instance.stub(:host_exists?) do |host|
17
+ host.match("dnserror") ? false : true
18
+ end
19
+ @instance
20
+ end
21
+ end
22
+ let!(:rest_client){ MockRestClient.new }
23
+ before(:each) do
24
+ @domain = rest_client.add_domain("mockdomain")
25
+ @app = @domain.add_application("app1", "mock_unique_standalone_cart")
26
+ end
27
+
28
+ after(:each) do
29
+ FakeFS.deactivate!
30
+ end
31
+
32
+ describe 'git-clone' do
33
+ let(:arguments) { ['app', 'git-clone', 'app1'] }
34
+
35
+ context "stubbing git_clone_repo" do
36
+ context "reports success successfully" do
37
+ before do
38
+ @instance.stub(:git_clone_repo) do |git_url, repo_dir|
39
+ Dir::mkdir(repo_dir)
40
+ say "Cloned"
41
+ true
42
+ end
43
+ end
44
+
45
+ it { expect { run }.to exit_with_code(0) }
46
+ it { run_output.should match("Cloned") }
47
+ end
48
+
49
+ context "testing git_clone_deploy_hooks" do
50
+ before do
51
+ @instance.stub(:git_clone_repo) do |git_url, repo_dir|
52
+ FileUtils.mkdir_p "#{repo_dir}/.git/hooks"
53
+ FileUtils.mkdir_p "#{repo_dir}/.protonbox/git_hooks"
54
+ FileUtils.touch "#{repo_dir}/.protonbox/git_hooks/pre_commit"
55
+ @instance.git_clone_deploy_hooks(repo_dir)
56
+ say "Copied" if File.exists?("#{repo_dir}/.git/hooks/pre_commit")
57
+ true
58
+ end
59
+
60
+ # Get around the FakeFS bug (defunkt/fakefs#177) by
61
+ # stubbing the #cp call to inject a expected fs entry
62
+ FileUtils.stub(:cp) do |hook, dir|
63
+ FakeFS::FileSystem.add(
64
+ File.join(dir, File.basename(hook)),
65
+ FakeFS::FileSystem.find(hook))
66
+ end
67
+ end
68
+ it { expect { run }.to exit_with_code(0) }
69
+ it { run_output.should match("Copied") }
70
+ end
71
+
72
+ context "reports failure" do
73
+ before{ @instance.stub(:git_clone_repo).and_raise(RHC::GitException) }
74
+
75
+ it { expect { run }.to exit_with_code(216) }
76
+ it { run_output.should match("Git returned an error") }
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc'
4
+ require 'rhc/commands/logout'
5
+
6
+ describe RHC::Commands::Logout do
7
+
8
+ describe '#run' do
9
+ let(:arguments) { ['logout'] }
10
+ let(:username) { 'foo' }
11
+ let(:password) { nil }
12
+ let(:supports_auth) { false }
13
+ let(:server) { mock_uri }
14
+ let!(:token_store) { RHC::Auth::TokenStore.new(Dir.mktmpdir) }
15
+ before{ user_config }
16
+ before do
17
+ stub_api(false, supports_auth)
18
+ challenge{ stub_user }
19
+ RHC::Auth::TokenStore.stub(:new).and_return(token_store)
20
+ end
21
+
22
+ context "when calling from the alias" do
23
+ let(:arguments){ ['account', 'logout', '-h'] }
24
+ it("should print usage"){ run_output.should match "Usage: pbox logout" }
25
+ end
26
+
27
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
28
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
29
+ it("should display a message"){ run_output.should match("All local sessions removed.") }
30
+
31
+ context "when --all is requested" do
32
+ let(:arguments) { ['account', 'logout', '--all'] }
33
+
34
+ context "if the server does not implement authorizations" do
35
+ it("should display a message"){ run_output.should match(/Deleting all authorizations associated with your account.*not supported/) }
36
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
37
+ end
38
+
39
+ context "if the server implements authorizations" do
40
+ let(:supports_auth) { true }
41
+ before{ stub_delete_authorizations }
42
+
43
+ it("should display a message"){ run_output.should match(/Deleting all authorizations associated with your account.*done/) }
44
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
45
+ end
46
+ end
47
+
48
+ context "when --token is provided" do
49
+ let(:arguments) { ['account', 'logout', '--token', 'foo'] }
50
+ def user_auth; { :token => 'foo' }; end
51
+
52
+ context "if the server does not implement authorizations" do
53
+ it("should display a message"){ run_output.should match(/Ending session on server.*not supported/) }
54
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
55
+ end
56
+
57
+ context "if the server implements authorizations" do
58
+ let(:supports_auth) { true }
59
+
60
+ context "if the server returns successfully" do
61
+ before{ stub_delete_authorization('foo') }
62
+
63
+ it("should display a message"){ run_output.should match(/Ending session on server.*deleted/) }
64
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
65
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
66
+ end
67
+
68
+ context "if the server rejects the token" do
69
+ before{ stub_request(:delete, mock_href('broker/rest/user/authorizations/foo', false)).to_return(:status => 401, :body => {}.to_json) }
70
+
71
+ it("should display a message"){ run_output.should match(/Ending session on server.*already closed/) }
72
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
73
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
74
+ end
75
+
76
+ context "if the server returns an unexpected error" do
77
+ before{ stub_request(:delete, mock_href('broker/rest/user/authorizations/foo', false)).to_return(:status => 500, :body => {}.to_json) }
78
+
79
+ it("should display a message"){ run_output.should match(/Ending session on server.*The server did not respond/) }
80
+ it("should exit with success"){ expect{ run }.to exit_with_code(0) }
81
+ it("should clear the token cache"){ expect{ run }.to call(:clear).on(token_store) }
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end