chef-cli 3.1.6 → 4.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db59602ecc8f8eccfed56173f71092e36e1cc55ad6ece88e311d26896d7a1e0b
4
- data.tar.gz: a584cf195ad81b8e3ddae995aa5c275545e795782439990ceb11e7dc2450eba6
3
+ metadata.gz: 60e2fef23b0a30ce5f7dcc08bb3a72a2166c7944e2edf80b79a01975f4721029
4
+ data.tar.gz: 1270d7ff326fb8460a31b71b2fde6ec940a3700627a62aec10c14926c01b258e
5
5
  SHA512:
6
- metadata.gz: d1d34379eda31b8391fd142cc60ad71c0ac8bcd9e8a0fc9734da1a25cbfebdae1b2dda323ef6937ba2a05d11a86cc429f8a6d4692067d073b240dd5da3fdc5a2
7
- data.tar.gz: 27b7a7342e77162a34a7c6e3dcabfc9ba73d3081fb2b1bc6d144c5d01a8fa673bc2c60f6fc87ee2cc3841a970274f407b6cf9ab2c099d4cd6e7fdd845066c10c
6
+ metadata.gz: 0130ff765efec8876f369244a8b77ded247fe8a58a24b60561d361a0f9577a72a61db8d8ec34f8cd9e5e4b3f95eb9c0d1618211cf2dcce1a8be5b402be8a2028
7
+ data.tar.gz: b7ee1e7672559a167b511afe308642eb13d28eaa89aaff9f0ac44bf3968aa049c8978df63b6e3d4ee66a17ab66539ef7337afa452194055773b7bb76110c5e9f
@@ -55,6 +55,13 @@ module ChefCLI
55
55
  boolean: true,
56
56
  default: nil
57
57
 
58
+ option :specs,
59
+ short: "-s",
60
+ long: "--specs",
61
+ description: "Generate a cookbook with sample ChefSpec specs",
62
+ boolean: true,
63
+ default: nil
64
+
58
65
  option :workflow,
59
66
  short: "-w",
60
67
  long: "--workflow",
@@ -81,6 +88,7 @@ module ChefCLI
81
88
  @cookbook_name = nil
82
89
  @policy_mode = true
83
90
  @verbose = false
91
+ @specs = false
84
92
  super
85
93
  end
86
94
 
@@ -133,6 +141,7 @@ module ChefCLI
133
141
  Generator.add_attr_to_context(:workflow_project_git_initialized, have_git? && !cookbook_path_in_git_repo?)
134
142
 
135
143
  Generator.add_attr_to_context(:verbose, verbose?)
144
+ Generator.add_attr_to_context(:specs, specs?)
136
145
 
137
146
  Generator.add_attr_to_context(:use_policyfile, policy_mode?)
138
147
  Generator.add_attr_to_context(:pipeline, pipeline)
@@ -188,6 +197,10 @@ module ChefCLI
188
197
  @verbose
189
198
  end
190
199
 
200
+ def specs?
201
+ @specs
202
+ end
203
+
191
204
  #
192
205
  # Is there a .delivery/cli.toml in the current dir or any of the parent dirs
193
206
  #
@@ -223,6 +236,10 @@ module ChefCLI
223
236
  @verbose = true
224
237
  end
225
238
 
239
+ if config[:specs]
240
+ @specs = true
241
+ end
242
+
226
243
  true
227
244
  end
228
245
 
@@ -92,24 +92,26 @@ template "#{cookbook_dir}/test/integration/default/default_test.rb" do
92
92
  end
93
93
 
94
94
  # ChefSpec
95
- directory "#{cookbook_dir}/spec/unit/recipes" do
96
- recursive true
97
- end
98
-
99
- cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
100
- if context.use_policyfile
101
- source 'spec_helper_policyfile.rb'
102
- else
103
- source 'spec_helper.rb'
95
+ if context.specs
96
+ directory "#{cookbook_dir}/spec/unit/recipes" do
97
+ recursive true
104
98
  end
105
99
 
106
- action :create_if_missing
107
- end
100
+ cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
101
+ if context.use_policyfile
102
+ source 'spec_helper_policyfile.rb'
103
+ else
104
+ source 'spec_helper.rb'
105
+ end
108
106
 
109
- template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
110
- source 'recipe_spec.rb.erb'
111
- helpers(ChefCLI::Generator::TemplateHelper)
112
- action :create_if_missing
107
+ action :create_if_missing
108
+ end
109
+
110
+ template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
111
+ source 'recipe_spec.rb.erb'
112
+ helpers(ChefCLI::Generator::TemplateHelper)
113
+ action :create_if_missing
114
+ end
113
115
  end
114
116
 
115
117
  # Recipes
@@ -125,10 +127,13 @@ end
125
127
  unless context.enable_workflow
126
128
  directory "#{cookbook_dir}/.delivery"
127
129
 
128
- # Adding the delivery local-mode config
129
- cookbook_file "#{cookbook_dir}/.delivery/project.toml" do
130
- source 'delivery-project.toml'
131
- not_if { ::File.exist?("#{cookbook_dir}/.delivery/project.toml") }
130
+ template "#{cookbook_dir}/.delivery/project.toml" do
131
+ variables(
132
+ specs: context.specs
133
+ )
134
+ source 'delivery-project.toml.erb'
135
+ helpers(ChefCLI::Generator::TemplateHelper)
136
+ action :create_if_missing
132
137
  end
133
138
  end
134
139
 
@@ -0,0 +1,36 @@
1
+ # Delivery for Local Phases Execution
2
+ #
3
+ # This file allows you to execute test phases locally on a workstation or
4
+ # in a CI pipeline. The delivery-cli will read this file and execute the
5
+ # command(s) that are configured for each phase. You can customize them
6
+ # by just modifying the phase key on this file.
7
+ #
8
+ # By default these phases are configured for Cookbook Workflow only
9
+ #
10
+
11
+ [local_phases]
12
+ <% if @specs %>
13
+ unit = "chef exec rspec spec/"
14
+ <% else %>
15
+ unit = "echo skipping unit phase."
16
+ <% end %>
17
+ lint = "chef exec cookstyle"
18
+ # foodcritic has been deprecated in favor of cookstyle so we skip the syntax
19
+ # phase now.
20
+ syntax = "echo skipping syntax phase. Use lint phase instead."
21
+ provision = "chef exec kitchen create"
22
+ deploy = "chef exec kitchen converge"
23
+ smoke = "chef exec kitchen verify"
24
+ # The functional phase is optional, you can define it by uncommenting
25
+ # the line below and running the command: `delivery local functional`
26
+ # functional = ""
27
+ cleanup = "chef exec kitchen destroy"
28
+
29
+ # Remote project.toml file
30
+ #
31
+ # Instead of the local phases above, you may specify a remote URI location for
32
+ # the `project.toml` file. This is useful for teams that wish to centrally
33
+ # manage the behavior of the `delivery local` command across many different
34
+ # projects.
35
+ #
36
+ # remote_file = "https://url/project.toml"
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "3.1.6".freeze
19
+ VERSION = "4.0.0".freeze
20
20
  end
@@ -30,6 +30,24 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
30
30
  let(:stderr_io) { StringIO.new }
31
31
 
32
32
  let(:expected_cookbook_file_relpaths) do
33
+ %w{
34
+ .gitignore
35
+ kitchen.yml
36
+ test
37
+ test/integration
38
+ test/integration/default/default_test.rb
39
+ Policyfile.rb
40
+ chefignore
41
+ LICENSE
42
+ metadata.rb
43
+ README.md
44
+ CHANGELOG.md
45
+ recipes
46
+ recipes/default.rb
47
+ }
48
+ end
49
+
50
+ let(:expected_cookbook_file_relpaths_specs) do
33
51
  %w{
34
52
  .gitignore
35
53
  kitchen.yml
@@ -58,6 +76,12 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
58
76
  end
59
77
  end
60
78
 
79
+ let(:expected_cookbook_files_specs) do
80
+ expected_cookbook_file_relpaths_specs.map do |relpath|
81
+ File.join(tempdir, "new_cookbook", relpath)
82
+ end
83
+ end
84
+
61
85
  let(:non_delivery_breadcrumb) do
62
86
  <<~EOF
63
87
  Your cookbook is ready. Type `cd new_cookbook` to enter it.
@@ -150,9 +174,11 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
150
174
  expect(generator_context.cookbook_name).to eq("new_cookbook")
151
175
  expect(generator_context.recipe_name).to eq("default")
152
176
  expect(generator_context.verbose).to be(false)
177
+ expect(generator_context.specs).to be(false)
153
178
  end
154
179
 
155
180
  it "creates a new cookbook" do
181
+
156
182
  Dir.chdir(tempdir) do
157
183
  allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
158
184
  expect(cookbook_generator.run).to eq(0)
@@ -398,6 +424,28 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
398
424
  end
399
425
  end
400
426
 
427
+ context "when given the specs flag" do
428
+
429
+ let(:argv) { %w{ new_cookbook --specs } }
430
+
431
+ it "configures the generator context with specs mode enabled" do
432
+ cookbook_generator.read_and_validate_params
433
+ cookbook_generator.setup_context
434
+ expect(generator_context.specs).to be(true)
435
+ end
436
+
437
+ it "creates a new cookbook" do
438
+ Dir.chdir(tempdir) do
439
+ allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
440
+ expect(cookbook_generator.run).to eq(0)
441
+ end
442
+ generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
443
+ expected_cookbook_files_specs.each do |expected_file|
444
+ expect(generated_files).to include(expected_file)
445
+ end
446
+ end
447
+ end
448
+
401
449
  context "when given the verbose flag" do
402
450
 
403
451
  let(:argv) { %w{ new_cookbook --verbose } }
@@ -594,6 +642,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
594
642
  end
595
643
 
596
644
  include_examples "chefspec_spec_helper_file" do
645
+ let(:argv) { %w{ new_cookbook --policy --specs } }
597
646
 
598
647
  let(:expected_chefspec_spec_helper_content) do
599
648
  <<~SPEC_HELPER
@@ -683,6 +732,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
683
732
  end
684
733
 
685
734
  include_examples "chefspec_spec_helper_file" do
735
+ let(:argv) { %w{ new_cookbook --berks --specs } }
686
736
 
687
737
  let(:expected_chefspec_spec_helper_content) do
688
738
  <<~SPEC_HELPER
@@ -712,6 +762,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
712
762
  end
713
763
 
714
764
  describe "spec/unit/recipes/default_spec.rb" do
765
+ let(:argv) { %w{ new_cookbook --specs } }
715
766
  let(:file) { File.join(tempdir, "new_cookbook", "spec", "unit", "recipes", "default_spec.rb") }
716
767
 
717
768
  include_examples "a generated file", :cookbook_name do
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: 3.1.6
4
+ version: 4.0.0
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: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli
@@ -376,6 +376,7 @@ files:
376
376
  - lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb
377
377
  - lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb
378
378
  - lib/chef-cli/skeletons/code_generator/templates/default/cookbook_file.erb
379
+ - lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb
379
380
  - lib/chef-cli/skeletons/code_generator/templates/default/helpers.rb.erb
380
381
  - lib/chef-cli/skeletons/code_generator/templates/default/inspec_default_test.rb.erb
381
382
  - lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb