chef-cli 5.5.5 → 5.5.6

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
  SHA256:
3
- metadata.gz: 1716bb7f053b4836d2e2a2fc6e309ca583a059d537606361dabf0c8b40e7cc98
4
- data.tar.gz: 75e3112b7e47f3bd96aa84727e76ec65d80c3ef977321c5132f0bebef962e201
3
+ metadata.gz: 38c929fa9c8587e5030c03d78715e5b483326e958a104ac4403f68779a8cdfd3
4
+ data.tar.gz: '07841d7b155b98b52cdb483c0e041ee8e59c34353295aa393c114db19af321b5'
5
5
  SHA512:
6
- metadata.gz: c10e74154812fc6db2b0b81f8bfa48d4e0e284824b8c3beb24e19518be85d909d5ca4f6f1c8263e09b019f6469479a071b78a09ee15b1e15566c7234d580708e
7
- data.tar.gz: f2684d4b818592bbd2c1575aa46105292a3903c2f93d3b68b60f260001474ae52b26b593fdaf9fa73113cf9e3db9397732dccbb724b605f9b50e21f6f744044b
6
+ metadata.gz: f7a6a2dfdbe694ed6897733c16af217c344a1d9163354325163172b21a9c8f5e00e26586774bd1f864b4b226a7fad72901aad776035a4d023f6432aae128242a
7
+ data.tar.gz: 659dbe818405db54685e7356156b6db39b671e7de86bf40fd3282ef497d68173a7042f3091cf7c60306d30639c7260349bcdab6e8ae1d5c28cd5ddadf9b5dc54
@@ -86,7 +86,7 @@ module ChefCLI
86
86
  option :pipeline,
87
87
  long: "--pipeline PIPELINE",
88
88
  description: "REMOVED: #{ChefCLI::Dist::WORKFLOW} is EOL. This option has been removed.",
89
- default: "master"
89
+ default: nil
90
90
 
91
91
  options.merge!(SharedGeneratorOptions.options)
92
92
 
@@ -131,20 +131,6 @@ else
131
131
  end
132
132
  end
133
133
 
134
- # the same will be done below if workflow was enabled so avoid double work and skip this
135
- unless context.enable_workflow
136
- directory "#{cookbook_dir}/.delivery"
137
-
138
- template "#{cookbook_dir}/.delivery/project.toml" do
139
- variables(
140
- specs: context.specs
141
- )
142
- source 'delivery-project.toml.erb'
143
- helpers(ChefCLI::Generator::TemplateHelper)
144
- action :create_if_missing
145
- end
146
- end
147
-
148
134
  # git
149
135
  if context.have_git
150
136
  unless context.skip_git_init
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "5.5.5".freeze
19
+ VERSION = "5.5.6".freeze
20
20
  end
@@ -66,6 +66,23 @@ shared_examples_for "custom generator cookbook" do
66
66
  end
67
67
  end
68
68
 
