Skip to content

Commit

Permalink
Fix cookstyle offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
legal90 committed Jan 18, 2017
1 parent b012791 commit df8d1ce
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
Style/GuardClause:
Enabled: false
Style/ModuleFunction:
Enabled: false
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace :style do
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
progress: true
progress: true,
}
end
rescue LoadError
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConsulAcl < Chef::Resource

# @!attribute type
# @return [String]
attribute(:type, equal_to: %w{client management}, default: 'client')
attribute(:type, equal_to: %w(client management), default: 'client')

# @!attribute rules
# @return [String]
Expand Down
4 changes: 2 additions & 2 deletions libraries/consul_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def to_json
watches
)

for_keeps << %i{bootstrap bootstrap_expect} if server
for_keeps << %i{ca_file cert_file key_file} if tls?
for_keeps << %i(bootstrap bootstrap_expect) if server
for_keeps << %i(ca_file cert_file key_file) if tls?
for_keeps = for_keeps.flatten

config = to_hash.keep_if do |k, _|
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConsulDefinition < Chef::Resource

# @!attribute type
# @return [String]
attribute(:type, equal_to: %w{check service checks services})
attribute(:type, equal_to: %w(check service checks services))

# @!attribute parameters
# @return [Hash]
Expand Down
4 changes: 2 additions & 2 deletions libraries/consul_installation_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.provides_auto?(_node, _resource)
# @return [Hash]
# @api private
def self.default_inversion_options(node, resource)
extract_path = node.windows? ? node.config_prefix_path : '/opt/consul'
extract_path = node.platform_family?('windows') ? node.config_prefix_path : '/opt/consul'
super.merge(extract_to: extract_path,
version: resource.version,
archive_url: 'https://releases.hashicorp.com/consul/%{version}/%{basename}',
Expand All @@ -47,7 +47,7 @@ def action_create
recursive true
end

url = options[:archive_url] % {version: options[:version], basename: options[:archive_basename]}
url = options[:archive_url] % { version: options[:version], basename: options[:archive_basename] }
poise_archive url do
destination join_path(options[:extract_to], new_resource.version)
source_properties checksum: options[:archive_checksum]
Expand Down
10 changes: 5 additions & 5 deletions libraries/consul_service_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module Provider
class ConsulServiceWindows < Chef::Provider
include Poise
include Chef::Mixin::ShellOut
provides(:consul_service, os: %w{windows})
provides(:consul_service, os: %w(windows))
include ConsulCookbook::Helpers

def action_enable
notifying_block do
directories = %W{#{new_resource.data_dir}
directories = %W(#{new_resource.data_dir}
#{new_resource.config_dir}
#{::File.dirname(new_resource.nssm_params['AppStdout'])}
#{::File.dirname(new_resource.nssm_params['AppStderr'])}}.uniq.compact
#{::File.dirname(new_resource.nssm_params['AppStderr'])}).uniq.compact
directories.delete_if { |i| i.eql? '.' }.each do |dirname|
directory dirname do
recursive true
Expand Down Expand Up @@ -54,7 +54,7 @@ def action_enable
end
# Check if the service is running, but don't bother if we're already
# changing some nssm parameters
unless nssm_service_status?(%w{SERVICE_RUNNING}) && mismatch_params.empty?
unless nssm_service_status?(%w(SERVICE_RUNNING)) && mismatch_params.empty?
powershell_script 'Trigger consul restart' do
code 'restart-service consul'
end
Expand Down Expand Up @@ -87,7 +87,7 @@ def action_disable
powershell_script 'Stop consul' do
action :run
code 'stop-service consul'
only_if { nssm_service_installed? && nssm_service_status?(%w{SERVICE_RUNNING SERVICE_PAUSED}) }
only_if { nssm_service_installed? && nssm_service_status?(%w(SERVICE_RUNNING SERVICE_PAUSED)) }
end

nssm 'consul' do
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConsulWatch < Chef::Resource

# @!attribute type
# @return [String]
attribute(:type, equal_to: %w{checks event key keyprefix nodes service services})
attribute(:type, equal_to: %w(checks event key keyprefix nodes service services))

# @!attribute parameters
# @return [Hash]
Expand Down
12 changes: 6 additions & 6 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def data_path

def command(config_file, config_dir)
if windows?
%{agent -config-file="""#{config_file}""" -config-dir="""#{config_dir}"""}
%(agent -config-file="""#{config_file}""" -config-dir="""#{config_dir}""")
else
"/usr/local/bin/consul agent -config-file=#{config_file} -config-dir=#{config_dir}"
end
Expand All @@ -57,7 +57,7 @@ def nssm_exe
end

def nssm_params
%w{Application
%w(Application
AppParameters
AppDirectory
AppExit
Expand Down Expand Up @@ -97,18 +97,18 @@ def nssm_params
ObjectName
Name
Start
Type}
Type)
end

def nssm_service_installed?
# 1 is command not found
# 3 is service not found
exit_code = shell_out!(%{"#{nssm_exe}" status consul}, returns: [0, 1, 3]).exitstatus
exit_code = shell_out!(%("#{nssm_exe}" status consul), returns: [0, 1, 3]).exitstatus
exit_code.zero?
end

def nssm_service_status?(expected_status)
expected_status.include? shell_out!(%{"#{nssm_exe}" status consul}, returns: [0]).stdout.delete("\0").strip
expected_status.include? shell_out!(%("#{nssm_exe}" status consul), returns: [0]).stdout.delete("\0").strip
end

# Returns a hash of mismatched params
Expand All @@ -117,7 +117,7 @@ def check_nssm_params
params = node['consul']['service']['nssm_params'].select { |k, _v| nssm_params.include? k.to_s }
params.each.each_with_object({}) do |(k, v), mismatch|
# shell_out! returns values with null bytes, need to delete them before we evaluate
unless shell_out!(%{"#{nssm_exe}" get consul #{k}}, returns: [0]).stdout.delete("\0").strip.eql? v.to_s
unless shell_out!(%("#{nssm_exe}" get consul #{k}), returns: [0]).stdout.delete("\0").strip.eql? v.to_s
mismatch[k] = v
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# The ruby interpreter is guaranteed to exist since it's currently running.
file "/consul_definition_check.rb" do
content (<<-EOF).gsub(/^ */, '')
file '/consul_definition_check.rb' do
content <<-EOF.gsub(/^ */, '')
/bin/sh -c 'echo "Consul check script invoked"'
EOF
unless node.platform?('windows')
Expand All @@ -13,7 +13,7 @@
consul_definition 'consul_definition_check' do
type 'check'
user 'root'
parameters(id: "consul_definition_check",
parameters(id: 'consul_definition_check',
script: '/consul_definition_check.rb',
interval: '10s',
timeout: '10s')
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/cookbooks/consul_spec/recipes/consul_watch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# The ruby interpreter is guaranteed to exist since it's currently running.
file "/consul_watch_handler.rb" do
content (<<-EOF).gsub(/^ */, '')
file '/consul_watch_handler.rb' do
content <<-EOF.gsub(/^ */, '')
/bin/sh -c 'echo "Consul watch handler invoked"'
EOF
unless node.platform?('windows')
Expand All @@ -13,6 +13,6 @@
consul_watch 'consul_watch_check' do
type 'event'
user 'root'
parameters(handler: "/consul_watch_handler.rb")
parameters(handler: '/consul_watch_handler.rb')
notifies :reload, 'consul_service[consul]', :delayed
end
6 changes: 3 additions & 3 deletions test/integration/client/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

describe command("su - consul -c 'echo successfully logged in'") do
its(:stdout) { should_not match /successfully logged in/ }
its(:stdout) { should_not include 'successfully logged in' }
its(:exit_status) { should_not eq 0 }
end

Expand All @@ -36,8 +36,8 @@

describe command("#{consul_executable} members -detailed") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match %r{\balive\b} }
its(:stdout) { should match %r{\brole=node\b} }
its(:stdout) { should include 'alive' }
its(:stdout) { should include 'role=node' }
end

describe file('/usr/local/bin/consul') do
Expand Down
10 changes: 5 additions & 5 deletions test/integration/default/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end

describe command("su - consul -c 'echo successfully logged in'") do
its(:stdout) { should_not match /successfully logged in/ }
its(:stdout) { should_not include 'successfully logged in' }
its(:exit_status) { should_not eq 0 }
end

Expand All @@ -38,10 +38,10 @@

describe command("#{consul_executable} members -detailed") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match %r{\balive\b} }
its(:stdout) { should match %r{\brole=consul\b} }
its(:stdout) { should match %r{\bbootstrap=1\b} }
its(:stdout) { should match %r{\bdc=fortmeade\b} }
its(:stdout) { should include 'alive' }
its(:stdout) { should include 'role=consul' }
its(:stdout) { should include 'bootstrap=1' }
its(:stdout) { should include 'dc=fortmeade' }
end

describe file('/usr/local/bin/consul') do
Expand Down
15 changes: 7 additions & 8 deletions test/spec/libraries/consul_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe ConsulCookbook::Resource::ConsulConfig do
step_into(:consul_config)
let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }
let(:chefspec_options) { { platform: 'ubuntu', version: '14.04' } }

before do
recipe = double('Chef::Recipe')
Expand All @@ -12,12 +12,11 @@
'service_user' => 'consul',
'service_group' => 'consul',
'service' => {
'config_dir' => '/etc/consul/conf.d'
}
}
'config_dir' => '/etc/consul/conf.d',
},
}
end


context 'sets options directly' do
recipe do
consul_config '/etc/consul/default.json' do
Expand All @@ -31,13 +30,13 @@

it do
is_expected.to create_directory('/etc/consul/conf.d')
.with(user: 'root', group: 'consul', mode: '0755')
.with(user: 'root', group: 'consul', mode: '0755')
end

it do
is_expected.to create_file('/etc/consul/default.json')
.with(user: 'root', group: 'consul', mode: '0640')
.with(content: <<-EOH.chomp.gsub(/^ /,''))
.with(user: 'root', group: 'consul', mode: '0640')
.with(content: <<-EOH.chomp.gsub(/^ /, ''))
{
"recursor": "foo",
"server": true,
Expand Down
Loading

0 comments on commit df8d1ce

Please sign in to comment.