startapp 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYRIGHT +1 -0
- data/LICENSE +11 -0
- data/README.md +95 -0
- data/Rakefile +6 -0
- data/autocomplete/rhc_bash +1672 -0
- data/bin/app +37 -0
- data/conf/express.conf +8 -0
- data/features/assets/deploy.tar.gz +0 -0
- data/features/core_feature.rb +191 -0
- data/features/deployments_feature.rb +129 -0
- data/features/domains_feature.rb +58 -0
- data/features/keys_feature.rb +37 -0
- data/features/members_feature.rb +166 -0
- data/lib/rhc/auth/basic.rb +64 -0
- data/lib/rhc/auth/token.rb +102 -0
- data/lib/rhc/auth/token_store.rb +53 -0
- data/lib/rhc/auth.rb +5 -0
- data/lib/rhc/autocomplete.rb +66 -0
- data/lib/rhc/autocomplete_templates/bash.erb +39 -0
- data/lib/rhc/cartridge_helpers.rb +118 -0
- data/lib/rhc/cli.rb +40 -0
- data/lib/rhc/command_runner.rb +185 -0
- data/lib/rhc/commands/account.rb +25 -0
- data/lib/rhc/commands/alias.rb +124 -0
- data/lib/rhc/commands/app.rb +726 -0
- data/lib/rhc/commands/apps.rb +20 -0
- data/lib/rhc/commands/authorization.rb +115 -0
- data/lib/rhc/commands/base.rb +174 -0
- data/lib/rhc/commands/cartridge.rb +329 -0
- data/lib/rhc/commands/clone.rb +66 -0
- data/lib/rhc/commands/configure.rb +20 -0
- data/lib/rhc/commands/create.rb +100 -0
- data/lib/rhc/commands/delete.rb +19 -0
- data/lib/rhc/commands/deploy.rb +32 -0
- data/lib/rhc/commands/deployment.rb +82 -0
- data/lib/rhc/commands/domain.rb +172 -0
- data/lib/rhc/commands/env.rb +142 -0
- data/lib/rhc/commands/force_stop.rb +17 -0
- data/lib/rhc/commands/git_clone.rb +34 -0
- data/lib/rhc/commands/logout.rb +51 -0
- data/lib/rhc/commands/logs.rb +21 -0
- data/lib/rhc/commands/member.rb +148 -0
- data/lib/rhc/commands/port_forward.rb +197 -0
- data/lib/rhc/commands/reload.rb +17 -0
- data/lib/rhc/commands/restart.rb +17 -0
- data/lib/rhc/commands/scp.rb +54 -0
- data/lib/rhc/commands/server.rb +40 -0
- data/lib/rhc/commands/setup.rb +60 -0
- data/lib/rhc/commands/show.rb +43 -0
- data/lib/rhc/commands/snapshot.rb +137 -0
- data/lib/rhc/commands/ssh.rb +51 -0
- data/lib/rhc/commands/sshkey.rb +97 -0
- data/lib/rhc/commands/start.rb +17 -0
- data/lib/rhc/commands/stop.rb +17 -0
- data/lib/rhc/commands/tail.rb +47 -0
- data/lib/rhc/commands/threaddump.rb +14 -0
- data/lib/rhc/commands/tidy.rb +17 -0
- data/lib/rhc/commands.rb +396 -0
- data/lib/rhc/config.rb +321 -0
- data/lib/rhc/context_helper.rb +121 -0
- data/lib/rhc/core_ext.rb +202 -0
- data/lib/rhc/coverage_helper.rb +33 -0
- data/lib/rhc/deployment_helpers.rb +111 -0
- data/lib/rhc/exceptions.rb +256 -0
- data/lib/rhc/git_helpers.rb +106 -0
- data/lib/rhc/help_formatter.rb +55 -0
- data/lib/rhc/helpers.rb +481 -0
- data/lib/rhc/highline_extensions.rb +479 -0
- data/lib/rhc/json.rb +51 -0
- data/lib/rhc/output_helpers.rb +260 -0
- data/lib/rhc/rest/activation.rb +11 -0
- data/lib/rhc/rest/alias.rb +42 -0
- data/lib/rhc/rest/api.rb +87 -0
- data/lib/rhc/rest/application.rb +348 -0
- data/lib/rhc/rest/attributes.rb +36 -0
- data/lib/rhc/rest/authorization.rb +8 -0
- data/lib/rhc/rest/base.rb +79 -0
- data/lib/rhc/rest/cartridge.rb +162 -0
- data/lib/rhc/rest/client.rb +650 -0
- data/lib/rhc/rest/deployment.rb +18 -0
- data/lib/rhc/rest/domain.rb +98 -0
- data/lib/rhc/rest/environment_variable.rb +15 -0
- data/lib/rhc/rest/gear_group.rb +16 -0
- data/lib/rhc/rest/httpclient.rb +145 -0
- data/lib/rhc/rest/key.rb +44 -0
- data/lib/rhc/rest/membership.rb +105 -0
- data/lib/rhc/rest/mock.rb +1042 -0
- data/lib/rhc/rest/user.rb +32 -0
- data/lib/rhc/rest.rb +148 -0
- data/lib/rhc/scp_helpers.rb +27 -0
- data/lib/rhc/ssh_helpers.rb +380 -0
- data/lib/rhc/tar_gz.rb +51 -0
- data/lib/rhc/usage_templates/command_help.erb +51 -0
- data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
- data/lib/rhc/usage_templates/help.erb +61 -0
- data/lib/rhc/usage_templates/missing_help.erb +1 -0
- data/lib/rhc/usage_templates/options_help.erb +12 -0
- data/lib/rhc/vendor/okjson.rb +600 -0
- data/lib/rhc/vendor/parseconfig.rb +178 -0
- data/lib/rhc/vendor/sshkey.rb +253 -0
- data/lib/rhc/vendor/zliby.rb +628 -0
- data/lib/rhc/version.rb +5 -0
- data/lib/rhc/wizard.rb +637 -0
- data/lib/rhc.rb +34 -0
- data/spec/coverage_helper.rb +82 -0
- data/spec/direct_execution_helper.rb +339 -0
- data/spec/keys/example.pem +23 -0
- data/spec/keys/example_private.pem +27 -0
- data/spec/keys/server.pem +19 -0
- data/spec/rest_spec_helper.rb +31 -0
- data/spec/rhc/assets/cert.crt +22 -0
- data/spec/rhc/assets/cert_key_rsa +27 -0
- data/spec/rhc/assets/empty.txt +0 -0
- data/spec/rhc/assets/env_vars.txt +7 -0
- data/spec/rhc/assets/env_vars_2.txt +1 -0
- data/spec/rhc/assets/foo.txt +1 -0
- data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
- data/spec/rhc/assets/targz_sample.tar.gz +0 -0
- data/spec/rhc/auth_spec.rb +442 -0
- data/spec/rhc/cli_spec.rb +186 -0
- data/spec/rhc/command_spec.rb +435 -0
- data/spec/rhc/commands/account_spec.rb +42 -0
- data/spec/rhc/commands/alias_spec.rb +333 -0
- data/spec/rhc/commands/app_spec.rb +777 -0
- data/spec/rhc/commands/apps_spec.rb +39 -0
- data/spec/rhc/commands/authorization_spec.rb +157 -0
- data/spec/rhc/commands/cartridge_spec.rb +665 -0
- data/spec/rhc/commands/clone_spec.rb +41 -0
- data/spec/rhc/commands/deployment_spec.rb +327 -0
- data/spec/rhc/commands/domain_spec.rb +401 -0
- data/spec/rhc/commands/env_spec.rb +493 -0
- data/spec/rhc/commands/git_clone_spec.rb +102 -0
- data/spec/rhc/commands/logout_spec.rb +86 -0
- data/spec/rhc/commands/member_spec.rb +247 -0
- data/spec/rhc/commands/port_forward_spec.rb +217 -0
- data/spec/rhc/commands/scp_spec.rb +77 -0
- data/spec/rhc/commands/server_spec.rb +69 -0
- data/spec/rhc/commands/setup_spec.rb +118 -0
- data/spec/rhc/commands/snapshot_spec.rb +179 -0
- data/spec/rhc/commands/ssh_spec.rb +163 -0
- data/spec/rhc/commands/sshkey_spec.rb +188 -0
- data/spec/rhc/commands/tail_spec.rb +81 -0
- data/spec/rhc/commands/threaddump_spec.rb +84 -0
- data/spec/rhc/config_spec.rb +407 -0
- data/spec/rhc/helpers_spec.rb +531 -0
- data/spec/rhc/highline_extensions_spec.rb +314 -0
- data/spec/rhc/json_spec.rb +30 -0
- data/spec/rhc/rest_application_spec.rb +258 -0
- data/spec/rhc/rest_client_spec.rb +752 -0
- data/spec/rhc/rest_spec.rb +740 -0
- data/spec/rhc/targz_spec.rb +55 -0
- data/spec/rhc/wizard_spec.rb +756 -0
- data/spec/spec_helper.rb +575 -0
- data/spec/wizard_spec_helper.rb +330 -0
- metadata +469 -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: app 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: app 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: app 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: app 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: app 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_OPENSHIFT_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_OPENSHIFT_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,102 @@
|
|
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 'when run without git installed' do
|
36
|
+
before do
|
37
|
+
@instance.stub(:has_git?) { false }
|
38
|
+
end
|
39
|
+
it "should print out git warning" do
|
40
|
+
run_output.should match("You do not have git installed")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "stubbing git_clone_repo" do
|
45
|
+
context "reports success successfully" do
|
46
|
+
before do
|
47
|
+
@instance.stub(:git_clone_repo) do |git_url, repo_dir|
|
48
|
+
Dir::mkdir(repo_dir)
|
49
|
+
say "Cloned"
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it { expect { run }.to exit_with_code(0) }
|
55
|
+
it { run_output.should match("Cloned") }
|
56
|
+
|
57
|
+
context 'when app has an initial git url' do
|
58
|
+
before do
|
59
|
+
@app2 = @domain.add_application("app2", "mock_unique_standalone_cart", nil, "default", "git://test")
|
60
|
+
@instance.stub(:git_remote_add) do |remote_name, remote_url|
|
61
|
+
say "Added remote #{remote_name} pointing to #{remote_url}"
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
let(:arguments) { ['git-clone', 'app2'] }
|
66
|
+
it { run_output.should match("Added remote startapp pointing to git://test") }
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context "testing git_clone_deploy_hooks" do
|
72
|
+
before do
|
73
|
+
@instance.stub(:git_clone_repo) do |git_url, repo_dir|
|
74
|
+
FileUtils.mkdir_p "#{repo_dir}/.git/hooks"
|
75
|
+
FileUtils.mkdir_p "#{repo_dir}/.openshift/git_hooks"
|
76
|
+
FileUtils.touch "#{repo_dir}/.openshift/git_hooks/pre_commit"
|
77
|
+
@instance.git_clone_deploy_hooks(repo_dir)
|
78
|
+
say "Copied" if File.exists?("#{repo_dir}/.git/hooks/pre_commit")
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get around the FakeFS bug (defunkt/fakefs#177) by
|
83
|
+
# stubbing the #cp call to inject a expected fs entry
|
84
|
+
FileUtils.stub(:cp) do |hook, dir|
|
85
|
+
FakeFS::FileSystem.add(
|
86
|
+
File.join(dir, File.basename(hook)),
|
87
|
+
FakeFS::FileSystem.find(hook))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
it { expect { run }.to exit_with_code(0) }
|
91
|
+
it { run_output.should match("Copied") }
|
92
|
+
end
|
93
|
+
|
94
|
+
context "reports failure" do
|
95
|
+
before{ @instance.stub(:git_clone_repo).and_raise(RHC::GitException) }
|
96
|
+
|
97
|
+
it { expect { run }.to exit_with_code(216) }
|
98
|
+
it { run_output.should match("Git returned an error") }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|