chef-cli 3.0.32 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/chef-cli.gemspec +1 -1
  4. data/lib/chef-cli/cli.rb +1 -5
  5. data/lib/chef-cli/command/generator_commands/cookbook.rb +5 -0
  6. data/lib/chef-cli/command/generator_commands/generator_generator.rb +1 -1
  7. data/lib/chef-cli/command/shell_init.rb +1 -1
  8. data/lib/chef-cli/command/update.rb +1 -1
  9. data/lib/chef-cli/configurable.rb +1 -1
  10. data/lib/chef-cli/cookbook_profiler/git.rb +4 -8
  11. data/lib/chef-cli/policyfile/artifactory_cookbook_source.rb +5 -1
  12. data/lib/chef-cli/policyfile/comparison_base.rb +1 -0
  13. data/lib/chef-cli/policyfile/differ.rb +1 -1
  14. data/lib/chef-cli/policyfile/remote_lock_fetcher.rb +1 -1
  15. data/lib/chef-cli/policyfile_services/install.rb +1 -1
  16. data/lib/chef-cli/service_exception_inspectors/http.rb +0 -26
  17. data/lib/chef-cli/service_exceptions.rb +1 -0
  18. data/lib/chef-cli/skeletons/code_generator/files/default/gitignore +4 -1
  19. data/lib/chef-cli/skeletons/code_generator/files/default/repo/README.md +3 -3
  20. data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +15 -2
  21. data/lib/chef-cli/skeletons/code_generator/recipes/cookbook_file.rb +5 -3
  22. data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb +1 -1
  23. data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +1 -1
  24. data/lib/chef-cli/version.rb +1 -1
  25. data/spec/test_helpers.rb +1 -1
  26. data/spec/unit/command/generator_commands/cookbook_file_spec.rb +9 -0
  27. data/spec/unit/command/generator_commands/cookbook_spec.rb +2 -2
  28. data/spec/unit/command/generator_commands/generator_generator_spec.rb +1 -1
  29. data/spec/unit/command/update_spec.rb +0 -8
  30. data/spec/unit/policyfile/artifactory_cookbook_source_spec.rb +27 -1
  31. data/spec/unit/policyfile/undo_stack_spec.rb +2 -2
  32. data/spec/unit/policyfile_install_with_includes_spec.rb +1 -1
  33. data/spec/unit/policyfile_lock_build_spec.rb +1 -1
  34. data/spec/unit/policyfile_lock_install_spec.rb +1 -1
  35. data/spec/unit/policyfile_lock_validation_spec.rb +1 -1
  36. data/spec/unit/policyfile_services/install_spec.rb +88 -0
  37. data/spec/unit/service_exception_inspectors/http_spec.rb +3 -17
  38. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f1cc14b62507710161304d60579a50eedb0125347d29e5600d4ba4240d6eec9
4
- data.tar.gz: a25398db16aa457dfcf8a59fa6ffbaf582469299ff0cdfa8427db5a1277e6b88
3
+ metadata.gz: ad936b7c0a024d571d22f4de9c78681906f98c07190e66ef723d07f680e3611d
4
+ data.tar.gz: 4e18354644f446734170b934fa9a1899a2178a121a62c64779e29995f5fad7be
5
5
  SHA512:
6
- metadata.gz: 5f0aaf0135f5f2034c7b7925f7fae7c5940dd4971531478dfd19be577739bfc4cd570381b4fa4e9c2f8b4ce4b3f7bb7108165d74aa36276023199e55a9094390
7
- data.tar.gz: e5ac2dc8430803d5f9a7d56e898466778bb2d4c9a4ebbd69580d045089048e905648e41f0c4b6a10d9b5d588489aa0caa2c37a7f9e4d24b0dfed8a5f5075c885
6
+ metadata.gz: adad25885aea41a51a851f1958f1c43668530d7a4eefaa4e4dffade6291f117836bb8f8908ac5d1ef0a2e13a0ab9ef3a689af6a5c8c874f370de7399c69e76c1
7
+ data.tar.gz: c89105687373b57a2809f5c540828c45a633b2872a73d4e926fd1e3aa189938be05d0a23ee8fc1f173bff5d3834826e1199a7c566cc09fa3fa835e8e1ddcaa6b
data/Gemfile CHANGED
@@ -13,8 +13,8 @@ group :test do
13
13
  gem "rspec", "~> 3.8"
