chef-cli 4.0.0 → 5.3.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/chef-cli.gemspec +1 -1
  4. data/lib/chef-cli/command/export.rb +14 -6
  5. data/lib/chef-cli/command/generate.rb +5 -3
  6. data/lib/chef-cli/command/generator_commands/cookbook.rb +15 -2
  7. data/lib/chef-cli/command/generator_commands/recipe.rb +7 -0
  8. data/lib/chef-cli/cookbook_metadata.rb +1 -1
  9. data/lib/chef-cli/exceptions.rb +13 -1
  10. data/lib/chef-cli/helpers.rb +4 -4
  11. data/lib/chef-cli/policyfile/dsl.rb +16 -1
  12. data/lib/chef-cli/policyfile_services/export_repo.rb +9 -13
  13. data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +26 -5
  14. data/lib/chef-cli/skeletons/code_generator/recipes/recipe.rb +11 -3
  15. data/lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb +1 -1
  16. data/lib/chef-cli/skeletons/code_generator/templates/default/recipe.yml.erb +18 -0
  17. data/lib/chef-cli/version.rb +1 -1
  18. data/spec/unit/command/export_spec.rb +18 -1
  19. data/spec/unit/command/generate_spec.rb +7 -0
  20. data/spec/unit/command/generator_commands/cookbook_spec.rb +49 -235
  21. data/spec/unit/command/generator_commands/recipe_spec.rb +34 -0
  22. data/spec/unit/cookbook_metadata_spec.rb +20 -1
  23. data/spec/unit/fixtures/example_cookbook_both_metadata/.gitignore +17 -0
  24. data/spec/unit/fixtures/example_cookbook_both_metadata/.kitchen.yml +16 -0
  25. data/spec/unit/fixtures/example_cookbook_both_metadata/Berksfile +3 -0
  26. data/spec/unit/fixtures/example_cookbook_both_metadata/README.md +4 -0
  27. data/spec/unit/fixtures/example_cookbook_both_metadata/chefignore +96 -0
  28. data/spec/unit/fixtures/example_cookbook_both_metadata/metadata.json +5 -0
  29. data/spec/unit/fixtures/example_cookbook_both_metadata/metadata.rb +9 -0
  30. data/spec/unit/fixtures/example_cookbook_both_metadata/recipes/default.rb +8 -0
  31. data/spec/unit/helpers_spec.rb +111 -0
  32. data/spec/unit/policyfile_evaluation_spec.rb +67 -1
  33. data/spec/unit/policyfile_services/export_repo_spec.rb +51 -2
  34. metadata +22 -14
  35. data/lib/chef-cli/command/generator_commands/build_cookbook.rb +0 -126
  36. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md +0 -146
  37. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +0 -21
  38. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +0 -8
  39. data/lib/chef-cli/skeletons/code_generator/files/default/delivery-config.json +0 -17
  40. data/lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb +0 -175
  41. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +0 -7
  42. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +0 -10
  43. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +0 -9
  44. data/spec/unit/command/generator_commands/build_cookbook_spec.rb +0 -377
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "4.0.0".freeze
19
+ VERSION = "5.3.0".freeze
20
20
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -84,6 +84,10 @@ describe ChefCLI::Command::Export do
84
84
  expect(command.export_service.policyfile_filename).to eq(File.expand_path("Policyfile.rb"))
85
85
  end
86
86
 
87
+ it "uses the default policy_group name" do
88
+ expect(command.export_service.policy_group).to eq("local")
89
+ end
90
+
87
91
  end
88
92
 
89
93
  context "when a Policyfile relative path and export path are given" do
@@ -98,6 +102,19 @@ describe ChefCLI::Command::Export do
98
102
  expect(command.export_service.policyfile_filename).to eq(File.expand_path("CustomNamedPolicy.rb"))
99
103
  end
100
104
  end
105
+
106
+ context "when a policy_group is given" do
107
+
108
+ let(:params) { [ "path/to/export", "--policy_group", "production" ] }
109
+
110
+ it "configures the export service with the export path" do
111
+ expect(command.export_service.export_dir).to eq(File.expand_path("path/to/export"))
112
+ end
113
+
114
+ it "configures the export service with the policyfile relative path" do
115
+ expect(command.export_service.policy_group).to eq("production")
116
+ end
117
+ end
101
118
  end
102
119
 
103
120
  describe "running the export" do
@@ -138,5 +138,12 @@ describe ChefCLI::Command::Generate do
138
138
 
139
139
  end
140
140
 
141
+ describe "When build-cookbookis given as subcommand" do
142
+ it "shows deprecation warning when" do
143
+ result = generate.run(%w{build-cookbook example})
144
+ expect(result).to eq(1)
145
+ end
146
+ end
147
+
141
148
  end
142
149
  end
@@ -189,241 +189,6 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
189
189
  end
190
190
  end
191
191
 
192
- context "when passed workflow option" do
193
-
194
- context "generates a workflow (delivery) cookbook" do
195
-
196
- let(:argv) { %w{new_cookbook --workflow} }
197
-
198
- let(:dot_delivery) { File.join(tempdir, "new_cookbook", ".delivery") }
199
-
200
- before do
201
- Dir.chdir(tempdir) do
202
- allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
203
- expect(cookbook_generator.run).to eq(0)
204
- end
205
- end
206
-
207
- describe ".delivery/project.toml" do
208
-
209
- let(:file) { File.join(tempdir, "new_cookbook", ".delivery", "project.toml") }
210
-
211
- let(:expected_content) do
212
- <<~PROJECT_DOT_TOML
213
- # Delivery for Local Phases Execution
214
- #
215
- # This file allows you to execute test phases locally on a workstation or
216
- # in a CI pipeline. The delivery-cli will read this file and execute the
217
- # command(s) that are configured for each phase. You can customize them
218
- # by just modifying the phase key on this file.
219
- #
220
- # By default these phases are configured for Cookbook Workflow only
221
- #
222
-
223
- [local_phases]
224
- unit = "chef exec rspec spec/"
225
- lint = "chef exec cookstyle"
226
- # foodcritic has been deprecated in favor of cookstyle so we skip the syntax
227
- # phase now.
228
- syntax = "echo skipping syntax phase. Use lint phase instead."
229
- provision = "chef exec kitchen create"
230
- deploy = "chef exec kitchen converge"
231
- smoke = "chef exec kitchen verify"
232
- # The functional phase is optional, you can define it by uncommenting
233
- # the line below and running the command: `delivery local functional`
234
- # functional = ""
235
- cleanup = "chef exec kitchen destroy"
236
-
237
- # Remote project.toml file
238
- #
239
- # Instead of the local phases above, you may specify a remote URI location for
240
- # the `project.toml` file. This is useful for teams that wish to centrally
241
- # manage the behavior of the `delivery local` command across many different
242
- # projects.
243
- #
244
- # remote_file = "https://url/project.toml"
245
- PROJECT_DOT_TOML
246
- end
247
-
248
- it "exists with default config for Cookbook Workflow" do
249
- expect(IO.read(file)).to eq(expected_content)
250
- end
251
-
252
- end
253
-
254
- describe ".delivery/config.json" do
255
-
256
- let(:file) { File.join(tempdir, "new_cookbook", ".delivery", "config.json") }
257
-
258
- let(:expected_content) do
259
- <<~CONFIG_DOT_JSON
260
- {
261
- "version": "2",
262
- "build_cookbook": {
263
- "name": "build_cookbook",
264
- "path": ".delivery/build_cookbook"
265
- },
266
- "delivery-truck": {
267
- "lint": {
268
- "enable_cookstyle": true
269
- }
270
- },
271
- "skip_phases": [],
272
- "job_dispatch": {
273
- "version": "v2"
274
- },
275
- "dependencies": []
276
- }
277
- CONFIG_DOT_JSON
278
- end
279
-
280
- it "configures delivery to use a local build cookbook" do
281
- expect(IO.read(file)).to eq(expected_content)
282
- end
283
-
284
- end
285
-
286
- describe "build cookbook recipes" do
287
-
288
- let(:file) do
289
- File.join(dot_delivery, "build_cookbook", "recipes", "publish.rb")
290
- end
291
-
292
- let(:expected_content) do
293
- <<~CONFIG_DOT_JSON
294
- #
295
- # Cookbook:: build_cookbook
296
- # Recipe:: publish
297
- #
298
- # Copyright:: #{DateTime.now.year}, The Authors, All Rights Reserved.
299
-
300
- include_recipe 'delivery-truck::publish'
301
- CONFIG_DOT_JSON
302
- end
303
-
304
- it "delegates functionality to delivery-truck" do
305
- expect(IO.read(file)).to include(expected_content)
306
- end
307
-
308
- end
309
-
310
- describe "build cookbook Berksfile" do
311
-
312
- let(:file) do
313
- File.join(dot_delivery, "build_cookbook", "Berksfile")
314
- end
315
-
316
- let(:expected_content) do
317
- <<~CONFIG_DOT_JSON
318
- source 'https://supermarket.chef.io'
319
-
320
- metadata
321
-
322
- group :workflow do
323
- cookbook 'test', path: './test/fixtures/cookbooks/test'
324
- end
325
- CONFIG_DOT_JSON
326
- end
327
-
328
- it "sets the sources for delivery library cookbooks to github" do
329
- expect(IO.read(file)).to include(expected_content)
330
- end
331
-
332
- end
333
- end
334
-
335
- context "when no delivery CLI configuration is present" do
336
-
337
- let(:argv) { %w{new_cookbook --workflow} }
338
-
339
- it "detects no delivery config" do
340
- Dir.chdir(tempdir) do
341
- expect(cookbook_generator.have_delivery_config?).to be(false)
342
- end
343
- end
344
-
345
- it "emits concise output" do
346
- Dir.chdir(tempdir) do
347
- allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
348
- expect(cookbook_generator.run).to eq(0)
349
- end
350
-
351
- expected = <<~OUTPUT
352
- Generating cookbook new_cookbook
353
- - Ensuring correct cookbook content
354
- - Committing cookbook files to git
355
- - Ensuring delivery CLI configuration
356
- - Ensuring correct Workflow (Delivery) build cookbook content
357
- - Adding delivery configuration to feature branch
358
- - Adding build cookbook to feature branch
359
- - Merging delivery content feature branch to master
360
-
361
- #{non_delivery_breadcrumb}
362
- OUTPUT
363
-
364
- actual = stdout_io.string
365
-
366
- # the formatter will add escape sequences to turn off any colors
367
- actual.gsub!("\e[0m", "")
368
- expect(actual).to eq(expected)
369
- end
370
- end
371
-
372
- context "when a delivery CLI config is present" do
373
-
374
- # Setup a situation like this:
375
- # there is a dir for the delivery organization with the
376
- # `.delivery/cli.toml` in it. Inside that is another dir (maybe IRL this
377
- # would be "cookbooks"), then we create the cookbook inside that.
378
-
379
- let(:argv) { %w{new_cookbook --workflow} }
380
-
381
- let(:tempdir_subdir) { File.join(tempdir, "subdirectory") }
382
-
383
- let(:dot_delivery_dir) { File.join(tempdir, ".delivery") }
384
-
385
- let(:dot_delivery_cli_toml) { File.join(dot_delivery_dir, "cli.toml") }
386
-
387
- before do
388
- Dir.mkdir(tempdir_subdir)
389
- Dir.mkdir(dot_delivery_dir)
390
- FileUtils.touch(dot_delivery_cli_toml)
391
- end
392
-
393
- it "detects the delivery config" do
394
- Dir.chdir(tempdir_subdir) do
395
- expect(cookbook_generator.have_delivery_config?).to be(true)
396
- end
397
- end
398
-
399
- it "emits concise output" do
400
- Dir.chdir(tempdir) do
401
- allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
402
- expect(cookbook_generator.run).to eq(0)
403
- end
404
-
405
- expected = <<~OUTPUT
406
- Generating cookbook new_cookbook
407
- - Ensuring correct cookbook content
408
- - Committing cookbook files to git
409
- - Ensuring delivery CLI configuration
410
- - Ensuring correct Workflow (Delivery) build cookbook content
411
- - Adding delivery configuration to feature branch
412
- - Adding build cookbook to feature branch
413
- - Merging delivery content feature branch to master
414
-
415
- Your cookbook is ready. To setup the pipeline, type `cd new_cookbook`, then run `delivery init`
416
- OUTPUT
417
-
418
- actual = stdout_io.string
419
-
420
- # the formatter will add escape sequences to turn off any colors
421
- actual.gsub!("\e[0m", "")
422
- expect(actual).to eq(expected)
423
- end
424
- end
425
- end
426
-
427
192
  context "when given the specs flag" do
