clc-cheffish 0.8.clc → 0.8.3.clc

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 579bebaf5cce935439331e89b3ce39236e012bbf
4
- data.tar.gz: ce355bc6e80774b6a17a44640a832fb4f5b82bb7
3
+ metadata.gz: 37af8ecf98a56c9edf8ea77a79fa4106a70ef466
4
+ data.tar.gz: 06086fc87748f2412d5c87f5e72c796d6378ed92
5
5
  SHA512:
6
- metadata.gz: 573774848e4ed345c30677ffc381824853053857bc024a02372148aaffc5d9026c1238cb4a43c2edd07846d787717e6f6a43f81c1589ff265b664a1a2929e87c
7
- data.tar.gz: 00f427b83499d5b73c374e4468a95340be2b8e4fad6d61e4edd2135c4ce86fcfa6f28e77849f280a69bbe60eda417839699ac28edcc3db705fcafe51e887813c
6
+ metadata.gz: 404e7a16288c4f56a1575e9ca2039b20f67449cdb205b3864767b66b61f0f52e192b4f78ce4d5e18f3a6b300ac8cf0ac43e032915fbce8fca160f00ef1666e21
7
+ data.tar.gz: 0134dfe98c135aa77ebffeb35db9dfbb9b6238667732a87a18b6bbd3e45ed7fc635e1211eb6cb42c8a1bed82e6642b1690263eaf7b88d9d15d0bf518316c1b4f
@@ -170,7 +170,7 @@ class Chef::Provider::ChefDataBagItem < Cheffish::ChefProviderBase
170
170
  result = current_decrypted.merge(new_resource.raw_data || {})
171
171
  end
172
172
  result['id'] = new_resource.id
173
- apply_modifiers(new_resource.raw_data_modifiers, result)
173
+ result = apply_modifiers(new_resource.raw_data_modifiers, result)
174
174
  end
175
175
  end
176
176
 
@@ -12,11 +12,36 @@ class Chef::Provider::ChefMirror < Chef::Provider::LWRPBase
12
12
  end
13
13
 
14
14
  action :upload do
15
- copy_to(local_fs, remote_fs)
15
+ with_modified_config do
16
+ copy_to(local_fs, remote_fs)
17
+ end
16
18
  end
17
19
 
18
20
  action :download do
19
- copy_to(remote_fs, local_fs)
21
+ with_modified_config do
22
+ copy_to(remote_fs, local_fs)
23
+ end
24
+ end
25
+
26
+ def with_modified_config
27
+ # pre-Chef-12 ChefFS reads versioned_cookbooks out of Chef::Config instead of
28
+ # taking it as an input, so we need to modify it for the duration of copy_to
29
+ @old_versioned_cookbooks = Chef::Config.versioned_cookbooks
30
+ # If versioned_cookbooks is explicitly set, set it.
31
+ if !new_resource.versioned_cookbooks.nil?
32
+ Chef::Config.versioned_cookbooks = new_resource.versioned_cookbooks
33
+
34
+ # If new_resource.chef_repo_path is set, versioned_cookbooks defaults to true.
35
+ # Otherwise, it stays at its current Chef::Config value.
36
+ elsif new_resource.chef_repo_path
37
+ Chef::Config.versioned_cookbooks = true
38
+ end
39
+
40
+ begin
41
+ yield
42
+ ensure
43
+ Chef::Config.versioned_cookbooks = @old_versioned_cookbooks
44
+ end
20
45
  end
21
46
 
22
47
  def copy_to(src_root, dest_root)
@@ -84,7 +109,8 @@ class Chef::Provider::ChefMirror < Chef::Provider::LWRPBase
84
109
  :chef_server_url => new_resource.chef_server[:chef_server_url],
85
110
  :node_name => new_resource.chef_server[:options][:client_name],
86
111
  :client_key => new_resource.chef_server[:options][:client_key],
87
- :repo_mode => repo_mode
112
+ :repo_mode => repo_mode,
113
+ :versioned_cookbooks => Chef::Config.versioned_cookbooks
88
114
  }
89
115
  Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", config)
90
116
  end
@@ -23,8 +23,9 @@ class Chef::Resource::ChefMirror < Chef::Resource::LWRPBase
23
23
  # versioned_cookbooks defaults to true.
