diff --git a/.foodcritic b/.foodcritic index 2aeb36d3..76524578 100644 --- a/.foodcritic +++ b/.foodcritic @@ -1 +1,2 @@ --t ~FC001 -t ~FC054 +~FC019 +~FC044 diff --git a/.rubocop.yml b/.rubocop.yml index 1951c3bf..b355ad0c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,48 +1,5 @@ --- -AllCops: - Exclude: - - 'Rakefile' - - 'Vagrantfile' - - 'Policyfile.rb' - - 'Berksfile' - - 'Gemfile' - - 'metadata.rb' - - 'test/**/*' - - 'bin/**' - - 'vendor/**/*' -AlignParameters: - Enabled: false -ClassLength: - Enabled: false -CyclomaticComplexity: - Enabled: false -Documentation: - Enabled: false -Encoding: - Enabled: false -Style/FileName: - Enabled: false -LineLength: - Enabled: false -MethodLength: - Enabled: false -Metrics/AbcSize: - Enabled: false -PerceivedComplexity: - Enabled: false -Style/SpaceBeforeFirstArg: - Enabled: false -Style/ClassAndModuleChildren: - Enabled: false -Style/FileName: - Enabled: false Style/GuardClause: Enabled: false -Style/PercentLiteralDelimiters: - Enabled: false Style/ModuleFunction: Enabled: false -Style/AlignHash: - Enabled: false -Style/SpaceInsideHashLiteralBraces: - Enabled: false diff --git a/Rakefile b/Rakefile index 4f7d4d3d..a77c71cd 100755 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/libraries/consul_acl.rb b/libraries/consul_acl.rb index 677a4abd..917e5ae2 100644 --- a/libraries/consul_acl.rb +++ b/libraries/consul_acl.rb @@ -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] diff --git a/libraries/consul_config.rb b/libraries/consul_config.rb index 99b9f923..304604a9 100644 --- a/libraries/consul_config.rb +++ b/libraries/consul_config.rb @@ -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, _| @@ -195,7 +195,7 @@ def tls? [::File.dirname(new_resource.path), new_resource.config_dir].each do |dir| directory dir do recursive true - unless node.platform?('windows') + unless platform?('windows') owner new_resource.owner group new_resource.group mode '0755' @@ -205,7 +205,7 @@ def tls? end file new_resource.path do - unless node.platform?('windows') + unless platform?('windows') owner new_resource.owner group new_resource.group mode '0640' diff --git a/libraries/consul_definition.rb b/libraries/consul_definition.rb index 3c1d7023..cf5115f4 100644 --- a/libraries/consul_definition.rb +++ b/libraries/consul_definition.rb @@ -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] @@ -45,7 +45,7 @@ def to_json notifying_block do directory ::File.dirname(new_resource.path) do recursive true - unless node.platform?('windows') + unless platform?('windows') owner new_resource.user group new_resource.group mode '0755' @@ -57,7 +57,7 @@ def to_json file new_resource.path do content new_resource.to_json - unless node.platform?('windows') + unless platform?('windows') owner new_resource.user group new_resource.group mode '0640' diff --git a/libraries/consul_installation_binary.rb b/libraries/consul_installation_binary.rb index f4ff6878..587c999e 100644 --- a/libraries/consul_installation_binary.rb +++ b/libraries/consul_installation_binary.rb @@ -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}', @@ -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] diff --git a/libraries/consul_service.rb b/libraries/consul_service.rb index 700123d3..a4b10814 100644 --- a/libraries/consul_service.rb +++ b/libraries/consul_service.rb @@ -90,7 +90,7 @@ def service_options(service) service.options(:sysvinit, template: 'consul:sysvinit.service.erb') service.options(:upstart, template: 'consul:upstart.service.erb', executable: new_resource.program) - if node.platform_family?('rhel') && node.platform_version.to_i == 6 + if platform_family?('rhel') && node['platform_version'].to_i == 6 service.provider(:sysvinit) end end diff --git a/libraries/consul_service_windows.rb b/libraries/consul_service_windows.rb index fe1bad78..72968cd7 100644 --- a/libraries/consul_service_windows.rb +++ b/libraries/consul_service_windows.rb @@ -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 @@ -54,10 +54,9 @@ 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? - powershell_script 'Trigger consul restart' do - code 'restart-service consul' - end + powershell_script 'Trigger consul restart' do + code 'restart-service consul' + not_if { nssm_service_status?(%w(SERVICE_RUNNING)) && mismatch_params.empty? } end end end @@ -87,7 +86,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 diff --git a/libraries/consul_watch.rb b/libraries/consul_watch.rb index cfc2659e..6886742c 100644 --- a/libraries/consul_watch.rb +++ b/libraries/consul_watch.rb @@ -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] @@ -43,7 +43,7 @@ def to_json notifying_block do directory ::File.dirname(new_resource.path) do recursive true - unless node.platform?('windows') + unless platform?('windows') owner new_resource.user group new_resource.group mode '0755' @@ -52,7 +52,7 @@ def to_json file new_resource.path do content new_resource.to_json - unless node.platform?('windows') + unless platform?('windows') owner new_resource.user group new_resource.group mode '0640' diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 4dade665..c0df82e3 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -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 @@ -57,7 +57,7 @@ def nssm_exe end def nssm_params - %w{Application + %w(Application AppParameters AppDirectory AppExit @@ -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 @@ -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 diff --git a/test/fixtures/cookbooks/consul_spec/recipes/consul_definition.rb b/test/fixtures/cookbooks/consul_spec/recipes/consul_definition.rb index c18b1bed..e6a853b8 100644 --- a/test/fixtures/cookbooks/consul_spec/recipes/consul_definition.rb +++ b/test/fixtures/cookbooks/consul_spec/recipes/consul_definition.rb @@ -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') @@ -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') diff --git a/test/fixtures/cookbooks/consul_spec/recipes/consul_watch.rb b/test/fixtures/cookbooks/consul_spec/recipes/consul_watch.rb index 5c576fe3..f5f38c56 100644 --- a/test/fixtures/cookbooks/consul_spec/recipes/consul_watch.rb +++ b/test/fixtures/cookbooks/consul_spec/recipes/consul_watch.rb @@ -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') @@ -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 diff --git a/test/integration/client/default_spec.rb b/test/integration/client/default_spec.rb index 5dc7ae0f..3d98164a 100644 --- a/test/integration/client/default_spec.rb +++ b/test/integration/client/default_spec.rb @@ -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 @@ -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 diff --git a/test/integration/default/default_spec.rb b/test/integration/default/default_spec.rb index e9661405..2959def5 100644 --- a/test/integration/default/default_spec.rb +++ b/test/integration/default/default_spec.rb @@ -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 @@ -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 diff --git a/test/integration/windows/windows_spec.rb b/test/integration/windows/windows_spec.rb index 620f1a69..0aba52e8 100644 --- a/test/integration/windows/windows_spec.rb +++ b/test/integration/windows/windows_spec.rb @@ -24,10 +24,10 @@ describe command("#{consul_command} 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(config_file) do diff --git a/test/spec/libraries/consul_config_spec.rb b/test/spec/libraries/consul_config_spec.rb index 306e460f..2a1acc68 100644 --- a/test/spec/libraries/consul_config_spec.rb +++ b/test/spec/libraries/consul_config_spec.rb @@ -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') @@ -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 @@ -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, diff --git a/test/spec/libraries/consul_definition_spec.rb b/test/spec/libraries/consul_definition_spec.rb index 896c7907..5efb5542 100644 --- a/test/spec/libraries/consul_definition_spec.rb +++ b/test/spec/libraries/consul_definition_spec.rb @@ -3,15 +3,15 @@ describe ConsulCookbook::Resource::ConsulDefinition do step_into(:consul_definition) - let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} } + let(:chefspec_options) { { platform: 'ubuntu', version: '14.04' } } before do default_attributes['consul'] = { 'service_user' => 'consul', 'service_group' => 'consul', 'service' => { - 'config_dir' => '/etc/consul/conf.d' - } - } + 'config_dir' => '/etc/consul/conf.d', + }, + } end context 'service definition' do @@ -19,23 +19,23 @@ consul_definition 'redis' do type 'service' user 'root' - parameters(tags: %w{master}, address: '127.0.0.1', port: 6379, interval: '10s') + parameters(tags: %w(master), address: '127.0.0.1', port: 6379, interval: '10s') end end it { is_expected.to create_directory('/etc/consul/conf.d') } it do is_expected.to create_file('/etc/consul/conf.d/redis.json') - .with(user: 'root', group: 'consul', mode: '0640') - .with(content: JSON.pretty_generate( - service: { - tags: ['master'], - address: '127.0.0.1', - port: 6379, - interval: '10s', - name: 'redis' - } - )) + .with(user: 'root', group: 'consul', mode: '0640') + .with(content: JSON.pretty_generate( + service: { + tags: ['master'], + address: '127.0.0.1', + port: 6379, + interval: '10s', + name: 'redis', + } + )) end end @@ -44,23 +44,23 @@ consul_definition 'redis' do type 'service' user 'root' - parameters(name: 'myredis', tags: %w{master}, address: '127.0.0.1', port: 6379, interval: '10s') + parameters(name: 'myredis', tags: %w(master), address: '127.0.0.1', port: 6379, interval: '10s') end end it { is_expected.to create_directory('/etc/consul/conf.d') } it do is_expected.to create_file('/etc/consul/conf.d/redis.json') - .with(user: 'root', group: 'consul', mode: '0640') - .with(content: JSON.pretty_generate( - service: { - name: 'myredis', - tags: ['master'], - address: '127.0.0.1', - port: 6379, - interval: '10s' - } - )) + .with(user: 'root', group: 'consul', mode: '0640') + .with(content: JSON.pretty_generate( + service: { + name: 'myredis', + tags: ['master'], + address: '127.0.0.1', + port: 6379, + interval: '10s', + } + )) end end @@ -70,31 +70,31 @@ 'service_user' => 'root', 'service_group' => 'root', 'service' => { - 'config_dir' => '/etc/consul/conf.d' - } - } + 'config_dir' => '/etc/consul/conf.d', + }, + } end recipe do consul_definition 'redis' do type 'service' - parameters(name: 'myredis', tags: %w{master}, address: '127.0.0.1', port: 6379, interval: '10s') + parameters(name: 'myredis', tags: %w(master), address: '127.0.0.1', port: 6379, interval: '10s') end end it { is_expected.to create_directory('/etc/consul/conf.d') } it do is_expected.to create_file('/etc/consul/conf.d/redis.json') - .with(user: 'root', group: 'root', mode: '0640') - .with(content: JSON.pretty_generate( - service: { - name: 'myredis', - tags: ['master'], - address: '127.0.0.1', - port: 6379, - interval: '10s' - } - )) + .with(user: 'root', group: 'root', mode: '0640') + .with(content: JSON.pretty_generate( + service: { + name: 'myredis', + tags: ['master'], + address: '127.0.0.1', + port: 6379, + interval: '10s', + } + )) end end @@ -110,14 +110,14 @@ it { is_expected.to create_directory('/etc/consul/conf.d') } it do is_expected.to create_file('/etc/consul/conf.d/web-api.json') - .with(user: 'root', group: 'consul', mode: '0640') - .with(content: JSON.pretty_generate( - check: { - http: 'http://localhost:5000/health', - ttl: '30s', - name: 'web-api', - } - )) + .with(user: 'root', group: 'consul', mode: '0640') + .with(content: JSON.pretty_generate( + check: { + http: 'http://localhost:5000/health', + ttl: '30s', + name: 'web-api', + } + )) end end end diff --git a/test/spec/libraries/consul_execute_spec.rb b/test/spec/libraries/consul_execute_spec.rb index 15e8ab1d..b4036625 100644 --- a/test/spec/libraries/consul_execute_spec.rb +++ b/test/spec/libraries/consul_execute_spec.rb @@ -3,7 +3,7 @@ describe ConsulCookbook::Resource::ConsulExecute do step_into(:consul_execute) - let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} } + let(:chefspec_options) { { platform: 'ubuntu', version: '14.04' } } context 'without options' do recipe do diff --git a/test/spec/libraries/consul_service_linux_spec.rb b/test/spec/libraries/consul_service_linux_spec.rb index 8260a7a2..8dd72aac 100644 --- a/test/spec/libraries/consul_service_linux_spec.rb +++ b/test/spec/libraries/consul_service_linux_spec.rb @@ -3,7 +3,7 @@ describe ConsulCookbook::Resource::ConsulService do step_into(:consul_service) - let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} } + let(:chefspec_options) { { platform: 'ubuntu', version: '14.04' } } context 'with default properties' do recipe 'consul::default' diff --git a/test/spec/libraries/consul_service_windows_spec.rb b/test/spec/libraries/consul_service_windows_spec.rb index 27209db1..f0e77433 100644 --- a/test/spec/libraries/consul_service_windows_spec.rb +++ b/test/spec/libraries/consul_service_windows_spec.rb @@ -4,7 +4,7 @@ describe ConsulCookbook::Resource::ConsulService do step_into(:consul_service) - let(:chefspec_options) { { platform: 'windows', version: '2012R2'} } + let(:chefspec_options) { { platform: 'windows', version: '2012R2' } } let(:shellout) { double('shellout') } context 'with default properties' do @@ -25,21 +25,22 @@ recipe 'consul::default' - it { + it do skip('Add poise inversion system to consul_service otherwise windows tests will not pass') is_expected.to create_directory('C:\Program Files\consul\conf.d') - } + end - it { + it do skip('Add poise inversion system to consul_service otherwise windows tests will not pass') is_expected.to create_directory('C:\Program Files\consul\data') - } + end - it { + it do skip('Add poise inversion system to consul_service otherwise windows tests will not pass') expect(chef_run).to install_nssm('consul').with( - program: 'C:\Program Files\consul\0.7.1\consul.exe', - args: 'agent -config-file="""C:\Program Files\consul\consul.json""" -config-dir="""C:\Program Files\consul\conf.d"""' - )} + program: 'C:\Program Files\consul\0.7.1\consul.exe', + args: 'agent -config-file="""C:\Program Files\consul\consul.json""" -config-dir="""C:\Program Files\consul\conf.d"""' + ) + end end end diff --git a/test/spec/libraries/consul_watch_spec.rb b/test/spec/libraries/consul_watch_spec.rb index 2cfbd0b5..4a417178 100644 --- a/test/spec/libraries/consul_watch_spec.rb +++ b/test/spec/libraries/consul_watch_spec.rb @@ -3,13 +3,13 @@ describe ConsulCookbook::Resource::ConsulWatch do step_into(:consul_watch) - let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} } + let(:chefspec_options) { { platform: 'ubuntu', version: '14.04' } } before do default_attributes['consul'] = { 'service' => { - 'config_dir' => '/etc/consul/conf.d' - } - } + 'config_dir' => '/etc/consul/conf.d', + }, + } end context 'key watch' do @@ -24,18 +24,16 @@ it { is_expected.to create_directory('/etc/consul/conf.d') } it do is_expected.to create_file('/etc/consul/conf.d/foo.json') - .with(user: 'root', group: 'consul', mode: '0640') - .with(content: JSON.pretty_generate( - { + .with(user: 'root', group: 'consul', mode: '0640') + .with(content: JSON.pretty_generate( watches: [ { type: 'key', key: 'foo/bar/baz', - handler: '/bin/false' - } + handler: '/bin/false', + }, ] - } - )) + )) end end end diff --git a/test/spec/recipes/default_spec.rb b/test/spec/recipes/default_spec.rb index 17357c93..63d1c991 100644 --- a/test/spec/recipes/default_spec.rb +++ b/test/spec/recipes/default_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -describe "consul::default" do - let(:service_user) { } +describe 'consul::default' do + let(:service_user) {} let(:create_service_user) { true } - let(:platform) { { :platform => 'ubuntu', :version => '14.04' } } - + let(:platform) { { platform: 'ubuntu', version: '14.04' } } + let(:chef_run) do runner = ChefSpec::SoloRunner.new(platform) do |node| node.normal['consul']['service_user'] = service_user @@ -13,13 +13,13 @@ runner.converge(described_recipe) end - context "with default service_user" do + context 'with default service_user' do it 'creates the user without a login shell' do expect(chef_run).to create_poise_service_user('consul') end end - context "with johnny5 service_user" do + context 'with johnny5 service_user' do let(:service_user) { 'johnny5' } it 'creates the requested user' do @@ -30,7 +30,7 @@ end end - context "with root service_user" do + context 'with root service_user' do let(:service_user) { 'root' } it 'does not try to create the root user' do @@ -41,17 +41,17 @@ end end - context "with create_service_user disabled" do + context 'with create_service_user disabled' do let(:create_service_user) { false } it 'does not try to create the user' do expect(chef_run).to_not create_poise_service_user('consul') end end - + context 'on Windows' do - let(:platform) { { :platform => 'windows', :version => '2012R2' } } - + let(:platform) { { platform: 'windows', version: '2012R2' } } + it 'does not try to create the user' do expect(chef_run).to_not create_poise_service_user('consul') end