chef-cli 3.0.40 → 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 +4 -4
- data/Gemfile +2 -8
- data/lib/chef-cli/command/generator_commands/cookbook.rb +18 -1
- data/lib/chef-cli/command/generator_commands/generator_generator.rb +1 -1
- data/lib/chef-cli/command/update.rb +1 -1
- data/lib/chef-cli/completions/chef.fish.erb +4 -5
- data/lib/chef-cli/generator.rb +1 -1
- data/lib/chef-cli/helpers.rb +6 -3
- data/lib/chef-cli/policyfile_services/install.rb +1 -1
- data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +24 -19
- data/lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb +36 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/inspec_default_test.rb.erb +1 -1
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +1 -0
- data/lib/chef-cli/version.rb +1 -1
- data/spec/unit/command/generator_commands/cookbook_spec.rb +52 -1
- data/spec/unit/command/generator_commands/generator_generator_spec.rb +1 -1
- data/spec/unit/command/shell_init_spec.rb +10 -10
- data/spec/unit/command/update_spec.rb +0 -8
- data/spec/unit/policyfile_services/install_spec.rb +88 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60e2fef23b0a30ce5f7dcc08bb3a72a2166c7944e2edf80b79a01975f4721029
|
4
|
+
data.tar.gz: 1270d7ff326fb8460a31b71b2fde6ec940a3700627a62aec10c14926c01b258e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0130ff765efec8876f369244a8b77ded247fe8a58a24b60561d361a0f9577a72a61db8d8ec34f8cd9e5e4b3f95eb9c0d1618211cf2dcce1a8be5b402be8a2028
|
7
|
+
data.tar.gz: b7ee1e7672559a167b511afe308642eb13d28eaa89aaff9f0ac44bf3968aa049c8978df63b6e3d4ee66a17ab66539ef7337afa452194055773b7bb76110c5e9f
|
data/Gemfile
CHANGED
@@ -2,12 +2,6 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
group :docs do
|
6
|
-
gem "yard"
|
7
|
-
gem "redcarpet"
|
8
|
-
gem "github-markup"
|
9
|
-
end
|
10
|
-
|
11
5
|
group :test do
|
12
6
|
gem "rake"
|
13
7
|
gem "rspec", "~> 3.8"
|
@@ -15,17 +9,17 @@ group :test do
|
|
15
9
|
gem "rspec-mocks", "~> 3.8"
|
16
10
|
gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command
|
17
11
|
gem "chefstyle", "=1.6.2"
|
18
|
-
gem "test-kitchen", "
|
12
|
+
gem "test-kitchen", ">= 2.11.1"
|
19
13
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6")
|
20
14
|
gem "chef-zero", "~> 14"
|
21
15
|
gem "chef", "~> 15"
|
16
|
+
gem "chef-utils", "=16.6.14"
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
20
|
group :development do
|
26
21
|
gem "pry"
|
27
22
|
gem "pry-byebug"
|
28
|
-
gem "pry-stack_explorer", "~> 0.4.0"
|
29
23
|
gem "rb-readline"
|
30
24
|
end
|
31
25
|
|
@@ -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
|
#
|
@@ -207,7 +220,7 @@ module ChefCLI
|
|
207
220
|
if !@cookbook_name_or_path
|
208
221
|
@params_valid = false
|
209
222
|
elsif File.basename(@cookbook_name_or_path).include?("-")
|
210
|
-
msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/ctl_chef/#chef-generate-cookbook for more information.")
|
223
|
+
msg("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.")
|
211
224
|
end
|
212
225
|
|
213
226
|
if config[:berks] && config[:policy]
|
@@ -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
|
|
@@ -109,7 +109,7 @@ module ChefCLI
|
|
109
109
|
# @api private
|
110
110
|
def metadata_rb
|
111
111
|
<<~METADATA
|
112
|
-
name
|
112
|
+
name File.basename(File.dirname(__FILE__))
|
113
113
|
description 'Custom code generator cookbook for use with #{ChefCLI::Dist::PRODUCT}'
|
114
114
|
version '0.1.0'
|
115
115
|
|
@@ -91,7 +91,7 @@ module ChefCLI
|
|
91
91
|
def run(params = [])
|
92
92
|
return 1 unless apply_params!(params)
|
93
93
|
|
94
|
-
attributes_updater.run
|
94
|
+
attributes_updater.run if update_attributes_only?
|
95
95
|
installer.run(@cookbooks_to_update, config[:exclude_deps]) unless update_attributes_only?
|
96
96
|
0
|
97
97
|
rescue PolicyfileServiceError => e
|
@@ -1,10 +1,9 @@
|
|
1
|
+
|
1
2
|
# Fish Shell command-line completions for <%=ChefCLI::Dist::PRODUCT %>
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
test (count $cmd) -eq 1
|
6
|
-
end
|
4
|
+
# set a list of all the chef commands in the Ruby chef-cli
|
5
|
+
set -l chef_commands <%= commands.keys.join(' ') %>;
|
7
6
|
|
8
7
|
<% commands.each do |command, desc| -%>
|
9
|
-
complete -c chef -f -n
|
8
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>";
|
10
9
|
<% end -%>
|
data/lib/chef-cli/generator.rb
CHANGED
@@ -150,7 +150,7 @@ module ChefCLI
|
|
150
150
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
151
151
|
EOH
|
152
152
|
else
|
153
|
-
raise ArgumentError, "Invalid generator.license setting: #{license}. See available licenses at https://docs.chef.io/ctl_chef/#chef-generate-cookbook"
|
153
|
+
raise ArgumentError, "Invalid generator.license setting: #{license}. See available licenses at https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook"
|
154
154
|
end
|
155
155
|
if comment
|
156
156
|
# Ensure there's no trailing whitespace
|
data/lib/chef-cli/helpers.rb
CHANGED
@@ -87,7 +87,7 @@ module ChefCLI
|
|
87
87
|
# On Mac we place all of our symlinks under /usr/local/bin on other
|
88
88
|
# platforms they are under /usr/bin
|
89
89
|
def usr_bin_prefix
|
90
|
-
@usr_bin_prefix ||=
|
90
|
+
@usr_bin_prefix ||= macos? ? "/usr/local/bin" : "/usr/bin"
|
91
91
|
end
|
92
92
|
|
93
93
|
# Returns the full path to the given command under usr_bin_prefix
|
@@ -166,8 +166,11 @@ module ChefCLI
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
# Returns true if we are on
|
170
|
-
|
169
|
+
# @return [Boolean] Returns true if we are on macOS. Otherwise false
|
170
|
+
#
|
171
|
+
# @api private
|
172
|
+
#
|
173
|
+
def macos?
|
171
174
|
!!(RUBY_PLATFORM =~ /darwin/)
|
172
175
|
end
|
173
176
|
end
|
@@ -61,7 +61,7 @@ module ChefCLI
|
|
61
61
|
|
62
62
|
if installing_from_lock?
|
63
63
|
install_from_lock
|
64
|
-
elsif cookbooks_to_update.empty? # means update everything
|
64
|
+
elsif cookbooks_to_update.empty? || policyfile_lock.nil? # means update everything
|
65
65
|
generate_lock_and_install
|
66
66
|
else
|
67
67
|
update_lock_and_install(cookbooks_to_update, exclude_deps)
|
@@ -92,24 +92,26 @@ template "#{cookbook_dir}/test/integration/default/default_test.rb" do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# ChefSpec
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
107
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
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"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# InSpec test for recipe <%= cookbook_name %>::<%= recipe_name %>
|
2
2
|
|
3
|
-
# The InSpec reference, with examples and extensive documentation, can be
|
3
|
+
# The Chef InSpec reference, with examples and extensive documentation, can be
|
4
4
|
# found at https://docs.chef.io/inspec/resources/
|
5
5
|
|
6
6
|
unless os.windows?
|
data/lib/chef-cli/version.rb
CHANGED
@@ -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.
|
@@ -129,7 +153,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
129
153
|
|
130
154
|
it "warns if a hyphenated cookbook name is passed" do
|
131
155
|
expect(with_argv(%w{my-cookbook}).run).to eq(0)
|
132
|
-
message = "Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/ctl_chef/#chef-generate-cookbook for more information."
|
156
|
+
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."
|
133
157
|
expect(stdout_io.string).to include(message)
|
134
158
|
end
|
135
159
|
|
@@ -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
|
@@ -181,7 +181,7 @@ describe ChefCLI::Command::GeneratorCommands::GeneratorGenerator do
|
|
181
181
|
metadata_path = File.join(target_dir, "metadata.rb")
|
182
182
|
metadata_content = IO.read(metadata_path)
|
183
183
|
expected_metadata = <<~METADATA
|
184
|
-
name
|
184
|
+
name File.basename(File.dirname(__FILE__))
|
185
185
|
description 'Custom code generator cookbook for use with #{ChefCLI::Dist::PRODUCT}'
|
186
186
|
version '0.1.0'
|
187
187
|
|
@@ -264,8 +264,8 @@ describe ChefCLI::Command::ShellInit do
|
|
264
264
|
{
|
265
265
|
"exec" => "Runs the command in context of the embedded ruby",
|
266
266
|
"env" => "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}",
|
267
|
-
"gem" => "Runs the `gem` command in context of the embedded
|
268
|
-
"generate" => "Generate a new
|
267
|
+
"gem" => "Runs the `gem` command in context of the embedded Ruby",
|
268
|
+
"generate" => "Generate a new repository, cookbook, or other component",
|
269
269
|
}
|
270
270
|
end
|
271
271
|
|
@@ -276,17 +276,17 @@ describe ChefCLI::Command::ShellInit do
|
|
276
276
|
|
277
277
|
let(:expected_completion_function) do
|
278
278
|
<<~END_COMPLETION
|
279
|
+
|
279
280
|
# Fish Shell command-line completions for #{ChefCLI::Dist::PRODUCT}
|
280
281
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
282
|
+
# set a list of all the chef commands in the Ruby chef-cli
|
283
|
+
set -l chef_commands exec env gem generate;
|
284
|
+
|
285
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a exec -d "Runs the command in context of the embedded ruby";
|
286
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a env -d "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}";
|
287
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a gem -d "Runs the `gem` command in context of the embedded Ruby";
|
288
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a generate -d "Generate a new repository, cookbook, or other component";
|
285
289
|
|
286
|
-
complete -c chef -f -n '__fish_chef_no_command' -a exec -d "Runs the command in context of the embedded ruby"
|
287
|
-
complete -c chef -f -n '__fish_chef_no_command' -a env -d "Prints environment variables used by Chef Workstation"
|
288
|
-
complete -c chef -f -n '__fish_chef_no_command' -a gem -d "Runs the `gem` command in context of the embedded ruby"
|
289
|
-
complete -c chef -f -n '__fish_chef_no_command' -a generate -d "Generate a new app, cookbook, or component"
|
290
290
|
END_COMPLETION
|
291
291
|
end
|
292
292
|
|
@@ -132,10 +132,6 @@ describe ChefCLI::Command::Update do
|
|
132
132
|
context "when the command is successful" do
|
133
133
|
before do
|
134
134
|
expect(install_service).to receive(:run)
|
135
|
-
expect(ChefCLI::PolicyfileServices::UpdateAttributes).to receive(:new)
|
136
|
-
.with(policyfile: nil, ui: command.ui, root_dir: Dir.pwd, chef_config: anything)
|
137
|
-
.and_return(update_attrs_service)
|
138
|
-
expect(update_attrs_service).to receive(:run)
|
139
135
|
end
|
140
136
|
|
141
137
|
it "returns 0" do
|
@@ -159,10 +155,6 @@ describe ChefCLI::Command::Update do
|
|
159
155
|
|
160
156
|
before do
|
161
157
|
expect(install_service).to receive(:run).and_raise(exception)
|
162
|
-
expect(ChefCLI::PolicyfileServices::UpdateAttributes).to receive(:new)
|
163
|
-
.with(policyfile: nil, ui: command.ui, root_dir: Dir.pwd, chef_config: anything)
|
164
|
-
.and_return(update_attrs_service)
|
165
|
-
expect(update_attrs_service).to receive(:run)
|
166
158
|
end
|
167
159
|
|
168
160
|
it "returns 1" do
|
@@ -54,6 +54,10 @@ describe ChefCLI::PolicyfileServices::Install do
|
|
54
54
|
|
55
55
|
let(:overwrite) { false }
|
56
56
|
|
57
|
+
let(:cookbooks_to_update) { [] || [ "my_cookbook" ] }
|
58
|
+
|
59
|
+
let(:cookbooks_to_update_empty) { false }
|
60
|
+
|
57
61
|
let(:ui) { TestHelpers::TestUI.new }
|
58
62
|
|
59
63
|
let(:install_service) { described_class.new(policyfile: policyfile_rb_name, ui: ui, root_dir: working_dir, overwrite: overwrite) }
|
@@ -153,6 +157,90 @@ describe ChefCLI::PolicyfileServices::Install do
|
|
153
157
|
|
154
158
|
end
|
155
159
|
|
160
|
+
context "when cookbook to update is empty and no policy lock exist" do
|
161
|
+
|
162
|
+
let(:cookbooks_to_update_empty) { true }
|
163
|
+
|
164
|
+
it "create the policy lock" do
|
165
|
+
install_service.run(:cookbooks_to_update)
|
166
|
+
generated_lock = result_policyfile_lock
|
167
|
+
expect(generated_lock.name).to eq("install-example")
|
168
|
+
expect(generated_lock.cookbook_locks).to have_key("local-cookbook")
|
169
|
+
end
|
170
|
+
|
171
|
+
it "checks for policy lock" do
|
172
|
+
lock = install_service.policyfile_lock
|
173
|
+
expect(lock).to eq(nil)
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
context "when cookbook to update is empty and policy lock exist" do
|
179
|
+
|
180
|
+
before do
|
181
|
+
install_service.dup.run
|
182
|
+
end
|
183
|
+
|
184
|
+
let(:cookbooks_to_update_empty) { true }
|
185
|
+
|
186
|
+
it "create the policy lock" do
|
187
|
+
install_service.run(:cookbooks_to_update)
|
188
|
+
generated_lock = result_policyfile_lock
|
189
|
+
expect(generated_lock.name).to eq("install-example")
|
190
|
+
expect(generated_lock.cookbook_locks).to have_key("local-cookbook")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "checks for policy lock" do
|
194
|
+
lock = install_service.policyfile_lock
|
195
|
+
expect(lock).to be_an_instance_of(ChefCLI::PolicyfileLock)
|
196
|
+
expect(lock.name).to eq("install-example")
|
197
|
+
expect(lock.cookbook_locks).to have_key("local-cookbook")
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when cookbook to update is not empty and no policy lock exist" do
|
203
|
+
|
204
|
+
let(:cookbooks_to_update) { [ "my_cookbook" ] }
|
205
|
+
|
206
|
+
it "create the policy lock" do
|
207
|
+
install_service.run(:cookbooks_to_update)
|
208
|
+
generated_lock = result_policyfile_lock
|
209
|
+
expect(generated_lock.name).to eq("install-example")
|
210
|
+
expect(generated_lock.cookbook_locks).to have_key("local-cookbook")
|
211
|
+
end
|
212
|
+
|
213
|
+
it "checks for policy lock" do
|
214
|
+
lock = install_service.policyfile_lock
|
215
|
+
expect(lock).to eq(nil)
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
context "when cookbook to update is not empty and policy lock exist" do
|
221
|
+
|
222
|
+
before do
|
223
|
+
install_service.dup.run
|
224
|
+
end
|
225
|
+
|
226
|
+
let(:cookbooks_to_update) { [ "my_cookbook" ] }
|
227
|
+
|
228
|
+
it "create the policy lock" do
|
229
|
+
install_service.run(:cookbooks_to_update)
|
230
|
+
generated_lock = result_policyfile_lock
|
231
|
+
expect(generated_lock.name).to eq("install-example")
|
232
|
+
expect(generated_lock.cookbook_locks).to have_key("local-cookbook")
|
233
|
+
end
|
234
|
+
|
235
|
+
it "create the policy lock" do
|
236
|
+
lock = install_service.policyfile_lock
|
237
|
+
expect(lock).to be_an_instance_of(ChefCLI::PolicyfileLock)
|
238
|
+
expect(lock.name).to eq("install-example")
|
239
|
+
expect(lock.cookbook_locks).to have_key("local-cookbook")
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
156
244
|
context "and a lockfile exists and `overwrite` is specified" do
|
157
245
|
|
158
246
|
let(:overwrite) { true }
|
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:
|
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-
|
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
|