14
14
  gem "rspec-expectations", "~> 3.8"
15
15
  gem "rspec-mocks", "~> 3.8"
16
- gem "cookstyle", "6.14.7" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command
17
- gem "chefstyle", "1.2.0"
16
+ gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command
17
+ gem "chefstyle", "=1.6.2"
18
18
  gem "test-kitchen", "> 2.5"
19
19
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6")
20
20
  gem "chef-zero", "~> 14"
data/chef-cli.gemspec CHANGED
@@ -15,7 +15,7 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- lib = File.expand_path("../lib", __FILE__)
18
+ lib = File.expand_path("lib", __dir__)
19
19
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
20
  require "chef-cli/version"
21
21
 
data/lib/chef-cli/cli.rb CHANGED
@@ -171,11 +171,7 @@ module ChefCLI
171
171
  private
172
172
 
173
173
  def manifest_field(field)
174
- if manifest_hash[field]
175
- manifest_hash[field]
176
- else
177
- "unknown"
178
- end
174
+ manifest_hash[field] || "unknown"
179
175
  end
180
176
 
181
177
  def component_version(name)
@@ -137,6 +137,7 @@ module ChefCLI
137
137
  Generator.add_attr_to_context(:use_policyfile, policy_mode?)
138
138
  Generator.add_attr_to_context(:pipeline, pipeline)
139
139
  Generator.add_attr_to_context(:kitchen, kitchen)
140
+ Generator.add_attr_to_context(:vscode_dir, create_vscode_dir?)
140
141
  end
141
142
 
142
143
  def kitchen
@@ -235,6 +236,10 @@ module ChefCLI
235
236
  end
236
237
  false
237
238
  end
239
+
240
+ def create_vscode_dir?
241
+ ::File.exist?("/Applications/Visual Studio Code.app") || ::File.exist?("#{ENV["APPDATA"]}\\Code")
242
+ end
238
243
  end
239
244
  end
240
245
  end
@@ -86,7 +86,7 @@ module ChefCLI
86
86
  # chefcli.generator_cookbook would make this command copy the custom
87
87
  # generator, but that doesn't make sense because the user can easily
88
88
  # do that anyway.
89
- File.expand_path("../../../skeletons/code_generator", __FILE__)
89
+ File.expand_path("../../skeletons/code_generator", __dir__)
90
90
  end
91
91
 
92
92
  private
@@ -142,7 +142,7 @@ module ChefCLI
142
142
  end
143
143
 
144
144
  def expand_completion_template_path(basename)
145
- File.join(File.expand_path("../../completions", __FILE__), basename)
145
+ File.join(File.expand_path("../completions", __dir__), basename)
146
146
  end
147
147
 
148
148
  def shell_completion_template_context
@@ -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
@@ -33,7 +33,7 @@ class Chef::Config
33
33
  # instead of `chefcli.generator_cookbook`).
34
34
  config_strict_mode(true)
35
35
 
36
- default(:generator_cookbook, File.expand_path("../skeletons/code_generator", __FILE__))
36
+ default(:generator_cookbook, File.expand_path("skeletons/code_generator", __dir__))
37
37
 
38
38
  config_context(:generator) do
39
39
  config_strict_mode(true)
@@ -120,14 +120,10 @@ module ChefCLI
120
120
  @unborn_branch = false
121
121
  branch
122
122
  rescue Mixlib::ShellOut::ShellCommandFailed => e
123
- # We may have an "unborn" branch, i.e. one with no commits.
124
- if unborn_branch_ref
125
- unborn_branch_ref
126
- else
127
- # if we got here, but verify_ref_cmd didn't error, we don't know why
128
- # the original git command failed, so re-raise.
129
- raise e
130
- end
123
+ # "unborn" branch, i.e. one with no commits or
124
+ # verify_ref_cmd didn't error, we don't know why
125
+ # the original git command failed, so re-raise.
126
+ unborn_branch_ref || raise(e)
131
127
  end
132
128
 
133
129
  def unborn_branch_ref
@@ -82,10 +82,14 @@ module ChefCLI
82
82
  "artifactory(#{uri})"
83
83
  end
84
84
 
85
+ def artifactory_api_key
86
+ chef_config&.artifactory_api_key || ENV["ARTIFACTORY_API_KEY"]
87
+ end
88
+
85
89
  private
86
90
 
87
91
  def http_connection_for(base_url)
88
- headers = { "X-Jfrog-Art-API" => chef_config.artifactory_api_key || ENV["ARTIFACTORY_API_KEY"] }
92
+ headers = { "X-Jfrog-Art-API" => artifactory_api_key }
89
93
  @http_connections[base_url] ||= Chef::HTTP::Simple.new(base_url, headers: headers)
90
94
  end
91
95
 
@@ -21,6 +21,7 @@ end
21
21
 
22
22
  autoload :FFI_Yajl, "ffi_yajl"
23
23
  require_relative "../service_exceptions"
24
+ require "net/protocol" unless defined?(Net::ProtocolError)
24
25
 
25
26
  module ChefCLI
26
27
  module Policyfile
@@ -17,7 +17,7 @@
17
17
 
18
18
  require "diff/lcs"
19
19
  require "diff/lcs/hunk"
20
- require "pastel"
20
+ require "pastel" unless defined?(Pastel)
21
21
  autoload :FFI_Yajl, "ffi_yajl"
22
22
 
23
23
  module ChefCLI
@@ -18,7 +18,7 @@
18
18
  require_relative "../policyfile_lock"
19
19
  require_relative "lock_fetcher_mixin"
20
20
  require_relative "../exceptions"
21
- require "chef/http"
21
+ require "net/protocol" unless defined?(Net::ProtocolError)
22
22
  require "tempfile" unless defined?(Tempfile)
23
23
 
24
24
  module ChefCLI
@@ -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)
@@ -33,17 +33,11 @@ module ChefCLI
33
33
 
34
34
  def extended_error_info
35
35
  <<~END
36
- --- REQUEST DATA ----
37
- #{http_method} #{uri}
38
- #{request_headers}
39
- #{req_body}
40
-
41
36
  --- RESPONSE DATA ---
42
37
  #{code} #{response_message}
43
38
  #{response_headers}
44
39
 
45
40
  #{response_body}
46
-
47
41
  END
48
42
  end
49
43
 
@@ -90,30 +84,10 @@ module ChefCLI
90
84
  headers_s
91
85
  end
92
86
 
93
- def request
94
- exception.chef_rest_request
95
- end
96
-
97
87
  def uri
98
88
  request.uri.to_s + request.path.to_s
99
89
  end
100
90
 
101
- def http_method
102
- request.method
103
- end
104
-
105
- def request_headers
106
- headers_s = ""
107
- request.each_header do |key, value|
108
- headers_s << key << ": " << value << "\n"
109
- end
110
- headers_s
111
- end
112
-
113
- def req_body
114
- request.body
115
- end
116
-
117
91
  end
118
92
  end
119
93
  end
@@ -123,6 +123,7 @@ module ChefCLI
123
123
 
124
124
  class DeletePolicyError < PolicyfileNestedException
125
125
  end
126
+
126
127
  class PolicyCookbookCleanError < PolicyfileNestedException
127
128
  end
128
129
 