24
24
  attribute :chef_repo_path, :kind_of => [ String, Hash ]
25
25
 
26
- # Whether the repo path contains / should contain cookbooks with versioned names,
26
+ # Whether the repo path should contain cookbooks with versioned names,
27
27
  # i.e. cookbooks/mysql-1.0.0, cookbooks/mysql-1.2.0, etc.
28
+ # Defaults to true if chef_repo_path is specified, or to Chef::Config.versioned_cookbooks otherwise.
28
29
  attribute :versioned_cookbooks, :kind_of => [ TrueClass, FalseClass ]
29
30
 
30
31
  # Chef server
data/lib/cheffish.rb CHANGED
@@ -57,7 +57,7 @@ module Cheffish
57
57
  Cheffish.profiled_config(chef_config)
58
58
  end
59
59
 
60
- def self.honor_local_mode(local_mode_default = true)
60
+ def self.honor_local_mode(local_mode_default = true, &block)
61
61
  if !Chef::Config.has_key?(:local_mode) && !local_mode_default.nil?
62
62
  Chef::Config.local_mode = local_mode_default
63
63
  end
@@ -31,8 +31,8 @@ module Cheffish
31
31
  if new_resource.complete
32
32
  result = normalize(resource_to_json(new_resource))
33
33
  else
34
- # If resource is incomplete, use current json to fill any holes
35
- result = Chef::Mixin::DeepMerge.hash_only_merge(current_json, resource_to_json(new_resource))
34
+ # If the resource is incomplete, we use the current json to fill any holes
35
+ result = current_json.merge(resource_to_json(new_resource))
36
36
  end
37
37
  augment_new_json(result)
38
38
  end
@@ -131,7 +131,18 @@ module Cheffish
131
131
  modifiers.each do |path, value|
132
132
  path = [path] if !path.kind_of?(Array)
133
133
  path = path.map { |path_part| path_part.to_s }
134
- parent = path[0..-2].inject(json) { |hash, path_part| hash ? hash[path_part] : nil }
134
+ parent = 0.upto(path.size-2).inject(json) do |hash, index|
135
+ if hash.nil?
136
+ nil
137
+ elsif !hash.is_a?(Hash)
138
+ raise "Attempt to set #{path} to #{value} when #{path[0..index-1]} is not a hash"
139
+ else
140
+ hash[path[index]]
141
+ end
142
+ end
143
+ if !parent.nil? && !parent.is_a?(Hash)
144
+ raise "Attempt to set #{path} to #{value} when #{path[0..-2]} is not a hash"
145
+ end
135
146
  existing_value = parent ? parent[path[-1]] : nil
136
147
 
137
148
  if value.is_a?(Proc)
@@ -139,16 +150,17 @@ module Cheffish
139
150
  end
140
151
  if value == :delete
141
152
  parent.delete(path[-1]) if parent
142
- # TODO clean up parent chain if hash is completely emptied
143
153
  else
144
- if !parent
145
- # Create parent if necessary
146
- parent = path[0..-2].inject(json) do |hash, path_part|
147
- hash[path_part] = {} if !hash[path_part]
148
- hash[path_part]
149
- end
154
+ # Create parent if necessary, overwriting values
155
+ parent = path[0..-2].inject(json) do |hash, path_part|
156
+ hash[path_part] = {} if !hash[path_part]
157
+ hash[path_part]
158
+ end
159
+ if path.size > 0
160
+ parent[path[-1]] = value
161
+ else
162
+ json = value
150
163
  end
151
- parent[path[-1]] = value
152
164
  end
153
165
  end
154
166
  json
@@ -72,14 +72,22 @@ class Chef
72
72
 
73
73
  # Ensure all paths are given
74
74
  %w(acl client cookbook container data_bag environment group node role).each do |type|
75
- options["#{type}_path"] ||= begin
75
+ # Set the options as symbol keys and then copy to string keys
76
+ string_key = "#{type}_path"
77
+ symbol_key = "#{type}_path".to_sym
78
+
79
+ options[symbol_key] ||= begin
76
80
  if options[:chef_repo_path].kind_of?(String)
77
81
  Chef::Util::PathHelper.join(options[:chef_repo_path], "#{type}s")
78
82
  else
79
83
  options[:chef_repo_path].map { |path| Chef::Util::PathHelper.join(path, "#{type}s")}
80
84
  end
81
85
  end
82
- end
86
+
87
+ # Copy over to string keys for things that use string keys (ChefFS)...
88
+ # TODO: Fix ChefFS to take symbols or use something that is insensitive to the difference
89
+ options[string_key] = options[symbol_key]
90
+ end
83
91
 
84
92
  chef_fs = Chef::ChefFS::Config.new(options).local_fs
85
93
  chef_fs.write_pretty_json = true
@@ -138,7 +146,7 @@ else
138
146
  class Chef
139
147
  class Util
140
148
  class PathHelper
141
- def join(*args)
149
+ def self.join(*args)
142
150
  Chef::Config.path_join(*args)
143
151
  end
144
152
  end
@@ -1,3 +1,3 @@
1
1
  module Cheffish
2
- VERSION = '0.8.clc'
2
+ VERSION = '0.8.3.clc'
3
3
  end
@@ -8,7 +8,7 @@ repo_path = Dir.mktmpdir('chef_repo')
8
8
  describe Chef::Resource::ChefClient do
9
9
  extend SpecSupport
10
10
 
11
- when_the_chef_server 'is in multi-org mode', :osc_compat => false, :single_org => false do
11
+ when_the_chef_12_server 'is in multi-org mode' do
12
12
  organization 'foo'
13
13
 
14
14
  before :each do
@@ -5,7 +5,7 @@ require 'chef/provider/chef_container'
5
5
  describe Chef::Resource::ChefContainer do
6
6
  extend SpecSupport
7
7
 
8
- when_the_chef_server 'is in multi-org mode', :osc_compat => false, :single_org => false do
8
+ when_the_chef_12_server 'is in multi-org mode' do
9
9
  organization 'foo'
10
10
 
11
11
  before :each do
@@ -5,7 +5,7 @@ require 'chef/provider/chef_group'
5
5
  describe Chef::Resource::ChefGroup do
6
6
  extend SpecSupport
7
7
 
8
- when_the_chef_server 'is in multi-org mode', :osc_compat => false, :single_org => false do
8
+ when_the_chef_12_server 'is in multi-org mode' do
9
9
  organization 'foo'
10
10
 
11
11
  before :each do
@@ -5,17 +5,20 @@ require 'chef/provider/chef_mirror'
5
5
  describe Chef::Resource::ChefMirror do
6
6
  extend SpecSupport
7
7
 
8
- when_the_chef_server 'is in multi-org mode', :osc_compat => false, :single_org => false do
8
+ when_the_chef_12_server 'is in multi-org mode' do
9
9
  organization 'foo'
10
10
 
11
11
  before :each do
12
12
  Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo').to_s
13
13
  end
14
14
 
15
- context 'and is empty' do
15
+ describe 'basic download and upload' do
16
16
  when_the_repository 'is full of stuff' do
17
17
  file 'nodes/x.json', {}
18
18
  file 'roles/x.json', {}
19
+ directory 'cookbooks/x' do
20
+ file 'metadata.rb', 'name "x"; version "2.0.0"'
21
+ end
19
22
 
20
23
  it "Download grabs defaults" do
21
24
  run_recipe do
@@ -37,6 +40,7 @@ describe Chef::Resource::ChefMirror do
37
40
  expect(chef_run).to have_updated('chef_mirror[]', :upload)
38
41
  expect { get('nodes/x') }.not_to raise_error
39
42
  expect { get('roles/x') }.not_to raise_error
43
+ expect { get('cookbooks/x/2.0.0') }.not_to raise_error
40
44
  end
41
45
 
42
46
  it 'chef_mirror with concurrency 0 fails with a reasonable message' do
@@ -50,7 +54,96 @@ describe Chef::Resource::ChefMirror do
50
54
  }.to raise_error /chef_mirror.concurrency must be above 0/
51
55
  end
52
56
  end
57
+ end
58
+
59
+ context 'and the Chef server has a node and role in it' do
60
+ node 'x', {}
61
+ role 'x', {}
62
+
63
+ when_the_repository 'is empty' do
64
+ it "Download grabs the node and role" do
65
+ run_recipe do
66
+ chef_mirror '' do
67
+ action :download
68
+ end
69
+ end
70
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
71
+ expect(File.exist?(path_to('nodes/x.json'))).to be true
72
+ expect(File.exist?(path_to('roles/x.json'))).to be true
73
+ end
74
+
75
+ it "Upload uploads nothing" do
76
+ run_recipe do
77
+ chef_mirror '' do
78
+ action :upload
79
+ end
80
+ end
81
+ expect(chef_run).not_to have_updated('chef_mirror[]', :upload)
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'and the Chef server has nodes and roles named x' do
87
+ node 'x', {}
88
+ role 'x', {}
89
+
90
+ when_the_repository 'has nodes and roles named y' do
91
+ file 'nodes/y.json', {}
92
+ file 'roles/y.json', {}
93
+
94
+ it "Download grabs the x's" do
95
+ run_recipe do
96
+ chef_mirror '' do
97
+ action :download
98
+ end
99
+ end
100
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
101
+ expect(File.exist?(path_to('nodes/x.json'))).to be true
102
+ expect(File.exist?(path_to('roles/x.json'))).to be true
103
+ expect(File.exist?(path_to('nodes/y.json'))).to be true
104
+ expect(File.exist?(path_to('roles/y.json'))).to be true
105
+ end
106
+
107
+ it "Upload uploads the y's" do
108
+ run_recipe do
109
+ chef_mirror '' do
110
+ action :upload
111
+ end
112
+ end
113
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
114
+ expect { get('nodes/x') }.not_to raise_error
115
+ expect { get('roles/x') }.not_to raise_error
116
+ expect { get('nodes/y') }.not_to raise_error
117
+ expect { get('roles/y') }.not_to raise_error
118
+ end
119
+
120
+ it "Download with purge grabs the x's and deletes the y's" do
121
+ run_recipe do
122
+ chef_mirror '' do
123
+ purge true
124
+ action :download
125
+ end
126
+ end
127
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
128
+ expect(File.exist?(path_to('nodes/x.json'))).to be true
129
+ expect(File.exist?(path_to('roles/x.json'))).to be true
130
+ end
131
+
132
+ it "Upload with :purge uploads the y's and deletes the x's" do
133
+ run_recipe do
134
+ chef_mirror '*/*.json' do
135
+ purge true
136
+ action :upload
137
+ end
138
+ end
139
+ expect(chef_run).to have_updated('chef_mirror[*/*.json]', :upload)
140
+ expect { get('nodes/y') }.not_to raise_error
141
+ expect { get('roles/y') }.not_to raise_error
142
+ end
143
+ end
144
+ end
53
145
 
146
+ describe "chef_repo_path" do
54
147
  when_the_repository 'has stuff but no chef_repo_path' do
55
148
  file 'repo/nodes/x.json', {}
56
149
  file 'repo/roles/x.json', {}
@@ -153,92 +246,274 @@ describe Chef::Resource::ChefMirror do
153
246
  end
154
247
  end
155
248
 
156
- context 'and has stuff' do
157
- node 'x', {}
158
- role 'x', {}
249
+ describe "cookbook upload, chef_repo_path and versioned_cookbooks" do
250
+ when_the_repository 'has cookbooks in non-versioned format' do
251
+ file 'cookbooks/x-1.0.0/metadata.rb', 'name "x-1.0.0"; version "2.0.0"'
252
+ file 'cookbooks/y-1.0.0/metadata.rb', 'name "y-3.0.0"; version "4.0.0"'
159
253
 
160
- when_the_repository 'is empty' do
161
- it "Download grabs stuff" do
254
+ it "chef_mirror :upload uploads everything" do
162
255
  run_recipe do
163
256
  chef_mirror '' do
164
- action :download
257
+ action :upload
165
258
  end
166
259
  end
167
- expect(chef_run).to have_updated('chef_mirror[]', :download)
168
- expect(File.exist?(path_to('nodes/x.json'))).to be true
169
- expect(File.exist?(path_to('roles/x.json'))).to be true
260
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
261
+ expect { get('cookbooks/x-1.0.0/2.0.0') }.not_to raise_error
262
+ expect { get('cookbooks/y-3.0.0/4.0.0') }.not_to raise_error
170
263
  end
171
264
 
172
- it "Upload uploads nothing" do
173
- run_recipe do
174
- chef_mirror '' do
175
- action :upload
265
+ context 'and Chef::Config.versioned_cookbooks is false' do
266
+ before do
267
+ Chef::Config.versioned_cookbooks false
268
+ end
269
+ it "chef_mirror :upload uploads everything" do
270
+ run_recipe do
271
+ chef_mirror '' do
272
+ action :upload
273
+ end
176
274
  end
275
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
276
+ expect { get('cookbooks/x-1.0.0/2.0.0') }.not_to raise_error
277
+ expect { get('cookbooks/y-3.0.0/4.0.0') }.not_to raise_error
177
278
  end
178
- expect(chef_run).not_to have_updated('chef_mirror[]', :upload)
179
279
  end
180
- end
181
- end
182
280
 
183
- context 'and has nodes and roles named x' do
184
- node 'x', {}
185
- role 'x', {}
281
+ context 'and Chef::Config.chef_repo_path is not set but versioned_cookbooks is false' do
282
+ before do
283
+ Chef::Config.delete(:chef_repo_path)
284
+ Chef::Config.versioned_cookbooks false
285
+ end
186
286
 
187
- when_the_repository 'has nodes and roles named y' do
188
- file 'nodes/y.json', {}
189
- file 'roles/y.json', {}
287
+ it "chef_mirror :upload with chef_repo_path and versioned_cookbooks false uploads cookbooks with name including version" do
288
+ repository_dir = @repository_dir
289
+ run_recipe do
290
+ chef_mirror '' do
291
+ chef_repo_path repository_dir
292
+ versioned_cookbooks false
293
+ action :upload
294
+ end
295
+ end
296
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
297
+ expect { get('cookbooks/x-1.0.0/2.0.0') }.not_to raise_error
298
+ expect { get('cookbooks/y-3.0.0/4.0.0') }.not_to raise_error
299
+ end
300
+ end
301
+ end
190
302
 
191
- it "Download grabs the x's" do
192
- run_recipe do
193
- chef_mirror '' do
194
- action :download
303
+ when_the_repository 'has cookbooks in versioned_cookbook format' do
304
+ file 'cookbooks/x-1.0.0/metadata.rb', 'name "x"; version "1.0.0"'
305
+ file 'cookbooks/x-2.0.0/metadata.rb', 'name "x"; version "2.0.0"'
306
+
307
+ context 'and Chef::Config.versioned_cookbooks is true' do
308
+ before do
309
+ Chef::Config.versioned_cookbooks true
310
+ end
311
+ it "chef_mirror :upload uploads everything" do
312
+ run_recipe do
313
+ chef_mirror '' do
314
+ action :upload
315
+ end
195
316
  end
317
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
318
+ expect { get('cookbooks/x/1.0.0') }.not_to raise_error
319
+ expect { get('cookbooks/x/2.0.0') }.not_to raise_error
196
320
  end
197
- expect(chef_run).to have_updated('chef_mirror[]', :download)
198
- expect(File.exist?(path_to('nodes/x.json'))).to be true
199
- expect(File.exist?(path_to('roles/x.json'))).to be true
200
- expect(File.exist?(path_to('nodes/y.json'))).to be true
201
- expect(File.exist?(path_to('roles/y.json'))).to be true
202
321
  end
203
322
 
204
- it "Upload uploads the y's" do
205
- run_recipe do
206
- chef_mirror '' do
207
- action :upload
323
+ context 'and Chef::Config.chef_repo_path set somewhere else' do
324
+ before do
325
+ Chef::Config.chef_repo_path = '/x/y/z'
326
+ end
327
+ it "chef_mirror :upload with chef_repo_path uploads cookbooks" do
328
+ repository_dir = @repository_dir
329
+ run_recipe do
330
+ chef_mirror '' do
331
+ chef_repo_path repository_dir
332
+ action :upload
333
+ end
208
334
  end
335
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
336
+ expect { get('cookbooks/x/1.0.0') }.not_to raise_error
337
+ expect { get('cookbooks/x/2.0.0') }.not_to raise_error
209
338
  end
210
- expect(chef_run).to have_updated('chef_mirror[]', :upload)
211
- expect { get('nodes/x') }.not_to raise_error
212
- expect { get('roles/x') }.not_to raise_error
213
- expect { get('nodes/y') }.not_to raise_error
214
- expect { get('roles/y') }.not_to raise_error
215
339
  end
216
340
 
217
- it "Download with purge grabs the x's and deletes the y's" do
218
- run_recipe do
219
- chef_mirror '' do
220
- purge true
221
- action :download
341
+ context 'and Chef::Config.chef_repo_path is not set but versioned_cookbooks is false' do
342
+ before do
343
+ Chef::Config.delete(:chef_repo_path)
344
+ Chef::Config.versioned_cookbooks false
345
+ end
346
+
347
+ it "chef_mirror :upload with chef_repo_path uploads cookbooks with name split from version" do
348
+ repository_dir = @repository_dir
349
+ run_recipe do
350
+ chef_mirror '' do
351
+ chef_repo_path repository_dir
352
+ action :upload
353
+ end
222
354
  end
355
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
356
+ expect { get('cookbooks/x/1.0.0') }.not_to raise_error
357
+ expect { get('cookbooks/x/2.0.0') }.not_to raise_error
358
+ end
359
+
360
+ it "chef_mirror :upload with chef_repo_path and versioned_cookbooks uploads cookbooks with name split from version" do
361
+ repository_dir = @repository_dir
362
+ run_recipe do
363
+ chef_mirror '' do
364
+ chef_repo_path repository_dir
365
+ versioned_cookbooks true
366
+ action :upload
367
+ end
368
+ end
369
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
370
+ expect { get('cookbooks/x/1.0.0') }.not_to raise_error
371
+ expect { get('cookbooks/x/2.0.0') }.not_to raise_error
223
372
  end
224
- expect(chef_run).to have_updated('chef_mirror[]', :download)
225
- expect(File.exist?(path_to('nodes/x.json'))).to be true
226
- expect(File.exist?(path_to('roles/x.json'))).to be true
227
373
  end
228
374
 
229
- it "Upload with :purge uploads the y's and deletes the x's" do
230
- run_recipe do
231
- chef_mirror '*/*.json' do
232
- purge true
233
- action :upload
375
+ context 'and Chef::Config.chef_repo_path is not set but versioned_cookbooks is true' do
376
+ before do
377
+ Chef::Config.delete(:chef_repo_path)
378
+ Chef::Config.versioned_cookbooks true
379
+ end
380
+ it "chef_mirror :upload with chef_repo_path uploads cookbooks with name split from version" do
381
+ repository_dir = @repository_dir
382
+ run_recipe do
383
+ chef_mirror '' do
384
+ chef_repo_path repository_dir
385
+ action :upload
386
+ end
234
387
  end
388
+ expect(chef_run).to have_updated('chef_mirror[]', :upload)
389
+ expect { get('cookbooks/x/1.0.0') }.not_to raise_error
390
+ expect { get('cookbooks/x/2.0.0') }.not_to raise_error
235
391
  end
236
- expect(chef_run).to have_updated('chef_mirror[*/*.json]', :upload)
237
- expect { get('nodes/y') }.not_to raise_error
238
- expect { get('roles/y') }.not_to raise_error
239
392
  end
240
393
  end
241
394
  end
242
395
 
396
+ describe 'cookbook download, chef_repo_path, and versioned_cookbooks' do
397
+ context 'when the Chef server has a cookbook with multiple versions' do
398
+ cookbook 'x', '1.0.0', 'metadata.rb' => 'name "x"; version "1.0.0"'
399
+ cookbook 'x', '2.0.0', 'metadata.rb' => 'name "x"; version "2.0.0"'
400
+
401
+ when_the_repository 'is empty' do
402
+ it 'chef_mirror :download downloads the latest version of the cookbook' do
403
+ run_recipe do
404
+ chef_mirror '' do
405
+ action :download
406
+ end
407
+ end
408
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
409
+ expect(File.read(path_to('cookbooks/x/metadata.rb'))).to eq('name "x"; version "2.0.0"')
410
+ end
411
+
412
+ it 'chef_mirror :download with versioned_cookbooks = true downloads all versions of the cookbook' do
413
+ run_recipe do
414
+ chef_mirror '' do
415
+ versioned_cookbooks true
416
+ action :download
417
+ end
418
+ end
419
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
420
+ expect(File.read(path_to('cookbooks/x-1.0.0/metadata.rb'))).to eq('name "x"; version "1.0.0"')
421
+ expect(File.read(path_to('cookbooks/x-2.0.0/metadata.rb'))).to eq('name "x"; version "2.0.0"')
422
+ end
423
+
424
+ context 'and Chef::Config.chef_repo_path is set elsewhere' do
425
+ before do
426
+ Chef::Config.chef_repo_path = '/x/y/z'
427
+ end
428
+
429
+ it 'chef_mirror :download with chef_repo_path downloads all versions of the cookbook' do
430
+ repository_dir = @repository_dir
431
+ run_recipe do
432
+ chef_mirror '' do
433
+ chef_repo_path repository_dir
434
+ action :download
435
+ end
436
+ end
437
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
438
+ expect(File.read(path_to('cookbooks/x-1.0.0/metadata.rb'))).to eq('name "x"; version "1.0.0"')
439
+ expect(File.read(path_to('cookbooks/x-2.0.0/metadata.rb'))).to eq('name "x"; version "2.0.0"')
440
+ end
441
+
442
+ it 'chef_mirror :download with chef_repo_path and versioned_cookbooks = false downloads the latest version of the cookbook' do
443
+ repository_dir = @repository_dir
444
+ run_recipe do
445
+ chef_mirror '' do
446
+ chef_repo_path repository_dir
447
+ versioned_cookbooks false
448
+ action :download
449
+ end
450
+ end
451
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
452
+ expect(File.read(path_to('cookbooks/x/metadata.rb'))).to eq('name "x"; version "2.0.0"')
453
+ end
454
+ end
455
+
456
+ context 'and Chef::Config.versioned_cookbooks is true' do
457
+ before do
458
+ Chef::Config.versioned_cookbooks = true
459
+ end
460
+
461
+ it 'chef_mirror :download downloads all versions of the cookbook' do
462
+ run_recipe do
463
+ chef_mirror '' do
464
+ action :download
465
+ end
466
+ end
467
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
468
+ expect(File.read(path_to('cookbooks/x-1.0.0/metadata.rb'))).to eq('name "x"; version "1.0.0"')
469
+ expect(File.read(path_to('cookbooks/x-2.0.0/metadata.rb'))).to eq('name "x"; version "2.0.0"')
470
+ end
471
+
472
+ it 'chef_mirror :download with versioned_cookbooks = false downloads the latest version of the cookbook' do
473
+ run_recipe do
474
+ chef_mirror '' do
475
+ versioned_cookbooks false
476
+ action :download
477
+ end
478
+ end
479
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
480
+ expect(File.read(path_to('cookbooks/x/metadata.rb'))).to eq('name "x"; version "2.0.0"')
481
+ end
482
+
483
+ context 'and Chef::Config.chef_repo_path is set elsewhere' do
484
+ before do
485
+ Chef::Config.chef_repo_path = '/x/y/z'
486
+ end
487
+
488
+ it 'chef_mirror :download with chef_repo_path downloads all versions of the cookbook' do
489
+ repository_dir = @repository_dir
490
+ run_recipe do
491
+ chef_mirror '' do
492
+ chef_repo_path repository_dir
493
+ action :download
494
+ end
495
+ end
496
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
497
+ expect(File.read(path_to('cookbooks/x-1.0.0/metadata.rb'))).to eq('name "x"; version "1.0.0"')
498
+ expect(File.read(path_to('cookbooks/x-2.0.0/metadata.rb'))).to eq('name "x"; version "2.0.0"')
499
+ end
500
+
501
+ it 'chef_mirror :download with chef_repo_path and versioned_cookbooks = false downloads the latest version of the cookbook' do
502
+ repository_dir = @repository_dir
503
+ run_recipe do
504
+ chef_mirror '' do
505
+ chef_repo_path repository_dir
506
+ versioned_cookbooks false
507
+ action :download
508
+ end
509
+ end
510
+ expect(chef_run).to have_updated('chef_mirror[]', :download)
511
+ expect(File.read(path_to('cookbooks/x/metadata.rb'))).to eq('name "x"; version "2.0.0"')
512
+ end
513
+ end
514
+ end
515
+ end
516
+ end
517
+ end
243
518
  end
244
519
  end