summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2019-04-18 15:35:22 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2019-04-24 13:29:00 -0400
commitcd1a90b44f74f86f9479de657feff6748f2a7a07 (patch)
tree0f138b97ac1618aa7ac1ef75a89bdf8834cf410d
parent05f75ab5a29ad2b563d13d90281508db4916c9c2 (diff)
downloadchef-cd1a90b44f74f86f9479de657feff6748f2a7a07.tar.gz
Rubocop
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r--lib/chef/knife/bootstrap.rb12
-rw-r--r--spec/unit/knife/bootstrap_spec.rb1
-rw-r--r--spec/unit/knife/core/windows_bootstrap_context_spec.rb80
3 files changed, 46 insertions, 47 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 5a2c00b91c..b68fb1aa1e 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -371,8 +371,8 @@ class Chef
],
winrm_authentication_protocol: [:winrm_auth_method,
"--winrm-authentication-protocol PROTOCOL",
- ]
- }
+ ],
+ }.freeze
DEPRECATED_FLAGS.each do |flag, new_flag_config|
new_flag, old_long = new_flag_config
@@ -513,13 +513,13 @@ class Chef
# This can be moved up to the base knife class if it's agreeable.
def warn_and_map_deprecated_flags
DEPRECATED_FLAGS.each do |old_key, new_flag_config|
- new_key, _ = new_flag_config
- if (config.key?(old_key) && config_source(old_key) == :cli)
+ new_key, = new_flag_config
+ if config.key?(old_key) && config_source(old_key) == :cli
# TODO - do we want the same warnings for knife config keys
# in absence of CLI keys?
if config.key?(new_key) && config_source(new_key) == :cli
- new_key_name = "--#{new_key.to_s.gsub("_", "-")}"
- old_key_name = "--#{old_key.to_s.gsub("_", "-")}"
+ new_key_name = "--#{new_key.to_s.tr("_", "-")}"
+ old_key_name = "--#{old_key.to_s.tr("_", "-")}"
ui.warn <<~EOM
You provided both #{new_key_name} and #{old_key_name}.
Using: '#{new_key_name.split(" ").first} #{config[new_key]}' because #{old_key_name} is deprecated.
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index c3c7cb6758..db85eafde7 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -1591,7 +1591,6 @@ describe Chef::Knife::Bootstrap do
Chef::Config[:silence_deprecation_warnings] = false
end
-
context "when a deprecated CLI flag is given on the CLI" do
before do
knife.config[:ssh_user] = "sshuser"
diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb
index 75c8702866..80a846100a 100644
--- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'chef/knife/core/windows_bootstrap_context'
+require "spec_helper"
+require "chef/knife/core/windows_bootstrap_context"
describe Chef::Knife::Core::WindowsBootstrapContext do
- let(:config) { { } }
+ let(:config) { {} }
let(:bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(config, nil, Chef::Config, nil) }
describe "fips" do
@@ -49,20 +49,20 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
end
describe "trusted_certs_script" do
- let(:mock_cert_dir) { ::File.absolute_path(::File.join('spec','assets','fake_trusted_certs')) }
+ let(:mock_cert_dir) { ::File.absolute_path(::File.join("spec", "assets", "fake_trusted_certs")) }
let(:script_output) { bootstrap_context.trusted_certs_script }
let(:crt_files) { ::Dir.glob(::File.join(mock_cert_dir, "*.crt")) }
let(:pem_files) { ::Dir.glob(::File.join(mock_cert_dir, "*.pem")) }
- let(:other_files) { ::Dir.glob(::File.join(mock_cert_dir, "*"))-crt_files-pem_files }
+ let(:other_files) { ::Dir.glob(::File.join(mock_cert_dir, "*")) - crt_files - pem_files }
before do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:trusted_certs_dir => mock_cert_dir))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(trusted_certs_dir: mock_cert_dir))
end
it "should echo every .crt file in the trusted_certs directory" do
crt_files.each do |f|
echo_file = ::File.read(f).gsub(/^/, "echo.")
- expect(script_output).to include(::File.join('trusted_certs',::File.basename(f)))
+ expect(script_output).to include(::File.join("trusted_certs", ::File.basename(f)))
expect(script_output).to include(echo_file)
end
end
@@ -70,7 +70,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
it "should echo every .pem file in the trusted_certs directory" do
pem_files.each do |f|
echo_file = ::File.read(f).gsub(/^/, "echo.")
- expect(script_output).to include(::File.join('trusted_certs',::File.basename(f)))
+ expect(script_output).to include(::File.join("trusted_certs", ::File.basename(f)))
expect(script_output).to include(echo_file)
end
end
@@ -78,7 +78,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
it "should not echo files which aren't .crt or .pem files" do
other_files.each do |f|
echo_file = ::File.read(f).gsub(/^/, "echo.")
- expect(script_output).to_not include(::File.join('trusted_certs',::File.basename(f)))
+ expect(script_output).to_not include(::File.join("trusted_certs", ::File.basename(f)))
expect(script_output).to_not include(echo_file)
end
end
@@ -86,7 +86,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
describe "validation_key" do
before do
- bootstrap_context.instance_variable_set(:@config, Mash.new(:validation_key => "C:\\chef\\key.pem"))
+ bootstrap_context.instance_variable_set(:@config, Mash.new(validation_key: "C:\\chef\\key.pem"))
end
it "should return false if validation_key does not exist" do
@@ -100,49 +100,49 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
context "when config_log_location value is nil" do
it "sets STDOUT in client.rb as default" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => nil))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: nil))
expect(bootstrap_context.get_log_location).to eq("STDOUT\n")
end
end
context "when config_log_location value is empty" do
it "sets STDOUT in client.rb as default" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => ""))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: ""))
expect(bootstrap_context.get_log_location).to eq("STDOUT\n")
end
end
context "when config_log_location value is STDOUT" do
it "sets STDOUT in client.rb" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => STDOUT))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: STDOUT))
expect(bootstrap_context.get_log_location).to eq("STDOUT\n")
end
end
context "when config_log_location value is STDERR" do
it "sets STDERR in client.rb" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => STDERR))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: STDERR))
expect(bootstrap_context.get_log_location).to eq("STDERR\n")
end
end
context "when config_log_location value is path to a file" do
it "sets file path in client.rb" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => "C:\\chef\\chef.log"))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: "C:\\chef\\chef.log"))
expect(bootstrap_context.get_log_location).to eq("\"C:\\chef\\chef.log\"\n")
end
end
context "when config_log_location value is :win_evt" do
it "sets :win_evt in client.rb" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => :win_evt))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: :win_evt))
expect(bootstrap_context.get_log_location).to eq(":win_evt\n")
end
end
context "when config_log_location value is :syslog" do
it "raise error with message and exit" do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_location => :syslog))
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_location: :syslog))
expect { bootstrap_context.get_log_location }.to raise_error("syslog is not supported for log_location on Windows OS\n")
end
end
@@ -151,34 +151,34 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
describe "#config_content" do
before do
- bootstrap_context.instance_variable_set(:@chef_config, Mash.new(:config_log_level => :info,
- :config_log_location => STDOUT,
- :chef_server_url => "http://chef.example.com:4444",
- :validation_client_name => "chef-validator-testing",
- :file_cache_path => "c:/chef/cache",
- :file_backup_path => "c:/chef/backup",
- :cache_options => ({:path => "c:/chef/cache/checksums", :skip_expires => true})
+ bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_level: :info,
+ config_log_location: STDOUT,
+ chef_server_url: "http://chef.example.com:4444",
+ validation_client_name: "chef-validator-testing",
+ file_cache_path: "c:/chef/cache",
+ file_backup_path: "c:/chef/backup",
+ cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true })
))
end
it "generates the config file data" do
- expected = <<-EXPECTED
-echo.chef_server_url "http://chef.example.com:4444"
-echo.validation_client_name "chef-validator-testing"
-echo.file_cache_path "c:/chef/cache"
-echo.file_backup_path "c:/chef/backup"
-echo.cache_options ^({:path =^> "c:/chef/cache/checksums", :skip_expires =^> true}^)
-echo.# Using default node name ^(fqdn^)
-echo.log_level :info
-echo.log_location STDOUT
-EXPECTED
- expect(bootstrap_context.config_content).to eq expected
+ expected = <<~EXPECTED
+ echo.chef_server_url "http://chef.example.com:4444"
+ echo.validation_client_name "chef-validator-testing"
+ echo.file_cache_path "c:/chef/cache"
+ echo.file_backup_path "c:/chef/backup"
+ echo.cache_options ^({:path =^> "c:/chef/cache/checksums", :skip_expires =^> true}^)
+ echo.# Using default node name ^(fqdn^)
+ echo.log_level :info
+ echo.log_location STDOUT
+ EXPECTED
+ expect(bootstrap_context.config_content).to eq expected
end
end
describe "latest_current_windows_chef_version_query" do
it "returns the major version of the current version of Chef" do
- stub_const("Chef::VERSION", '15.1.2')
+ stub_const("Chef::VERSION", "15.1.2")
expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=15")
end
@@ -197,7 +197,7 @@ EXPECTED
it "returns a chef.io msi url with provided url parameters substituted" do
reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something"
- expect(bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(reference_url)
+ expect(bootstrap_context.msi_url("machine", "arch", "ctx")).to eq(reference_url)
end
end
@@ -210,14 +210,14 @@ EXPECTED
end
it "doesn't introduce any unnecessary query parameters if provided by the template" do
- expect(bootstrap_context.msi_url('machine', 'arch', 'ctx')).to eq(custom_url)
+ expect(bootstrap_context.msi_url("machine", "arch", "ctx")).to eq(custom_url)
end
end
end
describe "bootstrap_install_command for bootstrap through WinRM" do
context "when bootstrap_install_command option is passed on CLI" do
- let(:bootstrap) { Chef::Knife::Bootstrap.new(['--bootstrap-install-command', 'chef-client']) }
+ let(:bootstrap) { Chef::Knife::Bootstrap.new(["--bootstrap-install-command", "chef-client"]) }
before do
bootstrap.config[:bootstrap_install_command] = "chef-client"
end
@@ -242,7 +242,7 @@ EXPECTED
describe "bootstrap_install_command for bootstrap through SSH" do
context "when bootstrap_install_command option is passed on CLI" do
- let(:bootstrap) { Chef::Knife::Bootstrap.new(['--bootstrap-install-command', 'chef-client']) }
+ let(:bootstrap) { Chef::Knife::Bootstrap.new(["--bootstrap-install-command", "chef-client"]) }
before do
bootstrap.config[:bootstrap_install_command] = "chef-client"
end