428
193
 
429
194
  let(:argv) { %w{ new_cookbook --specs } }
@@ -655,6 +420,55 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
655
420
 
656
421
  end
657
422
 
423
+ context "when YAML recipe flag is passed" do
424
+
425
+ let(:argv) { %w{new_cookbook --yaml} }
426
+
427
+ describe "recipes/default.yml" do
428
+ let(:file) { File.join(tempdir, "new_cookbook", "recipes", "default.yml") }
429
+
430
+ let(:expected_content_header) do
431
+ <<~DEFAULT_YML_HEADER
432
+ #
433
+ # Cookbook:: new_cookbook
434
+ # Recipe:: default
435
+ #
436
+ DEFAULT_YML_HEADER
437
+ end
438
+
439
+ let(:expected_content) do
440
+ <<~DEFAULT_YML_CONTENT
441
+ ---
442
+ resources:
443
+ # Example Syntax
444
+ # Additional snippets are available using the Chef Infra Extension for Visual Studio Code
445
+ # - type: file
446
+ # name: '/path/to/file'
447
+ # content: 'content'
448
+ # owner: 'root'
449
+ # group: 'root'
450
+ # mode: '0755'
451
+ # action:
452
+ # - create
453
+ DEFAULT_YML_CONTENT
454
+ end
455
+
456
+ before do
457
+ Dir.chdir(tempdir) do
458
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
459
+ expect(cookbook_generator.run).to eq(0)
460
+ end
461
+ end
462
+
463
+ it "has a default.yml file with template contents" do
464
+ expect(IO.read(file)).to match(expected_content_header)
465
+ expect(IO.read(file)).to match(expected_content)
466
+ end
467
+
468
+ end
469
+
470
+ end
471
+
658
472
  context "when configured for Berkshelf" do
659
473
 
660
474
  let(:argv) { %w{new_cookbook --berks} }
@@ -35,4 +35,38 @@ describe ChefCLI::Command::GeneratorCommands::Recipe do
35
35
 
36
36
  end
37
37
 
38
+ context "when YAML recipe flag is passed" do
39
+
40
+ let(:argv) { %w{some_recipe --yaml} }
41
+ let(:expected_cookbook_root) { tempdir }
42
+ let(:cookbook_name) { "example_cookbook" }
43
+ let(:cookbook_path) { File.join(tempdir, cookbook_name) }
44
+
45
+ let(:generator_name) { "recipe" }
46
+ let(:generated_files) do
47
+ [ "recipes/some_recipe.yml",
48
+ "spec/spec_helper.rb",
49
+ "spec/unit/recipes/some_recipe_spec.rb",
50
+ "test/integration/default/some_recipe_test.rb",
51
+ ]
52
+ end
53
+ let(:new_file_name) { "some_recipe" }
54
+
55
+ before do
56
+ FileUtils.cp_r(File.join(fixtures_path, "example_cookbook"), tempdir)
57
+ end
58
+
59
+ it "creates a new recipe" do
60
+ Dir.chdir(cookbook_path) do
61
+ allow(recipe_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
62
+ recipe_generator.run
63
+ end
64
+
65
+ generated_files.each do |expected_file|
66
+ expect(File).to exist(File.join(cookbook_path, expected_file))
67
+ end
68
+ end
69
+
70
+ end
71
+
38
72
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,6 +80,25 @@ describe ChefCLI::CookbookMetadata do
80
80
 
81
81
  end
82
82
 
83
+ context "and the cookbook has both a metadata.json and an (invalid) metadata.rb" do
84
+
85
+ let(:cookbook_root) { File.join(fixtures_path, "example_cookbook_both_metadata") }
86
+
87
+ it "has a name" do
88
+ expect(cookbook.name).to eq("example_cookbook")
89
+ expect(cookbook.cookbook_name).to eq("example_cookbook")
90
+ end
91
+
92
+ it "has a version" do
93
+ expect(cookbook.version).to eq("0.1.0")
94
+ end
95
+
96
+ it "has a map of dependencies" do
97
+ expect(cookbook.dependencies).to eq({})
98
+ end
99
+
100
+ end
101
+
83
102
  context "and the cookbook has no metadata" do
84
103
 
85
104
  let(:cookbook_root) { File.join(fixtures_path, "example_cookbook_no_metadata") }
@@ -0,0 +1,17 @@
1
+ .vagrant
2
+ Berksfile.lock
3
+ *~
4
+ *#
5
+ .#*
6
+ \#*#
7
+ .*.sw[a-z]
8
+ *.un~
9
+ /cookbooks
10
+
11
+ # Bundler
12
+ Gemfile.lock
13
+ bin/*
14
+ .bundle/*
15
+
16
+ .kitchen/
17
+ .kitchen.local.yml
@@ -0,0 +1,16 @@
1
+ ---
2
+ driver:
3
+ name: vagrant
4
+
5
+ provisioner:
6
+ name: chef_solo
7
+
8
+ platforms:
9
+ - name: ubuntu-12.04
10
+ - name: centos-6.4
11
+
12
+ suites:
13
+ - name: default
14
+ run_list:
15
+ - recipe[bar::default]
16
+ attributes: