remy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/spec/remy_spec.rb CHANGED
@@ -1,340 +1,112 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Remy do
4
- describe '.configuration' do
5
- describe 'with no yml files' do
6
- it 'should return an empty mash' do
7
- Remy.configuration.should == Hashie::Mash.new
8
- end
9
- end
10
-
11
- describe "yml files" do
12
- it 'should combine multiple yaml files into a mash' do
13
- Remy.configure { |config| config.yml_files = ['fixtures/foo.yml', 'fixtures/bar.yml'].map { |f| File.join(File.dirname(__FILE__), f) } }
14
- subject.configuration.yml_files.should == ['fixtures/foo.yml', 'fixtures/bar.yml'].map { |f| File.join(File.dirname(__FILE__), f) }
15
- subject.configuration.blah.should == 'bar' # From foo.yml
16
- subject.configuration.baz.should == 'baz' # From bar.yml
17
- subject.configuration.colors.to_hash.symbolize_keys.should == {:blue => 'blue', :green => 'green', :red => 'red'}
18
- end
19
-
20
- it 'should return an empty array if there are no yml files' do
21
- Remy.configure {}
22
- subject.configuration.yml_files.should == []
23
- end
24
-
25
- it 'should not raise an error if there is a file does does not exist' do
26
- expect do
27
- Remy.configure { |config| config.yml_files = ['does_not_exist.yml'] }
28
- end.should_not raise_error
29
- end
30
- end
31
-
32
- describe "cookbooks path" do
33
- it "should work if a single cookbook path is specified" do
34
- Remy.configure { |config| config.cookbook_path = 'cookbooks' }
35
- subject.configuration.cookbook_path.should == ['cookbooks']
36
- end
37
-
38
- it "should work if multiple cookbook paths are specified" do
39
- Remy.configure { |config| config.cookbook_path = ['cookbooks1', 'cookbooks2'] }
40
- subject.configuration.cookbook_path.should == ['cookbooks1', 'cookbooks2']
41
- end
42
-
43
- it "should return an empty array if no cookbook paths are specified" do
44
- Remy.configure {}
45
- subject.configuration.cookbook_path.should == []
46
- end
47
- end
48
-
49
- describe "specs path" do
50
- it "should work if a single spec path is specified" do
51
- Remy.configure { |config| config.spec_path = 'specs' }
52
- subject.configuration.spec_path.should == ['specs']
53
- end
54
-
55
- it "should work if multiple spec paths are specified" do
56
- Remy.configure { |config| config.spec_path = ['specs1', 'specs2'] }
57
- subject.configuration.spec_path.should == ['specs1', 'specs2']
58
- end
59
-
60
- it "should return an empty array if no spec paths are specified" do
61
- Remy.configure {}
62
- subject.configuration.spec_path.should == []
63
- end
64
- end
65
-
66
- describe "roles path" do
67
- it "should work if a single file is specified" do
68
- Remy.configure { |config| config.roles_path = 'roles' }
69
- subject.configuration.roles_path.should == ['roles']
70
- end
71
-
72
- it "should work if multiple files are specified" do
73
- Remy.configure { |config| config.roles_path = ['roles1', 'roles2'] }
74
- subject.configuration.roles_path.should == ['roles1', 'roles2']
75
- end
76
-
77
- it "should return an empty array if no roles paths are specified" do
78
- Remy.configure {}
79
- subject.configuration.roles_path.should == []
80
- end
81
- end
82
-
83
- describe "node attributes" do
84
- it "should merge in the other node attributes from the hash" do
85
- Remy.configure { |config| config.node_attributes = {:another_node_attribute => 'red'} }
86
- subject.configuration.another_node_attribute.should == 'red'
87
- end
88
-
89
- it "should not blow up if there no node attributes are specified" do
90
- lambda { Remy.configure {} }.should_not raise_error
91
- end
92
- end
93
-
94
- describe "#remote_chef_dir" do
95
- it "should default to /var/chef if no option is given" do
96
- subject.configuration.remote_chef_dir.should == '/var/chef'
97
- end
98
-
99
- it "should be able to be overriden" do
100
- Remy.configure { |config| config.remote_chef_dir = '/foo/shef' }
101
- subject.configuration.remote_chef_dir.should == '/foo/shef'
102
- end
103
- end
104
- end
105
4
 
106
5
  describe '.to_json' do
107
6
  it 'should create the expected JSON' do
108
- Remy.configure {}
7
+ Remy::Config::Chef.configure {}
109
8
  lambda do
110
9
  JSON.parse(subject.to_json)
111
10
  end.should_not raise_error
112
11
  end
113
12
  end
114
13
 
115
- context 'with a configuration' do
116
- before do
117
- Remy.configure do |config|
118
- config.yml_files = ['fixtures/chef.yml'].map { |f| File.join(File.dirname(__FILE__), f) }
119
- end
120
- end
121
-
122
- describe '.servers' do
123
- it 'returns all servers' do
124
- Remy.servers.size.should == 3
125
- Remy.servers['db.sharespost.com'].color.should == 'yellow'
126
- end
127
- it 'should return servers that match the criteria (using standard Enumerable methods)' do
128
- Remy.servers.select { |(k, v)| v.rails_env == 'demo' }.map(&:first).should == ['web.sharespost.com', 'demo.sharespost.com']
129
- end
130
- end
131
-
132
- describe '.find_servers' do
133
- it 'should return servers that match the criteria' do
134
- Remy.find_servers(:rails_env => 'demo').keys.should == ['web.sharespost.com', 'demo.sharespost.com']
135
- end
136
-
137
- it 'should return all servers if there are no criteria' do
138
- Remy.find_servers.keys.should == ['db.sharespost.com', 'web.sharespost.com', 'demo.sharespost.com']
139
- end
140
-
141
- it 'should return servers that match the criteria (with multiple criteria)' do
142
- Remy.find_servers(:rails_env => 'demo', :color => 'blue').keys.should == ['web.sharespost.com']
143
- end
144
-
145
- it "should return nil if there are no servers specified in the yaml file" do
146
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
147
- Remy.find_servers(:rails_env => 'demo').should be_nil
148
- end
149
- end
150
-
151
- describe '.find_server' do
152
- it 'should return the first server that matchs the criteria' do
153
- Remy.find_server(:rails_env => 'demo').keys.should == ['web.sharespost.com']
154
- end
155
-
156
- it 'should return nil if there are no servers specifie in the yml files' do
157
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
158
- Remy.find_server(:rails_env => 'demo').should be_nil
159
- end
160
- end
161
-
162
- describe '.find_server_config' do
163
- it 'should return the first server that matchs the criteria' do
164
- Remy.find_server_config(:rails_env => 'demo').to_hash.should == {"color"=>"blue", "recipes"=>["recipe[hello_world]"], "rails_env"=>"demo", "ip_address"=> IP_ADDRESS}
165
- end
166
-
167
- it 'should return nil if no server info is found' do
168
- Remy.find_server_config(:rails_env => 'foo').should be_nil
169
- end
170
-
171
- it 'should return nil if there are no servers in the yml files' do
172
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
173
- Remy.find_server_config(:rails_env => 'foo').should be_nil
174
- end
175
- end
176
-
177
- describe '.find_server_config_by_name' do
178
- it 'should return the server that matches the name' do
179
- Remy.find_server_config_by_name('db.sharespost.com').to_hash.should == {"encoding"=>"utf8", "adapter"=>"mysql2", "color"=>"yellow", "rails_env"=>"production", "ip_address"=>"51.51.51.51"}
180
- end
181
-
182
- it 'should return nil if theres no server that matches the name' do
183
- Remy.find_server_config_by_name('db.asdfjkll.com').should be_nil
184
- end
185
-
186
- it 'should return nil (and not blow up) if there are no servers in the yml files' do
187
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
188
- Remy.find_server_config_by_name('db.asdfjkll.com').should be_nil
189
- end
190
-
191
- it 'should return nil (and not blow up) if there is no Remy configuration' do
192
- Remy.instance_variable_set('@configuration', nil)
193
- Remy.find_server_config_by_name('db.asdfjkll.com').should be_nil
194
- end
195
- end
196
-
197
- describe '.cloud_configuration' do
198
- it 'should return nil if it has not been specified in the yml files' do
199
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
200
- Remy.cloud_configuration.should be_nil
201
- end
202
-
203
- it 'should return the cloud configuration options if present in the yml files' do
204
- Remy.cloud_configuration.should == Hashie::Mash.new(
205
- :cloud_api_key => 'abcdefg12345',
206
- :cloud_provider => 'Rackspace',
207
- :cloud_username => 'sharespost',
208
- :flavor_id => 4,
209
- :image_id => 49,
210
- :server_name => 'new-server.somedomain.com')
211
-
212
- end
213
-
214
- it 'should return nil if there is currently no Remy configuration' do
215
- Remy.instance_variable_set('@configuration', nil)
216
- Remy.cloud_configuration.should be_nil
217
- end
218
- end
219
-
220
- describe '.bootstrap' do
221
- it 'should return nil if it has not been specified in the yml files' do
222
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
223
- Remy.bootstrap.should be_nil
224
- end
225
-
226
- it 'should return the bootstrap options if present in the yml files' do
227
- Remy.bootstrap.should == Hashie::Mash.new(
228
- :ruby_version => '1.9.2',
229
- :gems => {
230
- :chef => '0.10.4',
231
- :rspec => '2.7.0',
232
- :bundler => '1.0.21'
233
- })
234
- end
235
-
236
- it 'should return nil if there is currently no Remy configuration' do
237
- Remy.instance_variable_set('@configuration', nil)
238
- Remy.bootstrap.should be_nil
239
- end
240
- end
241
- end
242
14
 
243
15
  describe 'support for the rake tasks' do
244
16
  before do
245
- Remy.configure do |config|
17
+ Remy::Config::Chef.configure do |config|
246
18
  config.yml_files = ['fixtures/foo.yml', 'fixtures/bar.yml', 'fixtures/chef.yml'].map { |f| File.join(File.dirname(__FILE__), f) }
247
19
  end
248
20
  end
249
21
 
250
22
  describe '.convert_properties_to_hash' do
251
23
  it 'should convert properties to a hash' do
252
- Remy.send(:convert_properties_to_hash, ' foo:bar blah:blech').should == {:foo => 'bar', :blah => 'blech'}
24
+ Remy::Config::Chef.send(:convert_properties_to_hash, ' foo:bar blah:blech').should == {:foo => 'bar', :blah => 'blech'}
253
25
  end
254
26
 
255
27
  it 'should convert a blank string to nil' do
256
- Remy.send(:convert_properties_to_hash, ' ').should be_nil
28
+ Remy::Config::Chef.send(:convert_properties_to_hash, ' ').should be_nil
257
29
  end
258
30
 
259
31
  it 'should return nil if the string is not in property format' do
260
- Remy.send(:convert_properties_to_hash, 'demo.sharespost.com').should be_nil
32
+ Remy::Config::Chef.send(:convert_properties_to_hash, 'demo.sharespost.com').should be_nil
261
33
  end
262
34
  end
263
35
 
264
36
  describe '.determine_ip_addresses_for_remy_run' do
265
37
  context 'top level ip address is present in the yml files' do
266
38
  before do
267
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
39
+ Remy::Config::Chef.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/hello_world_chef.yml') }
268
40
  end
269
41
 
270
42
  it 'should return the ip address in the yml file if no ip address is given and an ip is present in the yml files' do
271
- Remy.send(:determine_ip_addresses_for_remy_run, '').should == ['50.57.162.242']
43
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, '').should == [IP_ADDRESS_OF_REMY_TEST]
272
44
  end
273
45
 
274
46
  it 'should handle receiving no parameters' do
275
47
  expect do
276
- Remy.send(:determine_ip_addresses_for_remy_run, nil).should == ['50.57.162.242']
48
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, nil).should == [IP_ADDRESS_OF_REMY_TEST]
277
49
  end.to_not raise_error
278
50
  end
279
51
  end
280
52
 
281
53
  context 'no top level ip address is present in the yml files' do
282
54
  before do
283
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/foo.yml') }
55
+ Remy::Config::Chef.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/foo.yml') }
284
56
  end
285
57
 
286
58
  it 'should return nothing if no ip address is given and no top-level ip address is in the yml files' do
287
- Remy.send(:determine_ip_addresses_for_remy_run, '').should == []
59
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, '').should == []
288
60
  end
289
61
 
290
62
  it 'should return the ip address if an ip address is given and no top-level ip address is in the yml files' do
291
- Remy.send(:determine_ip_addresses_for_remy_run, '1.2.3.4').should == ['1.2.3.4']
63
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, '1.2.3.4').should == ['1.2.3.4']
292
64
  end
293
65
 
294
66
  it 'should handle receiving no parameters' do
295
67
  expect do
296
- Remy.send(:determine_ip_addresses_for_remy_run, nil).should == []
68
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, nil).should == []
297
69
  end.to_not raise_error
298
70
  end
299
71
  end
300
72
 
301
73
  context ':servers section present in the yml files' do
302
74
  before do
303
- Remy.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/chef.yml') }
75
+ Remy::Config::Chef.configure { |config| config.yml_files = File.join(File.dirname(__FILE__), 'fixtures/chef.yml') }
304
76
  end
305
77
 
306
78
  it 'should return an ip address if an ip address is given as property value (this IP address is not in the :servers section of the yml files)' do
307
- Remy.send(:determine_ip_addresses_for_remy_run, 'ip_address:1.2.3.4').should == ['1.2.3.4']
79
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, 'ip_address:1.2.3.4').should == ['1.2.3.4']
308
80
  end
309
81
 
310
82
  it 'should return the ip address if the ip address was found in the :servers section of the yml files' do
311
- Remy.send(:determine_ip_addresses_for_remy_run, 'ip_address:52.52.52.52').should == ['52.52.52.52']
83
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, 'ip_address:52.52.52.52').should == ['52.52.52.52']
312
84
  end
313
85
 
314
86
  it 'should return the IP address - the IP address is specified, but is not found in the servers section in the yml files' do
315
- Remy.send(:determine_ip_addresses_for_remy_run, '1.2.3.4').should == ['1.2.3.4']
87
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, '1.2.3.4').should == ['1.2.3.4']
316
88
  end
317
89
 
318
90
  it 'should return the IP address - the IP address is specified, and is found in the servers section in the yml files' do
319
- Remy.send(:determine_ip_addresses_for_remy_run, '52.52.52.52').should == ['52.52.52.52']
91
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, '52.52.52.52').should == ['52.52.52.52']
320
92
  end
321
93
 
322
94
  it 'should be able to find servers by name from the :servers section of the yml file' do
323
- Remy.send(:determine_ip_addresses_for_remy_run, 'demo.sharespost.com').should == ['52.52.52.52']
95
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, 'demo.sharespost.com').should == ['52.52.52.52']
324
96
  end
325
97
 
326
98
  it 'should be able to find servers by multiple names' do
327
- Remy.send(:determine_ip_addresses_for_remy_run, ' demo.sharespost.com db.sharespost.com ').should == ['52.52.52.52', '51.51.51.51']
99
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, ' demo.sharespost.com db.sharespost.com ').should == ['52.52.52.52', '51.51.51.51']
328
100
  end
329
101
 
330
102
  it 'should be able to find servers by multiple names and ip addresses' do
331
- Remy.send(:determine_ip_addresses_for_remy_run, ' demo.sharespost.com 51.51.51.51').should == ['52.52.52.52', '51.51.51.51']
103
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, ' demo.sharespost.com 51.51.51.51').should == ['52.52.52.52', '51.51.51.51']
332
104
  end
333
105
 
334
106
  it 'should be able to find all of the servers from the yml files that match certain attributes' do
335
- Remy.send(:determine_ip_addresses_for_remy_run, 'rails_env:demo').should == ['50.57.162.242', '52.52.52.52']
336
- Remy.send(:determine_ip_addresses_for_remy_run, 'rails_env:demo color:green').should == ['52.52.52.52']
337
- Remy.send(:determine_ip_addresses_for_remy_run, 'rails_env:demo color:yellow').should == []
107
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, 'rails_env:demo').should == [IP_ADDRESS_OF_REMY_TEST, '52.52.52.52']
108
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, 'rails_env:demo color:green').should == ['52.52.52.52']
109
+ Remy::Config::Chef.send(:determine_ip_addresses_for_remy_run, 'rails_env:demo color:yellow').should == []
338
110
  end
339
111
  end
340
112
  end
data/spec/spec_helper.rb CHANGED
@@ -3,14 +3,17 @@ ENV["RAILS_ENV"] ||= 'test'
3
3
  require 'rubygems'
4
4
  require 'bundler/setup'
5
5
  require 'active_support'
6
- require 'mocha'
7
6
  require 'json'
8
7
  require 'remy'
9
8
 
10
9
  Dir[File.join(File.dirname(__FILE__), 'spec', 'support', '**' '*.rb')].each { |f| require f }
11
10
 
12
- RSpec.configure do |config|
13
- config.mock_with :mocha
11
+ IP_ADDRESS_OF_REMY_TEST = '108.166.98.115'
12
+
13
+ def chef_fixture(file)
14
+ File.join(File.dirname(__FILE__), 'fixtures/' + file)
14
15
  end
15
16
 
16
- IP_ADDRESS = '50.57.162.242'
17
+ def project_root
18
+ File.expand_path(File.join(File.dirname(__FILE__), '../'))
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'rake'
3
+
4
+ describe 'background.rake' do
5
+ before do
6
+ Rake.application.rake_require "tasks/remy"
7
+ Rake::Task.define_task(:environment)
8
+ end
9
+
10
+ it 'should run the task to save the JSON file from the Chef yml config files' do
11
+ Remy::Config::Chef.should_receive(:save_node_json).with('my/path/to/node.json')
12
+ Rake.application['remy:save_node_json'].invoke('my/path/to/node.json')
13
+ end
14
+ end