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,407 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/config'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
describe RHC::Config do
|
6
|
+
subject{ RHC::Config }
|
7
|
+
before do
|
8
|
+
ENV['LIBRA_SERVER'] = nil
|
9
|
+
ENV['HTTP_PROXY'] = nil
|
10
|
+
ENV['http_proxy'] = nil
|
11
|
+
mock_terminal
|
12
|
+
RHC::Config.stub(:home_dir).and_return('/home/mock_user')
|
13
|
+
FakeFS.activate!
|
14
|
+
FakeFS::FileSystem.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
FakeFS.deactivate!
|
19
|
+
ENV['HTTP_PROXY'] = nil
|
20
|
+
ENV['http_proxy'] = nil
|
21
|
+
ENV['LIBRA_SERVER'] = nil
|
22
|
+
RHC::Config.send(:instance_variable_set, :@default, nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "class" do
|
26
|
+
it("should raise when foo is invoked") { expect{ subject.method_missing(:foo) }.to raise_error(NoMethodError) }
|
27
|
+
it("should invoke a method on default") { subject.username.should be subject.default.username }
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:values){ {} }
|
31
|
+
|
32
|
+
describe "#use_config" do
|
33
|
+
subject{ RHC::Config.new.tap{ |c| c.stub(:load_config_files) } }
|
34
|
+
|
35
|
+
context "when an exception is raised" do
|
36
|
+
before{ subject.should_receive(:set_opts_config).with(File.expand_path('foo')).and_raise(Errno::EISDIR.new('foo')) }
|
37
|
+
it("should wrap the error"){ expect{ subject.use_config('foo') }.to raise_error(ArgumentError, /Unable to read configuration file.*foo/) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to_options" do
|
42
|
+
subject do
|
43
|
+
RHC::Config.new.tap do |c|
|
44
|
+
c.stub(:home_dir).and_return('/home/mock_user')
|
45
|
+
c.stub(:load_config_files)
|
46
|
+
c.instance_variable_set(:@opts, values)
|
47
|
+
c.instance_variable_set(:@defaults, nil)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with an non true value for insecure" do
|
52
|
+
let(:values){ {'insecure' => 'untruth'} }
|
53
|
+
its(:to_options){ should == {:insecure => false} }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with an invalid timeout" do
|
57
|
+
let(:values){ {'timeout' => 'a'} }
|
58
|
+
it{ expect{ subject.to_options }.to raise_error(ArgumentError) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with standard values" do
|
62
|
+
let(:values) do
|
63
|
+
{
|
64
|
+
'insecure' => 'true',
|
65
|
+
'default_rhlogin' => 'user',
|
66
|
+
'libra_server' => 'test.com',
|
67
|
+
'password' => 'pass',
|
68
|
+
'ssl_client_cert_file' => 'file1',
|
69
|
+
'ssl_ca_file' => 'file2',
|
70
|
+
'timeout' => '1',
|
71
|
+
'use_authorization_tokens' => 'true',
|
72
|
+
}
|
73
|
+
end
|
74
|
+
its(:to_options){ should == {:insecure => true, :timeout => 1, :ssl_ca_file => 'file2', :ssl_client_cert_file => 'file1', :rhlogin => 'user', :password => 'pass', :server => 'test.com', :use_authorization_tokens => true} }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "Config default values with no files" do
|
79
|
+
before{ subject.initialize }
|
80
|
+
|
81
|
+
its(:has_global_config?){ should be_false }
|
82
|
+
its(:has_local_config?){ should be_false }
|
83
|
+
its(:has_opts_config?){ should be_false }
|
84
|
+
|
85
|
+
it "should return openshift.redhat.com for the server" do
|
86
|
+
subject['libra_server'].should == "broker.startapp.bg"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "Config values with /etc/openshift/express.conf" do
|
91
|
+
|
92
|
+
it "should have only a global config" do
|
93
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com", "global@redhat.com")
|
94
|
+
subject.initialize
|
95
|
+
subject.has_global_config?.should be_true
|
96
|
+
subject.has_local_config?.should be_false
|
97
|
+
subject.has_opts_config?.should be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should get values from the global config" do
|
101
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
|
102
|
+
"global@redhat.com",
|
103
|
+
{"random_value" => 12})
|
104
|
+
subject.initialize
|
105
|
+
|
106
|
+
subject['libra_server'].should == "global.openshift.redhat.com"
|
107
|
+
subject.default_rhlogin.should == "global@redhat.com"
|
108
|
+
subject['random_value'].should == "12"
|
109
|
+
subject['non_value'].should be_nil
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should have libra_server fallback to the default if not set in config" do
|
114
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
|
115
|
+
"global@redhat.com")
|
116
|
+
subject.initialize
|
117
|
+
|
118
|
+
subject['libra_server'].should == "broker.startapp.bg"
|
119
|
+
subject.default_rhlogin.should == "global@redhat.com"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "With a mock home dir" do
|
124
|
+
|
125
|
+
def stub_config
|
126
|
+
config = RHC::Config.new
|
127
|
+
RHC::Config.instance_variable_set(:@default, config)
|
128
|
+
config.stub(:home_dir).and_return(ConfigHelper.home_dir)
|
129
|
+
RHC::Config.stub(:new).and_return(config)
|
130
|
+
RHC::Config.default.should == config
|
131
|
+
config.read_config_files
|
132
|
+
end
|
133
|
+
|
134
|
+
context "Config values with ~/.startapp/express.conf" do
|
135
|
+
it "should have global and local config" do
|
136
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
|
137
|
+
"global@redhat.com")
|
138
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
139
|
+
"local.openshift.redhat.com","local@redhat.com")
|
140
|
+
stub_config
|
141
|
+
|
142
|
+
subject.home_conf_path.should == File.join(ConfigHelper.home_dir, '.startapp')
|
143
|
+
subject.local_config_path.should == File.join(ConfigHelper.home_dir, '.startapp', 'express.conf')
|
144
|
+
subject.has_global_config?.should be_true
|
145
|
+
subject.has_local_config?.should be_true
|
146
|
+
subject.has_opts_config?.should be_false
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should get values from local config" do
|
150
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
|
151
|
+
"global@redhat.com",
|
152
|
+
{"random_value" => "12"})
|
153
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
154
|
+
"local.openshift.redhat.com",
|
155
|
+
"local@redhat.com",
|
156
|
+
{"random_value" => 11})
|
157
|
+
stub_config
|
158
|
+
|
159
|
+
subject['libra_server'].should == "local.openshift.redhat.com"
|
160
|
+
subject.default_rhlogin.should == "local@redhat.com"
|
161
|
+
subject['random_value'].should == "11"
|
162
|
+
subject['non_value'].should be_nil
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should fallback to the default or global if not set in config" do
|
166
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
|
167
|
+
"global@redhat.com")
|
168
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
169
|
+
nil,
|
170
|
+
nil,
|
171
|
+
{"random_value" => 11})
|
172
|
+
stub_config
|
173
|
+
|
174
|
+
subject['libra_server'].should == "broker.startapp.bg"
|
175
|
+
subject.default_rhlogin.should == "global@redhat.com"
|
176
|
+
subject['random_value'].should == "11"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "Config values with LIBRA_SERVER ENV set" do
|
181
|
+
it "should get values from local config" do
|
182
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
|
183
|
+
"global@redhat.com",
|
184
|
+
{"random_value" => "12"})
|
185
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
186
|
+
"local.openshift.redhat.com",
|
187
|
+
"local@redhat.com",
|
188
|
+
{"random_value" => 11})
|
189
|
+
ENV['LIBRA_SERVER'] = "env.openshift.redhat.com"
|
190
|
+
|
191
|
+
stub_config
|
192
|
+
subject.set_local_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'))
|
193
|
+
|
194
|
+
subject['libra_server'].should == "env.openshift.redhat.com"
|
195
|
+
subject.default_rhlogin.should == "local@redhat.com"
|
196
|
+
subject['random_value'].should == "11"
|
197
|
+
subject['non_value'].should be_nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "Config values with options set" do
|
202
|
+
it "should have global and local config" do
|
203
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
|
204
|
+
"global@redhat.com")
|
205
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
206
|
+
"local.openshift.redhat.com","local@redhat.com")
|
207
|
+
ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
|
208
|
+
"opts.openshift.redhat.com",
|
209
|
+
"opts@redhat.com")
|
210
|
+
stub_config
|
211
|
+
subject.check_cpath({"config" => ConfigHelper.opts_config_path,
|
212
|
+
"random_val" => "ok"})
|
213
|
+
|
214
|
+
subject.has_global_config?.should be_true
|
215
|
+
subject.has_local_config?.should be_true
|
216
|
+
subject.has_opts_config?.should be_true
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should get values from local config" do
|
220
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
|
221
|
+
"global@redhat.com",
|
222
|
+
{"random_value" => "12"})
|
223
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
224
|
+
"local.openshift.redhat.com",
|
225
|
+
"local@redhat.com",
|
226
|
+
{"random_value" => 11})
|
227
|
+
ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
|
228
|
+
"opts.openshift.redhat.com",
|
229
|
+
"opts@redhat.com",
|
230
|
+
{"random_value" => 10})
|
231
|
+
stub_config
|
232
|
+
subject.check_cpath({"config" => ConfigHelper.opts_config_path,
|
233
|
+
"random_val" => "ok"})
|
234
|
+
|
235
|
+
subject['libra_server'].should == "opts.openshift.redhat.com"
|
236
|
+
subject.default_rhlogin.should == "opts@redhat.com"
|
237
|
+
subject['random_value'].should == "10"
|
238
|
+
subject['non_value'].should be_nil
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should fallback to the default or global or local if not set in config" do
|
242
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
|
243
|
+
"global@redhat.com")
|
244
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.startapp', 'express.conf'),
|
245
|
+
nil,
|
246
|
+
nil,
|
247
|
+
{"random_value" => 11,
|
248
|
+
"local_value" => "local"})
|
249
|
+
ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
|
250
|
+
nil,
|
251
|
+
nil,
|
252
|
+
{"random_value" => 10})
|
253
|
+
stub_config
|
254
|
+
subject.check_cpath({"config" => ConfigHelper.opts_config_path,
|
255
|
+
"random_val" => "ok"})
|
256
|
+
|
257
|
+
subject['libra_server'].should == "broker.startapp.bg"
|
258
|
+
subject.default_rhlogin.should == "global@redhat.com"
|
259
|
+
subject['random_value'].should == "10"
|
260
|
+
subject['local_value'].should == "local"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "Debug options" do
|
266
|
+
it "should show debug as false because nothing is set" do
|
267
|
+
subject.initialize
|
268
|
+
ConfigHelper.check_legacy_debug({}).should be_false
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should show debug as 'true' because config is set" do
|
272
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
273
|
+
nil,
|
274
|
+
nil,
|
275
|
+
{"debug" => "true"})
|
276
|
+
subject.initialize
|
277
|
+
ConfigHelper.check_legacy_debug({}).should == "true"
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should show debug as false because config is set" do
|
281
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
282
|
+
nil,
|
283
|
+
nil,
|
284
|
+
{"debug" => "false"})
|
285
|
+
subject.initialize
|
286
|
+
ConfigHelper.check_legacy_debug({}).should be_false
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should show debug as true because config is set" do
|
290
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
291
|
+
nil,
|
292
|
+
nil,
|
293
|
+
{"debug" => "true"})
|
294
|
+
subject.initialize
|
295
|
+
ConfigHelper.check_legacy_debug({"debug" => false}).should be_true
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should show debug as true because opt is set" do
|
299
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
300
|
+
nil,
|
301
|
+
nil,
|
302
|
+
{"debug" => "false"})
|
303
|
+
subject.initialize
|
304
|
+
ConfigHelper.check_legacy_debug({"debug" => true}).should be_true
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context "Proxy ENV variable parsing" do
|
309
|
+
before do
|
310
|
+
subject.initialize
|
311
|
+
['http_proxy','HTTP_PROXY'].each do |var|
|
312
|
+
ENV[var] = nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should return a direct http connection" do
|
317
|
+
subject.using_proxy?.should_not == true
|
318
|
+
end
|
319
|
+
|
320
|
+
['http_proxy','HTTP_PROXY'].each do |var|
|
321
|
+
it "should retrun a proxy http connection for #{var}" do
|
322
|
+
ENV[var] = "fakeproxy.foo:8080"
|
323
|
+
# returns a generic class so we check to make sure it is not a
|
324
|
+
# Net::HTTP class and rely on simplecov to make sure the proxy
|
325
|
+
# code path was run
|
326
|
+
subject.using_proxy?.should == true
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context "it should have the correct values" do
|
331
|
+
let(:vars){ subject.proxy_vars }
|
332
|
+
before do
|
333
|
+
ENV['http_proxy'] = "my_user:my_pass@fakeproxy.foo:8080"
|
334
|
+
end
|
335
|
+
|
336
|
+
{
|
337
|
+
:user => 'my_user',
|
338
|
+
:pass => 'my_pass',
|
339
|
+
:address => 'fakeproxy.foo',
|
340
|
+
:port => 8080
|
341
|
+
}.each do |var,expected|
|
342
|
+
it "for #{var}" do
|
343
|
+
vars[var].should == expected
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context "Configuration file parsing" do
|
350
|
+
it "should exit if config file can't be read" do
|
351
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
352
|
+
"global.openshift.redhat.com",
|
353
|
+
"global@redhat.com")
|
354
|
+
subject.initialize
|
355
|
+
RHC::Vendor::ParseConfig.stub(:new) { raise Errno::EACCES.new("Fake can't read file") }
|
356
|
+
subject.stub(:exit) { |code| code }
|
357
|
+
|
358
|
+
expect { subject.check_cpath({"config" => "fake.conf"}) }.to raise_error(Errno::EACCES)
|
359
|
+
|
360
|
+
# write out config file so it exists but is not readable
|
361
|
+
ConfigHelper.write_out_config("fake.conf",
|
362
|
+
"global.openshift.redhat.com",
|
363
|
+
"global@redhat.com")
|
364
|
+
|
365
|
+
expect { subject.read_config_files }.to raise_error(Errno::EACCES)
|
366
|
+
expect { subject.set_local_config("fake.conf") }.to raise_error(Errno::EACCES)
|
367
|
+
expect { subject.set_opts_config("fake.conf") }.to raise_error(Errno::EACCES)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
class ConfigHelper
|
373
|
+
@@global_config_path = '/etc/openshift/express.conf'
|
374
|
+
@@home_dir = '/home/mock_user'
|
375
|
+
@@opts_config_path = File.join(@@home_dir, "my.conf")
|
376
|
+
|
377
|
+
def self.global_config_path
|
378
|
+
@@global_config_path
|
379
|
+
end
|
380
|
+
|
381
|
+
def self.home_dir
|
382
|
+
@@home_dir
|
383
|
+
end
|
384
|
+
|
385
|
+
def self.opts_config_path
|
386
|
+
@@opts_config_path
|
387
|
+
end
|
388
|
+
|
389
|
+
def self.check_legacy_debug(opts)
|
390
|
+
# this simulates how the old rhc code checked for debug
|
391
|
+
# in the future this should all be filtered through the Config module
|
392
|
+
# and an app should just have to use subject.debug?
|
393
|
+
debug = RHC::Config['debug'] == 'false' ? nil : RHC::Config['debug']
|
394
|
+
debug = true if opts.has_key? 'debug'
|
395
|
+
debug
|
396
|
+
end
|
397
|
+
|
398
|
+
def self.write_out_config(config_path, server, login, other={})
|
399
|
+
FileUtils.mkdir_p File.dirname(config_path)
|
400
|
+
File.open(config_path, "w") do |f|
|
401
|
+
f.write "# This is a test file\n\n"
|
402
|
+
f.write("libra_server = #{server}\n") unless server.nil?
|
403
|
+
f.write("default_rhlogin = #{login}\n\n") unless login.nil?
|
404
|
+
other.each { |key, value| f.write("#{key}=#{value}\n") }
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|