chef-cli 5.0.1 → 5.3.1

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +15 -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 +14 -1
  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/policyfile/dsl.rb +16 -1
  11. data/lib/chef-cli/policyfile_services/export_repo.rb +9 -13
  12. data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +12 -4
  13. data/lib/chef-cli/skeletons/code_generator/recipes/recipe.rb +11 -3
  14. data/lib/chef-cli/skeletons/code_generator/templates/default/recipe.yml.erb +18 -0
  15. data/lib/chef-cli/version.rb +1 -1
  16. data/spec/unit/command/export_spec.rb +18 -1
  17. data/spec/unit/command/generate_spec.rb +7 -0
  18. data/spec/unit/command/generator_commands/cookbook_spec.rb +49 -195
  19. data/spec/unit/command/generator_commands/recipe_spec.rb +34 -0
  20. data/spec/unit/cookbook_metadata_spec.rb +20 -1
  21. data/spec/unit/fixtures/example_cookbook_both_metadata/.gitignore +17 -0
  22. data/spec/unit/fixtures/example_cookbook_both_metadata/.kitchen.yml +16 -0
  23. data/spec/unit/fixtures/example_cookbook_both_metadata/Berksfile +3 -0
  24. data/spec/unit/fixtures/example_cookbook_both_metadata/README.md +4 -0
  25. data/spec/unit/fixtures/example_cookbook_both_metadata/chefignore +96 -0
  26. data/spec/unit/fixtures/example_cookbook_both_metadata/metadata.json +5 -0
  27. data/spec/unit/fixtures/example_cookbook_both_metadata/metadata.rb +9 -0
  28. data/spec/unit/fixtures/example_cookbook_both_metadata/recipes/default.rb +8 -0
  29. data/spec/unit/policyfile_evaluation_spec.rb +67 -1
  30. data/spec/unit/policyfile_services/export_repo_spec.rb +51 -2
  31. metadata +21 -15
  32. data/lib/chef-cli/command/generator_commands/build_cookbook.rb +0 -126
  33. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md +0 -146
  34. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +0 -21
  35. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +0 -8
  36. data/lib/chef-cli/skeletons/code_generator/files/default/delivery-config.json +0 -17
  37. data/lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb +0 -175
  38. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +0 -7
  39. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +0 -10
  40. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +0 -9
  41. data/spec/unit/command/generator_commands/build_cookbook_spec.rb +0 -377
@@ -189,201 +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 "when passed without --specs subcommand .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 = "echo skipping unit phase."
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 "when passed with --specs subcommand .delivery/project.toml" do
255
-
256
- let(:argv) { %w{new_cookbook --workflow --specs} }
257
-
258
- let(:file) { File.join(tempdir, "new_cookbook", ".delivery", "project.toml") }
259
-
260
- let(:expected_content) do
261
- <<~PROJECT_DOT_TOML
262
- # Delivery for Local Phases Execution
263
- #
264
- # This file allows you to execute test phases locally on a workstation or
265
- # in a CI pipeline. The delivery-cli will read this file and execute the
266
- # command(s) that are configured for each phase. You can customize them
267
- # by just modifying the phase key on this file.
268
- #
269
- # By default these phases are configured for Cookbook Workflow only
270
- #
271
-
272
- [local_phases]
273
- unit = "chef exec rspec spec/"
274
- lint = "chef exec cookstyle"
275
- # foodcritic has been deprecated in favor of cookstyle so we skip the syntax
276
- # phase now.
277
- syntax = "echo skipping syntax phase. Use lint phase instead."
278
- provision = "chef exec kitchen create"
279
- deploy = "chef exec kitchen converge"
280
- smoke = "chef exec kitchen verify"
281
- # The functional phase is optional, you can define it by uncommenting
282
- # the line below and running the command: `delivery local functional`
283
- # functional = ""
284
- cleanup = "chef exec kitchen destroy"
285
-
286
- # Remote project.toml file
287
- #
288
- # Instead of the local phases above, you may specify a remote URI location for
289
- # the `project.toml` file. This is useful for teams that wish to centrally
290
- # manage the behavior of the `delivery local` command across many different
291
- # projects.
292
- #
293
- # remote_file = "https://url/project.toml"
294
- PROJECT_DOT_TOML
295
- end
296
-
297
- it "exists with default config for Cookbook Workflow" do
298
- expect(IO.read(file)).to eq(expected_content)
299
- end
300
-
301
- end
302
-
303
- end
304
-
305
- context "when no delivery CLI configuration is present" do
306
-
307
- let(:argv) { %w{new_cookbook --workflow} }
308
-
309
- it "detects no delivery config" do
310
- Dir.chdir(tempdir) do
311
- expect(cookbook_generator.have_delivery_config?).to be(false)
312
- end
313
- end
314
-
315
- it "emits concise output" do
316
- Dir.chdir(tempdir) do
317
- allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
318
- expect(cookbook_generator.run).to eq(0)
319
- end
320
-
321
- expected = <<~OUTPUT
322
- Generating cookbook new_cookbook
323
- - Ensuring correct cookbook content
324
- - Committing cookbook files to git
325
-
326
- #{non_delivery_breadcrumb}
327
- OUTPUT
328
-
329
- actual = stdout_io.string
330
-
331
- # the formatter will add escape sequences to turn off any colors
332
- actual.gsub!("\e[0m", "")
333
- expect(actual).to eq(expected)
334
- end
335
- end
336
-
337
- context "when a delivery CLI config is present" do
338
-
339
- # Setup a situation like this:
340
- # there is a dir for the delivery organization with the
341
- # `.delivery/cli.toml` in it. Inside that is another dir (maybe IRL this
342
- # would be "cookbooks"), then we create the cookbook inside that.
343
-
344
- let(:argv) { %w{new_cookbook --workflow} }
345
-
346
- let(:tempdir_subdir) { File.join(tempdir, "subdirectory") }
347
-
348
- let(:dot_delivery_dir) { File.join(tempdir, ".delivery") }
349
-
350
- let(:dot_delivery_cli_toml) { File.join(dot_delivery_dir, "cli.toml") }
351
-
352
- before do
353
- Dir.mkdir(tempdir_subdir)
354
- Dir.mkdir(dot_delivery_dir)
355
- FileUtils.touch(dot_delivery_cli_toml)
356
- end
357
-
358
- it "detects the delivery config" do
359
- Dir.chdir(tempdir_subdir) do
360
- expect(cookbook_generator.have_delivery_config?).to be(true)
361
- end
362
- end
363
-
364
- it "emits concise output" do
365
- Dir.chdir(tempdir) do
366
- allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
367
- expect(cookbook_generator.run).to eq(0)
368
- end
369
-
370
- expected = <<~OUTPUT
371
- Generating cookbook new_cookbook
372
- - Ensuring correct cookbook content
373
- - Committing cookbook files to git
374
-
375
- Your cookbook is ready. To setup the pipeline, type `cd new_cookbook`, then run `delivery init`
376
- OUTPUT
377
-
378
- actual = stdout_io.string
379
-
380
- # the formatter will add escape sequences to turn off any colors
381
- actual.gsub!("\e[0m", "")
382
- expect(actual).to eq(expected)
383
- end
384
- end
385
- end
386
-
387
192
  context "when given the specs flag" do
388
193
 
389
194
  let(:argv) { %w{ new_cookbook --specs } }
@@ -615,6 +420,55 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
615
420
 
616
421
  end
617
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
+
618
472
  context "when configured for Berkshelf" do
619
473
 
620
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:
@@ -0,0 +1,3 @@
1
+ source "https://supermarket.getchef.com"
2
+
3
+ metadata
@@ -0,0 +1,4 @@
1
+ # bar-cookbook
2
+
3
+ TODO: Enter the cookbook description here.
4
+
@@ -0,0 +1,96 @@
1
+ # Put files/directories that should be ignored in this file when uploading
2
+ # or sharing to the community site.
3
+ # Lines that start with '# ' are comments.
4
+
5
+ # OS generated files #
6
+ ######################
7
+ .DS_Store
8
+ Icon?
9
+ nohup.out
10
+ ehthumbs.db
11
+ Thumbs.db
12
+
13
+ # SASS #
14
+ ########
15
+ .sass-cache
16
+
17
+ # EDITORS #
18
+ ###########
19
+ \#*
20
+ .#*
21
+ *~
22
+ *.sw[a-z]
23
+ *.bak
24
+ REVISION
25
+ TAGS*
26
+ tmtags
27
+ *_flymake.*
28
+ *_flymake
29
+ *.tmproj
30
+ .project
31
+ .settings
32
+ mkmf.log
33
+
34
+ ## COMPILED ##
35
+ ##############
36
+ a.out
37
+ *.o
38
+ *.pyc
39
+ *.so
40
+ *.com
41
+ *.class
42
+ *.dll
43
+ *.exe
44
+ */rdoc/
45
+
46
+ # Testing #
47
+ ###########
48
+ .watchr
49
+ .rspec
50
+ spec/*
51
+ spec/fixtures/*
52
+ test/*
53
+ features/*
54
+ Guardfile
55
+ Procfile
56
+
57
+ # SCM #
58
+ #######
59
+ .git
60
+ */.git
61
+ .gitignore
62
+ .gitmodules
63
+ .gitconfig
64
+ .gitattributes
65
+ .svn
66
+ */.bzr/*
67
+ */.hg/*
68
+ */.svn/*
69
+
70
+ # Berkshelf #
71
+ #############
72
+ Berksfile
73
+ Berksfile.lock
74
+ cookbooks/*
75
+ tmp
76
+
77
+ # Cookbooks #
78
+ #############
79
+ CONTRIBUTING
80
+ CHANGELOG*
81
+
82
+ # Strainer #
83
+ ############
84
+ Colanderfile
85
+ Strainerfile
86
+ .colander
87
+ .strainer
88
+
89
+ # Vagrant #
90
+ ###########
91
+ .vagrant
92
+ Vagrantfile
93
+
94
+ # Travis #
95
+ ##########
96
+ .travis.yml