@@ -16,7 +16,10 @@ bin/*
16
16
  .kitchen/
17
17
  kitchen.local.yml
18
18
 
19
- # Chef
19
+ # Chef Infra
20
20
  Berksfile.lock
21
21
  .zero-knife.rb
22
22
  Policyfile.lock.json
23
+
24
+ .idea/
25
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  Every Chef Infra installation needs a Chef Repository. This is the place where cookbooks, policyfiles, config files and other artifacts for managing systems with Chef Infra will live. We strongly recommend storing this repository in a version control system such as Git and treating it like source code.
4
4
 
5
- # Repository Directories
5
+ ## Repository Directories
6
6
 
7
7
  This repository contains several directories, and each directory contains a README file that describes what it is for in greater detail, and how to use it for managing your systems with Chef.
8
8
 
@@ -11,10 +11,10 @@ This repository contains several directories, and each directory contains a READ
11
11
  - `roles/` - Store roles in .rb or .json in the repository.
12
12
  - `environments/` - Store environments in .rb or .json in the repository.
13
13
 
14
- # Configuration
14
+ ## Configuration
15
15
 
16
16
  The config file, `.chef/config.rb` is a repository-specific configuration file for the knife command line tool. If you're using the Hosted Chef platform, you can download one for your organization from the management console. You can also generate a new config.rb by running `knife configure`. For more information about configuring Knife, see the Knife documentation at https://docs.chef.io/workstation/knife/
17
17
 
18
- # Next Steps
18
+ ## Next Steps
19
19
 
20
20
  Read the README file in each of the subdirectories for more information about what goes in those directories.
@@ -91,7 +91,7 @@ template "#{cookbook_dir}/test/integration/default/default_test.rb" do
91
91
  action :create_if_missing
92
92
  end
93
93
 
94
- # Chefspec
94
+ # ChefSpec
95
95
  directory "#{cookbook_dir}/spec/unit/recipes" do
96
96
  recursive true
97
97
  end
@@ -113,7 +113,6 @@ template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
113
113
  end
114
114
 
115
115
  # Recipes
116
-
117
116
  directory "#{cookbook_dir}/recipes"
118
117
 
119
118
  template "#{cookbook_dir}/recipes/default.rb" do
@@ -164,4 +163,18 @@ if context.have_git
164
163
  end
165
164
  end
166
165
 
166
+ if context.vscode_dir
167
+ directory "#{cookbook_dir}/.vscode"
168
+
169
+ file "#{cookbook_dir}/.vscode/extensions.json" do
170
+ content <<~CONTENT
171
+ {
172
+ "recommendations": [
173
+ "chef-software.chef"
174
+ ]
175
+ }
176
+ CONTENT
177
+ end
178
+ end
179
+
167
180
  include_recipe '::build_cookbook' if context.enable_workflow
@@ -1,7 +1,10 @@
1
1
  context = ChefCLI::Generator.context
2
2
  cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
3
- files_dir = File.join(cookbook_dir, 'files')
4
- cookbook_file_path = File.join(files_dir, context.new_file_basename)
3
+ new_file_basename = File.basename(context.new_file_basename)
4
+ relative_path = File.dirname(context.new_file_basename)
5
+ relative_path.slice! "."
6
+ files_dir = File.join(cookbook_dir, 'files', relative_path)
7
+ cookbook_file_path = File.join(files_dir, new_file_basename)
5
8
 
6
9
  directory files_dir do
7
10
  recursive true
@@ -19,5 +22,4 @@ else
19
22
  source 'cookbook_file.erb'
20
23
  helpers(ChefCLI::Generator::TemplateHelper)
21
24
  end
22
-
23
25
  end
@@ -4,7 +4,7 @@ driver:
4
4
 
5
5
  ## The forwarded_port port feature lets you connect to ports on the VM guest via
6
6
  ## localhost on the host.
7
- ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html
7
+ ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports
8
8
 
9
9
  # network:
10
10
  # - ["forwarded_port", {guest: 80, host: 8080}]
@@ -4,7 +4,7 @@ driver:
4
4
 
5
5
  ## The forwarded_port port feature lets you connect to ports on the VM guest via
6
6
  ## localhost on the host.
7
- ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html
7
+ ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports
8
8
 
9
9
  # network:
10
10
  # - ["forwarded_port", {guest: 80, host: 8080}]
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "3.0.32".freeze
19
+ VERSION = "3.1.0".freeze
20
20
  end
data/spec/test_helpers.rb CHANGED
@@ -39,7 +39,7 @@ module TestHelpers
39
39
  end
40
40
 
41
41
  def project_root
42
- File.expand_path("../..", __FILE__)
42
+ File.expand_path("..", __dir__)
43
43
  end
44
44
 
45
45
  def reset_tempdir
@@ -28,4 +28,13 @@ describe ChefCLI::Command::GeneratorCommands::CookbookFile do
28
28
  let(:new_file_name) { "new_file.txt" }
29
29
 
30
30
  end
31
+
32
+ include_examples "a file generator" do
33
+
34
+ let(:generator_name) { "file" }
35
+ let(:generated_files) { [ "files/file/new_file.txt" ] }
36
+ let(:new_file_name) { "file/new_file.txt" }
37
+
38
+ end
39
+
31
40
  end
@@ -562,7 +562,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
562
562
 
563
563
  ## The forwarded_port port feature lets you connect to ports on the VM guest via
564
564
  ## localhost on the host.
565
- ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html
565
+ ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports
566
566
 
567
567
  # network:
568
568
  # - ["forwarded_port", {guest: 80, host: 8080}]
@@ -645,7 +645,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
645
645
 
646
646
  ## The forwarded_port port feature lets you connect to ports on the VM guest via
647
647
  ## localhost on the host.
648
- ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html
648
+ ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports
649
649
 
650
650
  # network:
651
651
  # - ["forwarded_port", {guest: 80, host: 8080}]
@@ -26,7 +26,7 @@ describe ChefCLI::Command::GeneratorCommands::GeneratorGenerator do
26
26
  let(:stdout_io) { StringIO.new }
27
27
  let(:stderr_io) { StringIO.new }
28
28
 
29
- let(:repo_root) { File.expand_path("../../../../..", __FILE__) }
29
+ let(:repo_root) { File.expand_path("../../../..", __dir__) }
30
30
 
31
31
  let(:builtin_generator_path) { File.join(repo_root, "lib/chef-cli/skeletons/code_generator") }
32
32
 
@@ -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
@@ -20,8 +20,9 @@ require "chef-cli/policyfile/source_uri"
20
20
  require "chef-cli/policyfile/artifactory_cookbook_source"
21
21
 
22
22
  describe ChefCLI::Policyfile::ArtifactoryCookbookSource do
23
- subject { described_class.new(cookbook_source) }
23
+ subject { described_class.new(cookbook_source, chef_config: config) }
24
24
 
25
+ let(:config) { nil }
25
26
  let(:cookbook_source) { "https://supermarket.chef.io/api/v1" }
26
27
 
27
28
  let(:http_connection) { double("Chef::HTTP::Simple") }
@@ -56,4 +57,29 @@ describe ChefCLI::Policyfile::ArtifactoryCookbookSource do
56
57
  expect(subject.source_options_for("apache2", "1.10.4")).to eq(expected_opts)
57
58
  end
58
59
  end
60
+
61
+ describe "#artifactory_api_key" do
62
+ before do
63
+ ENV["ARTIFACTORY_API_KEY"] = "test"
64
+ end
65
+
66
+ context "when config is not present" do
67
+ let(:config) { nil }
68
+ it "should get artifactory key from the env" do
69
+ expect(subject.artifactory_api_key).to eq("test")
70
+ end
71
+ end
72
+
73
+ context "when config is present" do
74
+ let(:config) { double("Chef::Config") }
75
+ it "should get artifactory key from config when key is present" do
76
+ expect(config).to receive(:artifactory_api_key).and_return "test1"
77
+ expect(subject.artifactory_api_key).to eq("test1")
78
+ end
79
+ it "should get artifactory key from env when config is present but has a nil key" do
80
+ expect(config).to receive(:artifactory_api_key).and_return nil
81
+ expect(subject.artifactory_api_key).to eq("test")
82
+ end
83
+ end
84
+ end
59
85
  end
@@ -223,7 +223,7 @@ describe ChefCLI::Policyfile::UndoStack do
223
223
  end
224
224
 
225
225
  it "removes the oldest record" do
226
- oldest_record_file = undo_stack_files.sort.first
226
+ oldest_record_file = undo_stack_files.min
227
227
 
228
228
  undo_stack.push(incremented_undo_record(11))
229
229
 
@@ -251,7 +251,7 @@ describe ChefCLI::Policyfile::UndoStack do
251
251
  end
252
252
 
253
253
  it "removes the oldest record" do
254
- oldest_record_file = undo_stack_files.sort.first
254
+ oldest_record_file = undo_stack_files.min
255
255
 
256
256
  undo_stack.push(incremented_undo_record(11))
257
257
 
@@ -17,7 +17,7 @@
17
17
 
18
18
  require "spec_helper"
19
19
  require "chef-cli/policyfile_compiler"
20
- require "chef-cli/policyfile_lock.rb"
20
+ require "chef-cli/policyfile_lock"
21
21
 
22
22
  describe ChefCLI::PolicyfileLock, "installing cookbooks from included policies" do
23
23
 
@@ -19,7 +19,7 @@ require "spec_helper"
19
19
  require "shared/setup_git_cookbooks"
20
20
  require "shared/fixture_cookbook_checksums"
21
21
  require "chef-cli/policyfile/storage_config"
22
- require "chef-cli/policyfile_lock.rb"
22
+ require "chef-cli/policyfile_lock"
23
23
 
24
24
  describe ChefCLI::PolicyfileLock, "building a lockfile", :skip_on_windows do
25
25
 
@@ -17,7 +17,7 @@
17
17
 
18
18
  require "spec_helper"
19
19
  require "shared/fixture_cookbook_checksums"
20
- require "chef-cli/policyfile_lock.rb"
20
+ require "chef-cli/policyfile_lock"
21
21
 
22
22
  describe ChefCLI::PolicyfileLock, "installing cookbooks from a lockfile" do
23
23
 
@@ -16,7 +16,7 @@
16
16
  #
17
17
 
18
18
  require "spec_helper"
19
- require "chef-cli/policyfile_lock.rb"
19
+ require "chef-cli/policyfile_lock"
20
20
 
21
21
  describe ChefCLI::PolicyfileLock, "validating locked cookbooks" do
22
22
 
@@ -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 }
@@ -16,8 +16,7 @@
16
16
  #
17
17
 
18
18
  require "spec_helper"
19
- require "net/http" unless defined?(Net::HTTP)
20
- require "chef/monkey_patches/net_http"
19
+ require "net/http"
21
20
  require "chef-cli/service_exception_inspectors/http"
22
21
 
23
22
  describe ChefCLI::ServiceExceptionInspectors::HTTP do
@@ -64,7 +63,7 @@ describe ChefCLI::ServiceExceptionInspectors::HTTP do
64
63
  end
65
64
 
66
65
  let(:exception) do
67
- Net::HTTPClientException.new(message, response).tap { |e| e.chef_rest_request = request }
66
+ Net::HTTPClientException.new(message, response)
68
67
  end
69
68
 
70
69
  subject(:inspector) { described_class.new(exception) }
@@ -103,23 +102,10 @@ describe ChefCLI::ServiceExceptionInspectors::HTTP do
103
102
 
104
103
  end
105
104
 
106
- describe "showing the request and response in extended error info" do
105
+ describe "showing the response in extended error info" do
107
106
 
108
107
  let(:response_body) { "this is the response" }
109
108
 
110
- it "shows the request in a format similar to HTTP messages" do
111
- expected_request_string = <<~E
112
- --- REQUEST DATA ----
113
- POST /organizations/chef-oss-dev/cookbooks
114
- content-type: application/json
115
- accept: application/json
116
-
117
- this is the request
118
-
119
- E
120
- expect(inspector.extended_error_info).to include(expected_request_string)
121
- end
122
-
123
109
  it "shows the response in a format similar to HTTP messages" do
124
110
  expected_response_string = <<~E
125
111
  --- RESPONSE DATA ---
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.0.32
4
+ version: 3.1.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: 2020-09-29 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli
@@ -102,22 +102,22 @@ dependencies:
102
102
  name: solve
103
103
  requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ">"
106
- - !ruby/object:Gem::Version
107
- version: '2.0'
108
105
  - - "<"
109
106
  - !ruby/object:Gem::Version
110
107
  version: '5.0'
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
111
  type: :runtime
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">"
116
- - !ruby/object:Gem::Version
117
- version: '2.0'
118
115
  - - "<"
119
116
  - !ruby/object:Gem::Version
120
117
  version: '5.0'
118
+ - - ">"
119
+ - !ruby/object:Gem::Version
120
+ version: '2.0'
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: addressable
123
123
  requirement: !ruby/object:Gem::Requirement
@@ -601,7 +601,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
601
601
  - !ruby/object:Gem::Version
602
602
  version: '0'
603
603
  requirements: []
604
- rubygems_version: 3.0.3
604
+ rubygems_version: 3.1.4
605
605
  signing_key:
606
606
  specification_version: 4
607
607
  summary: A streamlined development and deployment workflow for Chef platform.