69
+ context "with an invalid generator-cookbook path" do
70
+
71
+ it "fails with an informative error" do
72
+ Dir.chdir(tempdir) do
73
+ allow(code_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
74
+ allow(code_generator).to receive(:stderr).and_return(stderr_io)
75
+ expect(code_generator.run).to eq(1)
76
+ end
77
+
78
+ cookbook_path = File.dirname(generator_cookbook_path)
79
+ expected_msg = %Q{ERROR: Could not find cookbook(s) to satisfy run list ["recipe[a_generator_cookbook::#{generator_name}]"] in #{cookbook_path}}
80
+
81
+ expect(stderr_io.string).to include(expected_msg)
82
+ end
83
+
84
+ end
85
+
69
86
  context "with a generator-cookbook path to a specific cookbook" do
70
87
 
71
88
  let(:metadata_file) { File.join(generator_cookbook_path, "metadata.rb") }
@@ -88,5 +105,32 @@ shared_examples_for "custom generator cookbook" do
88
105
  end
89
106
 
90
107
  end
108
+
109
+ context "with a generator-cookbook path to a directory containing a 'code_generator' cookbook" do
110
+
111
+ before do
112
+ FileUtils.mkdir_p(generator_cookbook_path)
113
+ FileUtils.cp_r(default_generator_cookbook_path, generator_cookbook_path)
114
+
115
+ allow(code_generator).to receive(:stderr).and_return(stderr_io)
116
+ end
117
+
118
+ it "creates the new_files (and warns about deprecated usage)" do
119
+ allow(code_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
120
+
121
+ Dir.chdir(tempdir) do
122
+ code_generator.run
123
+ end
124
+ generated_files = Dir.glob("#{tempdir}/#{generator_arg}/**/*", File::FNM_DOTMATCH)
125
+ expected_cookbook_files.each do |expected_file|
126
+ expect(generated_files).to include(expected_file)
127
+ end
128
+
129
+ code_generator_path = File.join(generator_cookbook_path, "code_generator")
130
+ warning_message = "WARN: Please configure the generator cookbook by giving the full path to the desired cookbook (like '#{code_generator_path}')"
131
+
132
+ expect(stderr_io.string).to include(warning_message)
133
+ end
134
+ end
91
135
  end
92
136
  end
@@ -151,7 +151,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
151
151
  end
152
152
 
153
153
  it "warns if a hyphenated cookbook name is passed" do
154
- expect(with_argv(%w{my-cookbook}).run).to eq(1)
154
+ expect(with_argv(%w{my-cookbook}).run).to eq(0)
155
155
  message = "Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information."
156
156
  expect(stdout_io.string).to include(message)
157
157
  end
@@ -176,6 +176,18 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
176
176
  expect(generator_context.specs).to be(false)
177
177
  end
178
178
 
179
+ it "creates a new cookbook" do
180
+
181
+ Dir.chdir(tempdir) do
182
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
183
+ expect(cookbook_generator.run).to eq(0)
184
+ end
185
+ generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
186
+ expected_cookbook_files.each do |expected_file|
187
+ expect(generated_files).to include(expected_file)
188
+ end
189
+ end
190
+
179
191
  context "when given the specs flag" do
180
192
 
181
193
  let(:argv) { %w{ new_cookbook --specs } }
@@ -185,6 +197,17 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
185
197
  cookbook_generator.setup_context
186
198
  expect(generator_context.specs).to be(true)
187
199
  end
200
+
201
+ it "creates a new cookbook" do
202
+ Dir.chdir(tempdir) do
203
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
204
+ expect(cookbook_generator.run).to eq(0)
205
+ end
206
+ generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
207
+ expected_cookbook_files_specs.each do |expected_file|
208
+ expect(generated_files).to include(expected_file)
209
+ end
210
+ end
188
211
  end
189
212
 
190
213
  context "when given the verbose flag" do
@@ -196,19 +219,34 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
196
219
  cookbook_generator.setup_context
197
220
  expect(generator_context.verbose).to be(true)
198
221
  end
222
+
223
+ it "emits verbose output" do
224
+ Dir.chdir(tempdir) do
225
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
226
+ expect(cookbook_generator.run).to eq(0)
227
+ end
228
+
229
+ # The normal chef formatter puts a heading for each recipe like this.
230
+ # Full output is large and subject to change with minor changes in the
231
+ # generator cookbook, so we just look for this line
232
+ expected_line = "Recipe: code_generator::cookbook"
233
+
234
+ actual = stdout_io.string
235
+
236
+ expect(actual).to include(expected_line)
237
+ end
199
238
  end
200
239
 
201
240
  shared_examples_for "a generated file" do |context_var|
202
241
  before do
203
242
  Dir.chdir(tempdir) do
204
243
  allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
205
- expect(cookbook_generator.run).to eq(1)
244
+ expect(cookbook_generator.run).to eq(0)
206
245
  end
207
246
  end
208
247
 
209
- it "should not generate a file" do
210
- expect(File.directory?(file)).to be false
211
- expect(File).not_to exist(file)
248
+ it "should contain #{context_var} from the generator context" do
249
+ expect(File.read(file)).to match line
212
250
  end
213
251
  end
214
252
 
@@ -228,6 +266,297 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
228
266
  end
229
267
  end
230
268
 
269
+ # This shared example group requires a let binding for
270
+ # `expected_kitchen_yml_content`
271
+ shared_examples_for "kitchen_yml_and_integration_tests" do
272
+
273
+ describe "Generating Test Kitchen and integration testing files" do
274
+
275
+ describe "generating kitchen config" do
276
+
277
+ before do
278
+ Dir.chdir(tempdir) do
279
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
280
+ expect(cookbook_generator.run).to eq(0)
281
+ end
282
+ end
283
+
284
+ let(:file) { File.join(tempdir, "new_cookbook", "kitchen.yml") }
285
+
286
+ it "creates a kitchen.yml with the expected content" do
287
+ expect(IO.read(file)).to eq(expected_kitchen_yml_content)
288
+ end
289
+
290
+ end
291
+
292
+ describe "test/integration/default/default_test.rb" do
293
+ let(:file) { File.join(tempdir, "new_cookbook", "test", "integration", "default", "default_test.rb") }
294
+
295
+ include_examples "a generated file", :cookbook_name do
296
+ let(:line) { "describe port" }
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ # This shared example group requires you to define a let binding for
303
+ # `expected_chefspec_spec_helper_content`
304
+ shared_examples_for "chefspec_spec_helper_file" do
305
+
306
+ describe "Generating ChefSpec files" do
307
+
308
+ before do
309
+ Dir.chdir(tempdir) do
310
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
311
+ expect(cookbook_generator.run).to eq(0)
312
+ end
313
+ end
314
+
315
+ let(:file) { File.join(tempdir, "new_cookbook", "spec", "spec_helper.rb") }
316
+
317
+ it "creates a spec/spec_helper.rb for ChefSpec with the expected content" do
318
+ expect(IO.read(file)).to eq(expected_chefspec_spec_helper_content)
319
+ end
320
+
321
+ end
322
+
323
+ end
324
+
325
+ context "when configured for Policyfiles" do
326
+
327
+ let(:argv) { %w{new_cookbook --policy} }
328
+
329
+ describe "Policyfile.rb" do
330
+
331
+ let(:file) { File.join(tempdir, "new_cookbook", "Policyfile.rb") }
332
+
333
+ let(:expected_content) do
334
+ <<~POLICYFILE_RB
335
+ # Policyfile.rb - Describe how you want Chef Infra Client to build your system.
336
+ #
337
+ # For more information on the Policyfile feature, visit
338
+ # https://docs.chef.io/policyfile/
339
+
340
+ # A name that describes what the system you're building with Chef does.
341
+ name 'new_cookbook'
342
+
343
+ # Where to find external cookbooks:
344
+ default_source :supermarket
345
+
346
+ # run_list: chef-client will run these recipes in the order specified.
347
+ run_list 'new_cookbook::default'
348
+
349
+ # Specify a custom source for a single cookbook:
350
+ cookbook 'new_cookbook', path: '.'
351
+ POLICYFILE_RB
352
+ end
353
+
354
+ before do
355
+ Dir.chdir(tempdir) do
356
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
357
+ expect(cookbook_generator.run).to eq(0)
358
+ end
359
+ end
360
+
361
+ it "has a run_list and cookbook path that will work out of the box" do
362
+ expect(IO.read(file)).to eq(expected_content)
363
+ end
364
+
365
+ end
366
+
367
+ include_examples "kitchen_yml_and_integration_tests" do
368
+
369
+ let(:expected_kitchen_yml_content) do
370
+ <<~KITCHEN_YML
371
+ ---
372
+ driver:
373
+ name: vagrant
374
+
375
+ ## The forwarded_port port feature lets you connect to ports on the VM guest
376
+ ## via localhost on the host.
377
+ ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports
378
+
379
+ # network:
380
+ # - ["forwarded_port", {guest: 80, host: 8080}]
381
+
382
+ provisioner:
383
+ name: chef_zero
384
+
385
+ ## product_name and product_version specifies a specific Chef product and version to install.
386
+ ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/
387
+ # product_name: chef
388
+ # product_version: 17
389
+
390
+ verifier:
391
+ name: inspec
392
+
393
+ platforms:
394
+ - name: ubuntu-20.04
395
+ - name: centos-8
396
+
397
+ suites:
398
+ - name: default
399
+ verifier:
400
+ inspec_tests:
401
+ - test/integration/default
402
+ KITCHEN_YML
403
+ end
404
+
405
+ end
406
+
407
+ include_examples "chefspec_spec_helper_file" do
408
+ let(:argv) { %w{ new_cookbook --policy --specs } }
409
+
410
+ let(:expected_chefspec_spec_helper_content) do
411
+ <<~SPEC_HELPER
412
+ require 'chefspec'
413
+ require 'chefspec/policyfile'
414
+ SPEC_HELPER
415
+ end
416
+
417
+ end
418
+
419
+ end
420
+
421
+ context "when YAML recipe flag is passed" do
422
+
423
+ let(:argv) { %w{new_cookbook --yaml} }
424
+
425
+ describe "recipes/default.yml" do
426
+ let(:file) { File.join(tempdir, "new_cookbook", "recipes", "default.yml") }
427
+
428
+ let(:expected_content_header) do
429
+ <<~DEFAULT_YML_HEADER
430
+ #
431
+ # Cookbook:: new_cookbook
432
+ # Recipe:: default
433
+ #
434
+ DEFAULT_YML_HEADER
435
+ end
436
+
437
+ let(:expected_content) do
438
+ <<~DEFAULT_YML_CONTENT
439
+ ---
440
+ resources:
441
+ # Example Syntax
442
+ # Additional snippets are available using the Chef Infra Extension for Visual Studio Code
443
+ # - type: file
444
+ # name: '/path/to/file'
445
+ # content: 'content'
446
+ # owner: 'root'
447
+ # group: 'root'
448
+ # mode: '0755'
449
+ # action:
450
+ # - create
451
+ DEFAULT_YML_CONTENT
452
+ end
453
+
454
+ before do
455
+ Dir.chdir(tempdir) do
456
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
457
+ expect(cookbook_generator.run).to eq(0)
458
+ end
459
+ end
460
+
461
+ it "has a default.yml file with template contents" do
462
+ expect(IO.read(file)).to match(expected_content_header)
463
+ expect(IO.read(file)).to match(expected_content)
464
+ end
465
+
466
+ end
467
+
468
+ end
469
+
470
+ context "when configured for Berkshelf" do
471
+
472
+ let(:argv) { %w{new_cookbook --berks} }
473
+
474
+ describe "Berksfile" do
475
+
476
+ let(:file) { File.join(tempdir, "new_cookbook", "Berksfile") }
477
+
478
+ let(:expected_content) do
479
+ <<~POLICYFILE_RB
480
+ source 'https://supermarket.chef.io'
481
+
482
+ metadata
483
+ POLICYFILE_RB
484
+ end
485
+
486
+ before do
487
+ Dir.chdir(tempdir) do
488
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
489
+ expect(cookbook_generator.run).to eq(0)
490
+ end
491
+ end
492
+
493
+ it "pulls deps from metadata" do
494
+ expect(IO.read(file)).to eq(expected_content)
495
+ end
496
+
497
+ end
498
+
499
+ include_examples "kitchen_yml_and_integration_tests" do
500
+
501
+ let(:expected_kitchen_yml_content) do
502
+ <<~KITCHEN_YML
503
+ ---
504
+ driver:
505
+ name: vagrant
506
+
507
+ ## The forwarded_port port feature lets you connect to ports on the VM guest via
508
+ ## localhost on the host.
509
+ ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports
510
+
511
+ # network:
512
+ # - ["forwarded_port", {guest: 80, host: 8080}]
513
+
514
+ provisioner:
515
+ name: chef_zero
516
+ # You may wish to disable always updating cookbooks in CI or other testing environments.
517
+ # For example:
518
+ # always_update_cookbooks: <%= !ENV['CI'] %>
519
+ always_update_cookbooks: true
520
+
521
+ ## product_name and product_version specifies a specific Chef product and version to install.
522
+ ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/
523
+ # product_name: chef
524
+ # product_version: 17
525
+
526
+ verifier:
527
+ name: inspec
528
+
529
+ platforms:
530
+ - name: ubuntu-20.04
531
+ - name: centos-8
532
+
533
+ suites:
534
+ - name: default
535
+ run_list:
536
+ - recipe[new_cookbook::default]
537
+ verifier:
538
+ inspec_tests:
539
+ - test/integration/default
540
+ attributes:
541
+ KITCHEN_YML
542
+ end
543
+
544
+ end
545
+
546
+ include_examples "chefspec_spec_helper_file" do
547
+ let(:argv) { %w{ new_cookbook --berks --specs } }
548
+
549
+ let(:expected_chefspec_spec_helper_content) do
550
+ <<~SPEC_HELPER
551
+ require 'chefspec'
552
+ require 'chefspec/berkshelf'
553
+ SPEC_HELPER
554
+ end
555
+
556
+ end
557
+
558
+ end
559
+
231
560
  describe "metadata.rb" do
232
561
  let(:file) { File.join(tempdir, "new_cookbook", "metadata.rb") }
233
562
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.5
4
+ version: 5.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli