From b2cef0046e362b09e390d01fa6423b6a010b5d7e Mon Sep 17 00:00:00 2001 From: William Yardley Date: Tue, 29 Aug 2017 13:16:41 -0700 Subject: [PATCH 1/4] update .rubocop.yml (pre-modulesync) --- .rubocop.yml | 108 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 42 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5aadd1b64..b1a952131 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,10 +4,14 @@ AllCops: Include: - ./**/*.rb Exclude: + - files/**/* - vendor/**/* - .vendor/**/* - pkg/**/* - spec/fixtures/**/* + - Gemfile + - Rakefile + - Guardfile Lint/ConditionPosition: Enabled: True @@ -47,7 +51,7 @@ Lint/AmbiguousOperator: Lint/AssignmentInCondition: Enabled: True -Style/SpaceBeforeComment: +Layout/SpaceBeforeComment: Enabled: True Style/AndOr: @@ -56,6 +60,9 @@ Style/AndOr: Style/RedundantSelf: Enabled: True +Metrics/BlockLength: + Enabled: False + # Method length is not necessarily an indicator of code quality Metrics/MethodLength: Enabled: False @@ -70,7 +77,7 @@ Style/WhileUntilModifier: Lint/AmbiguousRegexpLiteral: Enabled: True -Lint/Eval: +Security/Eval: Enabled: True Lint/BlockAlignment: @@ -112,7 +119,7 @@ Lint/UselessAssignment: Lint/Void: Enabled: True -Style/AccessModifierIndentation: +Layout/AccessModifierIndentation: Enabled: True Style/AccessorMethodName: @@ -121,13 +128,13 @@ Style/AccessorMethodName: Style/Alias: Enabled: True -Style/AlignArray: +Layout/AlignArray: Enabled: True -Style/AlignHash: +Layout/AlignHash: Enabled: True -Style/AlignParameters: +Layout/AlignParameters: Enabled: True Metrics/BlockNesting: @@ -145,7 +152,7 @@ Style/BracesAroundHashParameters: Style/CaseEquality: Enabled: True -Style/CaseIndentation: +Layout/CaseIndentation: Enabled: True Style/CharacterLiteral: @@ -179,64 +186,64 @@ Style/WordArray: Style/UnneededPercentQ: Enabled: True -Style/Tab: +Layout/Tab: Enabled: True -Style/SpaceBeforeSemicolon: +Layout/SpaceBeforeSemicolon: Enabled: True -Style/TrailingBlankLines: +Layout/TrailingBlankLines: Enabled: True -Style/SpaceInsideBlockBraces: +Layout/SpaceInsideBlockBraces: Enabled: True -Style/SpaceInsideBrackets: +Layout/SpaceInsideBrackets: Enabled: True -Style/SpaceInsideHashLiteralBraces: +Layout/SpaceInsideHashLiteralBraces: Enabled: True -Style/SpaceInsideParens: +Layout/SpaceInsideParens: Enabled: True -Style/LeadingCommentSpace: +Layout/LeadingCommentSpace: Enabled: True -Style/SpaceBeforeFirstArg: +Layout/SpaceBeforeFirstArg: Enabled: True -Style/SpaceAfterColon: +Layout/SpaceAfterColon: Enabled: True -Style/SpaceAfterComma: +Layout/SpaceAfterComma: Enabled: True -Style/SpaceAfterMethodName: +Layout/SpaceAfterMethodName: Enabled: True -Style/SpaceAfterNot: +Layout/SpaceAfterNot: Enabled: True -Style/SpaceAfterSemicolon: +Layout/SpaceAfterSemicolon: Enabled: True -Style/SpaceAroundEqualsInParameterDefault: +Layout/SpaceAroundEqualsInParameterDefault: Enabled: True -Style/SpaceAroundOperators: +Layout/SpaceAroundOperators: Enabled: True -Style/SpaceBeforeBlockBraces: +Layout/SpaceBeforeBlockBraces: Enabled: True -Style/SpaceBeforeComma: +Layout/SpaceBeforeComma: Enabled: True Style/CollectionMethods: Enabled: True -Style/CommentIndentation: +Layout/CommentIndentation: Enabled: True Style/ColonMethodCall: @@ -261,7 +268,7 @@ Style/DefWithParentheses: Style/PreferredHashMethods: Enabled: True -Style/DotPosition: +Layout/DotPosition: EnforcedStyle: trailing Style/DoubleNegation: @@ -270,25 +277,25 @@ Style/DoubleNegation: Style/EachWithObject: Enabled: True -Style/EmptyLineBetweenDefs: +Layout/EmptyLineBetweenDefs: Enabled: True -Style/IndentArray: +Layout/IndentArray: Enabled: True -Style/IndentHash: +Layout/IndentHash: Enabled: True -Style/IndentationConsistency: +Layout/IndentationConsistency: Enabled: True -Style/IndentationWidth: +Layout/IndentationWidth: Enabled: True -Style/EmptyLines: +Layout/EmptyLines: Enabled: True -Style/EmptyLinesAroundAccessModifier: +Layout/EmptyLinesAroundAccessModifier: Enabled: True Style/EmptyLiteral: @@ -298,7 +305,7 @@ Style/EmptyLiteral: Metrics/LineLength: Enabled: False -Style/MethodCallParentheses: +Style/MethodCallWithoutArgsParentheses: Enabled: True Style/MethodDefParentheses: @@ -307,7 +314,7 @@ Style/MethodDefParentheses: Style/LineEndConcatenation: Enabled: True -Style/TrailingWhitespace: +Layout/TrailingWhitespace: Enabled: True Style/StringLiterals: @@ -459,9 +466,6 @@ Metrics/ParameterLists: Lint/RequireParentheses: Enabled: True -Style/SpaceBeforeFirstArg: - Enabled: True - Style/ModuleFunction: Enabled: True @@ -477,7 +481,7 @@ Style/Encoding: Style/BlockDelimiters: Enabled: True -Style/MultilineBlockLayout: +Layout/MultilineBlockLayout: Enabled: True # 'Complexity' is very relative @@ -491,11 +495,15 @@ Metrics/PerceivedComplexity: Lint/UselessAssignment: Enabled: True -Style/ClosingParenthesisIndentation: - Enabled: False +Layout/ClosingParenthesisIndentation: + Enabled: True # RSpec +RSpec/BeforeAfterAll: + Exclude: + - spec/acceptance/**/* + # We don't use rspec in this way RSpec/DescribeClass: Enabled: False @@ -506,3 +514,19 @@ RSpec/ExampleLength: RSpec/NamedSubject: Enabled: False + +# disabled for now since they cause a lot of issues +# these issues aren't easy to fix +RSpec/RepeatedDescription: + Enabled: False + +RSpec/NestedGroups: + Enabled: False + +# this is broken on ruby1.9 +Layout/IndentHeredoc: + Enabled: False + +# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs +Security/YAMLLoad: + Enabled: false From 9a9d551f800e4a03f2b77ad195c395e943fceddd Mon Sep 17 00:00:00 2001 From: William Yardley Date: Tue, 29 Aug 2017 13:19:04 -0700 Subject: [PATCH 2/4] transpec auto-updates to spec syntax --- spec/acceptance/class_spec.rb | 38 +- spec/acceptance/clustering_spec.rb | 16 +- spec/acceptance/delete_guest_user_spec.rb | 4 +- spec/acceptance/rabbitmqadmin_spec.rb | 6 +- spec/acceptance/server_spec.rb | 14 +- spec/classes/rabbitmq_spec.rb | 342 +++++++++--------- .../rabbitmq_binding/rabbitmqadmin_spec.rb | 16 +- .../rabbitmq_exchange/rabbitmqadmin_spec.rb | 2 +- .../rabbitmq_parameter/rabbitmqctl_spec.rb | 10 +- .../rabbitmq_plugin/rabbitmqctl_spec.rb | 2 +- .../rabbitmq_policy/rabbitmqctl_spec.rb | 14 +- .../rabbitmq_queue/rabbitmqadmin_spec.rb | 2 +- .../rabbitmq_user/rabbitmqctl_spec.rb | 18 +- .../rabbitmqctl_spec.rb | 10 +- .../rabbitmq_vhost/rabbitmqctl_spec.rb | 6 +- .../unit/puppet/type/rabbitmq_binding_spec.rb | 8 +- .../puppet/type/rabbitmq_exchange_spec.rb | 8 +- .../puppet/type/rabbitmq_parameter_spec.rb | 14 +- spec/unit/puppet/type/rabbitmq_plugin_spec.rb | 4 +- spec/unit/puppet/type/rabbitmq_policy_spec.rb | 44 +-- spec/unit/puppet/type/rabbitmq_queue_spec.rb | 14 +- .../type/rabbitmq_user_permissions_spec.rb | 12 +- spec/unit/puppet/type/rabbitmq_user_spec.rb | 8 +- spec/unit/puppet/type/rabbitmq_vhost_spec.rb | 2 +- 24 files changed, 307 insertions(+), 307 deletions(-) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index a54194918..5e19f6235 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -32,12 +32,12 @@ class { 'erlang': epel_enable => true} end describe package(package_name) do - it { should be_installed } + it { is_expected.to be_installed } end describe service(service_name) do - it { should be_enabled } - it { should be_running } + it { is_expected.to be_enabled } + it { is_expected.to be_running } end end @@ -57,8 +57,8 @@ class { 'erlang': epel_enable => true} end describe service(service_name) do - it { should_not be_enabled } - it { should_not be_running } + it { is_expected.not_to be_enabled } + it { is_expected.not_to be_running } end end @@ -88,8 +88,8 @@ class { 'erlang': epel_enable => true} end describe service(service_name) do - it { should be_enabled } - it { should be_running } + it { is_expected.to be_enabled } + it { is_expected.to be_running } end end @@ -108,17 +108,17 @@ class { 'rabbitmq': end describe service(service_name) do - it { should be_running } + it { is_expected.to be_running } end describe port(5672) do - it { should be_listening.on('0.0.0.0').with('tcp') } + it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end describe port(15672) do - it { should be_listening.on('0.0.0.0').with('tcp') } + it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end describe port(25672) do xit "Is on 55672 instead on older rmq versions" do - should be_listening.on('0.0.0.0').with('tcp') + is_expected.to be_listening.on('0.0.0.0').with('tcp') end end end @@ -138,18 +138,18 @@ class { 'rabbitmq': end describe service(service_name) do - it { should be_running } + it { is_expected.to be_running } end describe port(5672) do - it { should be_listening.on('127.0.0.1').with('tcp') } + it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end describe port(15672) do - it { should be_listening.on('127.0.0.1').with('tcp') } + it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end # This listens on all interfaces regardless of these settings describe port(25672) do xit "Is on 55672 instead on older rmq versions" do - should be_listening.on('0.0.0.0').with('tcp') + is_expected.to be_listening.on('0.0.0.0').with('tcp') end end end @@ -170,17 +170,17 @@ class { 'rabbitmq': end describe service(service_name) do - it { should be_running } + it { is_expected.to be_running } end describe port(5672) do - it { should be_listening.on('0.0.0.0').with('tcp') } + it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end describe port(15672) do - it { should be_listening.on('127.0.0.1').with('tcp') } + it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end describe port(25672) do xit "Is on 55672 instead on older rmq versions" do - should be_listening.on('0.0.0.0').with('tcp') + is_expected.to be_listening.on('0.0.0.0').with('tcp') end end end diff --git a/spec/acceptance/clustering_spec.rb b/spec/acceptance/clustering_spec.rb index 438c65ba1..274284be9 100644 --- a/spec/acceptance/clustering_spec.rb +++ b/spec/acceptance/clustering_spec.rb @@ -21,7 +21,7 @@ class { 'erlang': epel_enable => true} end describe file('/var/lib/rabbitmq/.erlang.cookie') do - it { should_not contain 'TESTCOOKIE' } + it { is_expected.not_to contain 'TESTCOOKIE' } end end @@ -45,16 +45,16 @@ class { 'erlang': epel_enable => true} end describe file('/etc/rabbitmq/rabbitmq.config') do - it { should be_file } - it { should contain 'cluster_nodes' } - it { should contain 'rabbit@rabbit1' } - it { should contain 'rabbit@rabbit2' } - it { should contain 'ram' } + it { is_expected.to be_file } + it { is_expected.to contain 'cluster_nodes' } + it { is_expected.to contain 'rabbit@rabbit1' } + it { is_expected.to contain 'rabbit@rabbit2' } + it { is_expected.to contain 'ram' } end describe file('/var/lib/rabbitmq/.erlang.cookie') do - it { should be_file } - it { should contain 'TESTCOOKIE' } + it { is_expected.to be_file } + it { is_expected.to contain 'TESTCOOKIE' } end end end diff --git a/spec/acceptance/delete_guest_user_spec.rb b/spec/acceptance/delete_guest_user_spec.rb index 1060eb1da..6d2494248 100644 --- a/spec/acceptance/delete_guest_user_spec.rb +++ b/spec/acceptance/delete_guest_user_spec.rb @@ -19,8 +19,8 @@ class { 'erlang': epel_enable => true} end describe file('/tmp/rabbitmqctl_users') do - it { should be_file } - it { should_not contain 'guest' } + it { is_expected.to be_file } + it { is_expected.not_to contain 'guest' } end end end diff --git a/spec/acceptance/rabbitmqadmin_spec.rb b/spec/acceptance/rabbitmqadmin_spec.rb index dcf62402d..ecd603c5c 100644 --- a/spec/acceptance/rabbitmqadmin_spec.rb +++ b/spec/acceptance/rabbitmqadmin_spec.rb @@ -18,7 +18,7 @@ class { 'erlang': epel_enable => true} end describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should be_file } + it { is_expected.to be_file } end end @@ -40,7 +40,7 @@ class { 'erlang': epel_enable => true} end describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should_not be_file } + it { is_expected.not_to be_file } end end @@ -78,7 +78,7 @@ class { 'erlang': epel_enable => true} end describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should be_file } + it { is_expected.to be_file } end end diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index d99f995db..89929b44a 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -32,12 +32,12 @@ class { 'erlang': epel_enable => true} end describe package(package_name) do - it { should be_installed } + it { is_expected.to be_installed } end describe service(service_name) do - it { should be_enabled } - it { should be_running } + it { is_expected.to be_enabled } + it { is_expected.to be_running } end end @@ -57,8 +57,8 @@ class { 'erlang': epel_enable => true} end describe service(service_name) do - it { should_not be_enabled } - it { should_not be_running } + it { is_expected.not_to be_enabled } + it { is_expected.not_to be_running } end end @@ -89,8 +89,8 @@ class { 'erlang': epel_enable => true} end describe service(service_name) do - it { should be_enabled } - it { should be_running } + it { is_expected.to be_enabled } + it { is_expected.to be_running } end end end diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index d6fc34f9d..189a17efe 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -13,11 +13,11 @@ context 'on Debian' do with_debian_facts it 'should not include rabbitmq::repo::apt' do - should_not contain_class('rabbitmq::repo::apt') + is_expected.not_to contain_class('rabbitmq::repo::apt') end it 'does ensure rabbitmq apt::source is absent when repos_ensure is false' do - should_not contain_apt__source('rabbitmq') + is_expected.not_to contain_apt__source('rabbitmq') end end @@ -26,12 +26,12 @@ with_debian_facts it 'includes rabbitmq::repo::apt' do - should contain_class('rabbitmq::repo::apt') + is_expected.to contain_class('rabbitmq::repo::apt') end describe 'apt::source default values' do it 'should add a repo with default values' do - should contain_apt__source('rabbitmq').with( { + is_expected.to contain_apt__source('rabbitmq').with( { :ensure => 'present', :location => 'http://www.rabbitmq.com/debian/', :release => 'testing', @@ -42,27 +42,27 @@ context 'with file_limit => unlimited' do let(:params) {{ :file_limit => 'unlimited' }} - it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n unlimited/) } + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n unlimited/) } end context 'with file_limit => infinity' do let(:params) {{ :file_limit => 'infinity' }} - it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n infinity/) } + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n infinity/) } end context 'with file_limit => \'-1\'' do let(:params) {{ :file_limit => '-1' }} - it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n -1/) } + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n -1/) } end context 'with file_limit => \'1234\'' do let(:params) {{ :file_limit => '1234' }} - it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) } + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) } end context 'with file_limit => 1234' do let(:params) {{ :file_limit => 1234 }} - it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) } + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) } end context 'with file_limit => \'-42\'' do @@ -83,12 +83,12 @@ context 'on Redhat' do with_redhat_facts it 'should not include rabbitmq::repo::rhel' do - should_not contain_class('rabbitmq::repo::rhel') + is_expected.not_to contain_class('rabbitmq::repo::rhel') end context 'with file_limit => \'unlimited\'' do let(:params) {{ :file_limit => 'unlimited' }} - it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -101,7 +101,7 @@ context 'with file_limit => \'infinity\'' do let(:params) {{ :file_limit => 'infinity' }} - it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -114,7 +114,7 @@ context 'with file_limit => \'-1\'' do let(:params) {{ :file_limit => '-1' }} - it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -127,7 +127,7 @@ context 'with file_limit => \'1234\'' do let(:params) {{ :file_limit => '1234' }} - it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -157,10 +157,10 @@ let(:params) {{ :repos_ensure => false }} with_redhat_facts it 'does not contain class rabbitmq::repo::rhel when repos_ensure is false' do - should_not contain_class('rabbitmq::repo::rhel') + is_expected.not_to contain_class('rabbitmq::repo::rhel') end it 'should not contain "rabbitmq" repo' do - should_not contain_yumrepo('rabbitmq') + is_expected.not_to contain_yumrepo('rabbitmq') end end @@ -168,13 +168,13 @@ let(:params) {{ :repos_ensure => true }} with_redhat_facts it 'should contain class rabbitmq::repo::rhel' do - should contain_class('rabbitmq::repo::rhel') + is_expected.to contain_class('rabbitmq::repo::rhel') end it 'should contain "rabbitmq" repo' do - should contain_yumrepo('rabbitmq') + is_expected.to contain_yumrepo('rabbitmq') end it 'the repo should be present, and contain the expected values' do - should contain_yumrepo('rabbitmq').with( { + is_expected.to contain_yumrepo('rabbitmq').with( { :ensure => 'present', :baseurl => 'https://packagecloud.io/rabbitmq/rabbitmq-server/el/$releasever/$basearch', :gpgkey => 'https://www.rabbitmq.com/rabbitmq-release-signing-key.asc', @@ -185,7 +185,7 @@ context 'on RedHat 7.0 or higher' do with_redhat_facts - it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d').with( + it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d').with( 'ensure' => 'directory', 'owner' => '0', 'group' => '0', @@ -193,14 +193,14 @@ 'selinux_ignore_defaults' => true ) } - it { should contain_exec('rabbitmq-systemd-reload').with( + it { is_expected.to contain_exec('rabbitmq-systemd-reload').with( 'command' => '/usr/bin/systemctl daemon-reload', 'notify' => 'Class[Rabbitmq::Service]', 'refreshonly' => true ) } context 'with file_limit => \'unlimited\'' do let(:params) {{ :file_limit => 'unlimited' }} - it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -213,7 +213,7 @@ context 'with file_limit => \'infinity\'' do let(:params) {{ :file_limit => 'infinity' }} - it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -226,7 +226,7 @@ context 'with file_limit => \'-1\'' do let(:params) {{ :file_limit => '-1' }} - it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -239,7 +239,7 @@ context 'with file_limit => \'1234\'' do let(:params) {{ :file_limit => '1234' }} - it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( 'owner' => '0', 'group' => '0', 'mode' => '0644', @@ -273,37 +273,37 @@ context "on #{distro}" do with_distro_facts distro - it { should contain_class('rabbitmq::install') } - it { should contain_class('rabbitmq::config') } - it { should contain_class('rabbitmq::service') } + it { is_expected.to contain_class('rabbitmq::install') } + it { is_expected.to contain_class('rabbitmq::config') } + it { is_expected.to contain_class('rabbitmq::service') } context 'with admin_enable set to true' do let(:params) {{ :admin_enable => true, :management_ip_address => '1.1.1.1' }} context 'with service_manage set to true' do it 'we enable the admin interface by default' do - should contain_class('rabbitmq::install::rabbitmqadmin') - should contain_rabbitmq_plugin('rabbitmq_management').with( + is_expected.to contain_class('rabbitmq::install::rabbitmqadmin') + is_expected.to contain_rabbitmq_plugin('rabbitmq_management').with( 'require' => 'Class[Rabbitmq::Install]', 'notify' => 'Class[Rabbitmq::Service]' ) - should contain_staging__file('rabbitmqadmin').with_source("http://1.1.1.1:15672/cli/rabbitmqadmin") + is_expected.to contain_staging__file('rabbitmqadmin').with_source("http://1.1.1.1:15672/cli/rabbitmqadmin") end end context 'with $management_ip_address undef and service_manage set to true' do let(:params) {{ :admin_enable => true, :management_ip_address => :undef }} it 'we enable the admin interface by default' do - should contain_class('rabbitmq::install::rabbitmqadmin') - should contain_rabbitmq_plugin('rabbitmq_management').with( + is_expected.to contain_class('rabbitmq::install::rabbitmqadmin') + is_expected.to contain_rabbitmq_plugin('rabbitmq_management').with( 'require' => 'Class[Rabbitmq::Install]', 'notify' => 'Class[Rabbitmq::Service]' ) - should contain_staging__file('rabbitmqadmin').with_source("http://127.0.0.1:15672/cli/rabbitmqadmin") + is_expected.to contain_staging__file('rabbitmqadmin').with_source("http://127.0.0.1:15672/cli/rabbitmqadmin") end end context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified' do let(:params) {{ :admin_enable => true, :default_user => 'foobar', :default_pass => 'hunter2', :node_ip_address => :undef }} it 'we use the correct URL to rabbitmqadmin' do - should contain_staging__file('rabbitmqadmin').with( + is_expected.to contain_staging__file('rabbitmqadmin').with( :source => 'http://127.0.0.1:15672/cli/rabbitmqadmin', :curl_option => '-u "foobar:hunter2" -k --retry 30 --retry-delay 6', ) @@ -312,7 +312,7 @@ context 'with service_manage set to true and default user/pass specified' do let(:params) {{ :admin_enable => true, :default_user => 'foobar', :default_pass => 'hunter2', :management_ip_address => '1.1.1.1' }} it 'we use the correct URL to rabbitmqadmin' do - should contain_staging__file('rabbitmqadmin').with( + is_expected.to contain_staging__file('rabbitmqadmin').with( :source => 'http://1.1.1.1:15672/cli/rabbitmqadmin', :curl_option => '-u "foobar:hunter2" -k --noproxy 1.1.1.1 --retry 30 --retry-delay 6', ) @@ -322,7 +322,7 @@ # note that the 2.x management port is 55672 not 15672 let(:params) {{ :admin_enable => true, :management_port => 55672, :management_ip_address => '1.1.1.1' }} it 'we use the correct URL to rabbitmqadmin' do - should contain_staging__file('rabbitmqadmin').with( + is_expected.to contain_staging__file('rabbitmqadmin').with( :source => 'http://1.1.1.1:55672/cli/rabbitmqadmin', :curl_option => '-u "guest:guest" -k --noproxy 1.1.1.1 --retry 30 --retry-delay 6', ) @@ -332,7 +332,7 @@ # note that the 2.x management port is 55672 not 15672 let(:params) {{ :admin_enable => true, :management_port => 55672, :management_ip_address => '::1' }} it 'we use the correct URL to rabbitmqadmin' do - should contain_staging__file('rabbitmqadmin').with( + is_expected.to contain_staging__file('rabbitmqadmin').with( :source => 'http://[::1]:55672/cli/rabbitmqadmin', :curl_option => '-u "guest:guest" -k --noproxy ::1 -g -6 --retry 30 --retry-delay 6', ) @@ -341,21 +341,21 @@ context 'with service_manage set to false' do let(:params) {{ :admin_enable => true, :service_manage => false }} it 'should do nothing' do - should_not contain_class('rabbitmq::install::rabbitmqadmin') - should_not contain_rabbitmq_plugin('rabbitmq_management') + is_expected.not_to contain_class('rabbitmq::install::rabbitmqadmin') + is_expected.not_to contain_rabbitmq_plugin('rabbitmq_management') end end end describe 'manages configuration directory correctly' do - it { should contain_file('/etc/rabbitmq').with( + it { is_expected.to contain_file('/etc/rabbitmq').with( 'ensure' => 'directory', 'mode' => '0755' )} end describe 'manages configuration file correctly' do - it { should contain_file('rabbitmq.config').with( + it { is_expected.to contain_file('rabbitmq.config').with( 'owner' => '0', 'group' => 'rabbitmq', 'mode' => '0640' @@ -379,7 +379,7 @@ :wipe_db_on_cookie_change => true }} it 'contains the rabbitmq_erlang_cookie' do - should contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') + is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') end end @@ -389,7 +389,7 @@ :erlang_cookie => 'TESTCOOKIE', }} it 'contains the rabbitmq_erlang_cookie' do - should contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') + is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') end end @@ -398,7 +398,7 @@ :config_cluster => false, }} it 'contains the rabbitmq_erlang_cookie' do - should_not contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') + is_expected.not_to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') end end @@ -411,7 +411,7 @@ :wipe_db_on_cookie_change => true }} it 'for cluster_nodes' do - should contain_file('rabbitmq.config').with({ + is_expected.to contain_file('rabbitmq.config').with({ 'content' => /cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram/, }) end @@ -423,7 +423,7 @@ context 'with default params' do it 'should set environment variables' do - should contain_file('rabbitmq-env.config') \ + is_expected.to contain_file('rabbitmq-env.config') \ .with_content(%r{ERL_INETRC=/etc/rabbitmq/inetrc}) end end @@ -440,7 +440,7 @@ 'SERVER_START_ARGS' => 'debug' }}} it 'should set environment variables' do - should contain_file('rabbitmq-env.config') \ + is_expected.to contain_file('rabbitmq-env.config') \ .with_content(/NODE_IP_ADDRESS=1.1.1.1/) \ .with_content(/NODE_PORT=5656/) \ .with_content(/NODENAME=HOSTNAME/) \ @@ -455,13 +455,13 @@ context 'delete_guest_user' do describe 'should do nothing by default' do - it { should_not contain_rabbitmq_user('guest') } + it { is_expected.not_to contain_rabbitmq_user('guest') } end describe 'delete user when delete_guest_user set' do let(:params) {{ :delete_guest_user => true }} it 'removes the user' do - should contain_rabbitmq_user('guest').with( + is_expected.to contain_rabbitmq_user('guest').with( 'ensure' => 'absent', 'provider' => 'rabbitmqctl' ) @@ -473,21 +473,21 @@ describe 'node_ip_address when set' do let(:params) {{ :node_ip_address => '172.0.0.1' }} it 'should set NODE_IP_ADDRESS to specified value' do - should contain_file('rabbitmq-env.config'). + is_expected.to contain_file('rabbitmq-env.config'). with_content(%r{NODE_IP_ADDRESS=172\.0\.0\.1}) end end describe 'stomp by default' do it 'should not specify stomp parameters in rabbitmq.config' do - should contain_file('rabbitmq.config').without({ + is_expected.to contain_file('rabbitmq.config').without({ 'content' => /stomp/,}) end end describe 'stomp when set' do let(:params) {{ :config_stomp => true, :stomp_port => 5679 }} it 'should specify stomp port in rabbitmq.config' do - should contain_file('rabbitmq.config').with({ + is_expected.to contain_file('rabbitmq.config').with({ 'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\]/m, }) end @@ -495,7 +495,7 @@ describe 'stomp when set ssl port w/o ssl enabled' do let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => false, :ssl_stomp_port => 5680 }} it 'should not configure ssl_listeners in rabbitmq.config' do - should contain_file('rabbitmq.config').without({ + is_expected.to contain_file('rabbitmq.config').without({ 'content' => /rabbitmq_stomp.*ssl_listeners, \[5680\]/m, }) end @@ -503,7 +503,7 @@ describe 'stomp when set with ssl' do let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => true, :ssl_stomp_port => 5680 }} it 'should specify stomp port and ssl stomp port in rabbitmq.config' do - should contain_file('rabbitmq.config').with({ + is_expected.to contain_file('rabbitmq.config').with({ 'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]/m, }) end @@ -524,7 +524,7 @@ } end - it { should contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') } + it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') } it 'should contain ldap parameters' do verify_contents(catalogue, 'rabbitmq.config', @@ -550,7 +550,7 @@ } end - it { should contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') } + it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') } it 'should contain ldap parameters' do verify_contents(catalogue, 'rabbitmq.config', @@ -590,9 +590,9 @@ } end - it { should contain_rabbitmq_plugin('rabbitmq_shovel') } + it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel') } - it { should contain_rabbitmq_plugin('rabbitmq_shovel_management') } + it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel_management') } describe 'with admin_enable false' do let :params do @@ -602,7 +602,7 @@ } end - it { should_not contain_rabbitmq_plugin('rabbitmq_shovel_management') } + it { is_expected.not_to contain_rabbitmq_plugin('rabbitmq_shovel_management') } end describe 'with static shovels' do @@ -642,9 +642,9 @@ } end - it { should contain_rabbitmq_plugin('rabbitmq_shovel') } + it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel') } - it { should contain_rabbitmq_plugin('rabbitmq_shovel_management') } + it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel_management') } describe 'with admin_enable false' do let :params do @@ -654,7 +654,7 @@ } end - it { should_not contain_rabbitmq_plugin('rabbitmq_shovel_management') } + it { is_expected.not_to contain_rabbitmq_plugin('rabbitmq_shovel_management') } end describe 'with static shovels' do @@ -690,7 +690,7 @@ describe 'default_user and default_pass set' do let(:params) {{ :default_user => 'foo', :default_pass => 'bar' }} it 'should set default_user and default_pass to specified values' do - should contain_file('rabbitmq.config').with({ + is_expected.to contain_file('rabbitmq.config').with({ 'content' => /default_user, <<"foo">>.*default_pass, <<"bar">>/m, }) end @@ -702,7 +702,7 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\{"0.0.0.0", 5672\}\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\{"0.0.0.0", 5672\}\]}) end end @@ -718,27 +718,27 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_listeners, \[3141\]} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_options, \[} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{cacertfile,"/path/to/cacert"} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{certfile,"/path/to/cert"} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{keyfile,"/path/to/key"} ) end it 'should set non ssl port for management port' do - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{port, 13142} ) - should contain_file('rabbitmqadmin.conf').with_content( + is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{port\s=\s13142} ) end @@ -756,44 +756,44 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_listeners, \[3141\]} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_opts, } ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_options, \[} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{cacertfile,"/path/to/cacert"} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{certfile,"/path/to/cert"} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{keyfile,"/path/to/key"} ) end it 'should set ssl managment port to specified values' do - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{port, 13141} ) end it 'should set ssl options in the rabbitmqadmin.conf' do - should contain_file('rabbitmqadmin.conf').with_content( + is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{ssl_ca_cert_file\s=\s/path/to/cacert} ) - should contain_file('rabbitmqadmin.conf').with_content( + is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{ssl_cert_file\s=\s/path/to/cert} ) - should contain_file('rabbitmqadmin.conf').with_content( + is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{ssl_key_file\s=\s/path/to/key} ) - should contain_file('rabbitmqadmin.conf').with_content( + is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{hostname\s=\s} ) - should contain_file('rabbitmqadmin.conf').with_content( + is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{port\s=\s13141} ) end @@ -809,19 +809,19 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_listeners, \[3141\]} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_options, \[} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{cacertfile,"/path/to/cacert"} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{certfile,"/path/to/cert"} ) - should contain_file('rabbitmq.config').with_content( + is_expected.to contain_file('rabbitmq.config').with_content( %r{keyfile,"/path/to/key"} ) end @@ -839,10 +839,10 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) - should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) - should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) end end @@ -859,15 +859,15 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]}) - should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]}) - should contain_file('rabbitmq.config').with_content(%r{ssl_options, \[}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) - should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) - should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_options, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) end it 'should not set TCP listener environment defaults' do - should contain_file('rabbitmq-env.config') \ + is_expected.to contain_file('rabbitmq-env.config') \ .without_content(%r{NODE_PORT=}) \ .without_content(%r{NODE_IP_ADDRESS=}) end @@ -885,11 +885,11 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]}) - should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) - should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) - should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) end end @@ -904,13 +904,13 @@ } } it 'should set ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]}) - should contain_file('rabbitmq.config').with_content(%r{ssl_options, \[}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) - should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) - should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) - should contain_file('rabbitmq.config').with_content(%r{ssl, \[\{versions, \['tlsv1.1', 'tlsv1.2'\]\}\]}) - should contain_file('rabbitmq.config').with_content(%r{versions, \['tlsv1.1', 'tlsv1.2'\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_options, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, \[\{versions, \['tlsv1.1', 'tlsv1.2'\]\}\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{versions, \['tlsv1.1', 'tlsv1.2'\]}) end end @@ -940,7 +940,7 @@ } } it 'should set ssl ciphers to specified values' do - should contain_file('rabbitmq.config').with_content(%r{ciphers,\[[[:space:]]+{dhe_rsa,aes_256_cbc,sha},[[:space:]]+{ecdhe_rsa,aes_256_cbc,sha}[[:space:]]+\]}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ciphers,\[[[:space:]]+{dhe_rsa,aes_256_cbc,sha},[[:space:]]+{ecdhe_rsa,aes_256_cbc,sha}[[:space:]]+\]}) end end @@ -956,15 +956,15 @@ } } it 'should set admin ssl opts to specified values' do - should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) - should contain_file('rabbitmq.config').with_content(%r{listener, \[}) - should contain_file('rabbitmq.config').with_content(%r{port, 5926\}}) - should contain_file('rabbitmq.config').with_content(%r{ssl, true\}}) - should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},}) - should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},}) - should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}}) - should contain_file('rabbitmq.config').with_content(%r{,\{versions, \['tlsv1.1', 'tlsv1.2'\]\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 5926\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, true\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{,\{versions, \['tlsv1.1', 'tlsv1.2'\]\}}) end end @@ -979,14 +979,14 @@ } } it 'should set rabbitmq_management ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) - should contain_file('rabbitmq.config').with_content(%r{listener, \[}) - should contain_file('rabbitmq.config').with_content(%r{port, 3141\}}) - should contain_file('rabbitmq.config').with_content(%r{ssl, true\}}) - should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},}) - should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},}) - should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, true\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}}) end end @@ -998,9 +998,9 @@ } } it 'should set rabbitmq_management options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) - should contain_file('rabbitmq.config').with_content(%r{listener, \[}) - should contain_file('rabbitmq.config').with_content(%r{port, 3141\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\}}) end end @@ -1015,14 +1015,14 @@ } } it 'should set rabbitmq_management ssl options to specified values' do - should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) - should contain_file('rabbitmq.config').with_content(%r{listener, \[}) - should contain_file('rabbitmq.config').with_content(%r{port, 3141\},}) - should contain_file('rabbitmq.config').with_content(%r{ssl, true\},}) - should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[}) - should contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},}) - should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},}) - should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, true\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},}) + is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}}) end end @@ -1034,7 +1034,7 @@ } } it 'should set rabbitmq_management options to specified values' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{rabbitmq_management, \[/) \ .with_content(/\{listener, \[/) \ .with_content(/\{port, 3141\}/) @@ -1045,12 +1045,12 @@ let(:params) { { :ipv6 => true } } it 'should enable resolver inet6 in inetrc' do - should contain_file('rabbitmq-inetrc').with_content(%r{{inet6, true}.}) + is_expected.to contain_file('rabbitmq-inetrc').with_content(%r{{inet6, true}.}) end context 'without other erl args' do it 'should enable inet6 distribution' do - should contain_file('rabbitmq-env.config') \ + is_expected.to contain_file('rabbitmq-env.config') \ .with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="-proto_dist inet6_tcp"$}) \ .with_content(%r{^RABBITMQ_CTL_ERL_ARGS="-proto_dist inet6_tcp"$}) end @@ -1064,7 +1064,7 @@ } it 'should enable inet6 distribution and quote properly' do - should contain_file('rabbitmq-env.config') \ + is_expected.to contain_file('rabbitmq-env.config') \ .with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="some quoted args -proto_dist inet6_tcp"$}) \ .with_content(%r{^RABBITMQ_CTL_ERL_ARGS="other quoted args -proto_dist inet6_tcp"$}) end @@ -1078,7 +1078,7 @@ } it 'should enable inet6 distribution and quote properly' do - should contain_file('rabbitmq-env.config') \ + is_expected.to contain_file('rabbitmq-env.config') \ .with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="foo -proto_dist inet6_tcp"$}) \ .with_content(%r{^RABBITMQ_CTL_ERL_ARGS="bar -proto_dist inet6_tcp"$}) end @@ -1095,7 +1095,7 @@ 'auth_mechanisms' => "['PLAIN', 'AMQPLAIN']", }}} it 'should set environment variables' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{hipe_compile, true\}/) \ .with_content(/\{vm_memory_high_watermark, 0.4\}/) \ .with_content(/\{frame_max, 131072\}/) \ @@ -1110,7 +1110,7 @@ 'inet_dist_listen_max' => 9105, }}} it 'should set config variables' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{inet_dist_listen_min, 9100\}/) \ .with_content(/\{inet_dist_listen_max, 9105\}/) end @@ -1121,7 +1121,7 @@ 'rates_mode' => 'none', }}} it 'should set config variables' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{rates_mode, none\}/) end end @@ -1129,21 +1129,21 @@ describe 'tcp_keepalive enabled' do let(:params) {{ :tcp_keepalive => true }} it 'should set tcp_listen_options keepalive true' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{keepalive, true\}/) end end describe 'tcp_keepalive disabled (default)' do it 'should not set tcp_listen_options' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .without_content(/\{keepalive, true\}/) end end describe 'tcp_backlog with default value' do it 'should set tcp_listen_options backlog to 128' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{backlog, 128\}/) end end @@ -1154,14 +1154,14 @@ end it 'should set tcp_listen_options backlog to 256' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{backlog, 256\}/) end end describe 'tcp_sndbuf with default value' do it 'should not set tcp_listen_options sndbuf' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .without_content(/sndbuf/) end end @@ -1172,14 +1172,14 @@ end it 'should set tcp_listen_options sndbuf to 128' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{sndbuf, 128\}/) end end describe 'tcp_recbuf with default value' do it 'should not set tcp_listen_options recbuf' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .without_content(/recbuf/) end end @@ -1190,7 +1190,7 @@ end it 'should set tcp_listen_options recbuf to 128' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{recbuf, 128\}/) end end @@ -1198,20 +1198,20 @@ describe 'rabbitmq-heartbeat options' do let(:params) {{ :heartbeat => 60 }} it 'should set heartbeat paramter in config file' do - should contain_file('rabbitmq.config') \ + is_expected.to contain_file('rabbitmq.config') \ .with_content(/\{heartbeat, 60\}/) end end context 'delete_guest_user' do describe 'should do nothing by default' do - it { should_not contain_rabbitmq_user('guest') } + it { is_expected.not_to contain_rabbitmq_user('guest') } end describe 'delete user when delete_guest_user set' do let(:params) {{ :delete_guest_user => true }} it 'removes the user' do - should contain_rabbitmq_user('guest').with( + is_expected.to contain_rabbitmq_user('guest').with( 'ensure' => 'absent', 'provider' => 'rabbitmqctl' ) @@ -1223,7 +1223,7 @@ ## rabbitmq::service ## describe 'service with default params' do - it { should contain_service('rabbitmq-server').with( + it { is_expected.to contain_service('rabbitmq-server').with( 'ensure' => 'running', 'enable' => 'true', 'hasstatus' => 'true', @@ -1236,7 +1236,7 @@ { :service_ensure => 'stopped' } end - it { should contain_service('rabbitmq-server').with( + it { is_expected.to contain_service('rabbitmq-server').with( 'ensure' => 'stopped', 'enable' => false ) } @@ -1247,7 +1247,7 @@ { :service_manage => false } end - it { should_not contain_service('rabbitmq-server') } + it { is_expected.not_to contain_service('rabbitmq-server') } end end @@ -1260,7 +1260,7 @@ with_redhat_facts let(:params) {{ :repos_ensure => true }} it 'installs the rabbitmq package' do - should contain_package('rabbitmq-server').with( + is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', 'name' => 'rabbitmq-server', ) @@ -1271,7 +1271,7 @@ with_redhat_facts let(:params) {{ :repos_ensure => false}} it 'installs the rabbitmq package [from EPEL] when $repos_ensure is false' do - should contain_package('rabbitmq-server').with( + is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', 'name' => 'rabbitmq-server', ) @@ -1281,7 +1281,7 @@ context "on Debian" do with_debian_facts it 'installs the rabbitmq package' do - should contain_package('rabbitmq-server').with( + is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', 'name' => 'rabbitmq-server', ) @@ -1291,7 +1291,7 @@ context "on Archlinux" do with_archlinux_facts it 'installs the rabbitmq package' do - should contain_package('rabbitmq-server').with( + is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', ) end @@ -1300,7 +1300,7 @@ context "on OpenBSD" do with_openbsd_facts it 'installs the rabbitmq package' do - should contain_package('rabbitmq-server').with( + is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', 'name' => 'rabbitmq', ) @@ -1314,7 +1314,7 @@ let(:params) {{:repos_ensure => true, :package_apt_pin => '' }} describe 'it sets up an apt::source' do - it { should contain_apt__source('rabbitmq').with( + it { is_expected.to contain_apt__source('rabbitmq').with( 'location' => 'http://www.rabbitmq.com/debian/', 'release' => 'testing', 'repos' => 'main', @@ -1327,14 +1327,14 @@ let(:params) {{:repos_ensure => true, :package_apt_pin => '700' }} describe 'it sets up an apt::source and pin' do - it { should contain_apt__source('rabbitmq').with( + it { is_expected.to contain_apt__source('rabbitmq').with( 'location' => 'http://www.rabbitmq.com/debian/', 'release' => 'testing', 'repos' => 'main', 'key' => '{"id"=>"0A9AF2115F4687BD29803A206B73A36E6026DFCA", "source"=>"https://www.rabbitmq.com/rabbitmq-release-signing-key.asc", "content"=>:undef}' ) } - it { should contain_apt__pin('rabbitmq').with( + it { is_expected.to contain_apt__pin('rabbitmq').with( 'packages' => '*', 'priority' => '700', 'origin' => 'www.rabbitmq.com' diff --git a/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb index 82762bde8..d3dac2309 100644 --- a/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb @@ -26,22 +26,22 @@ exchange\tdst_queue\tqueue\t*\t[] EOT instances = provider_class.instances - instances.size.should == 1 - instances.map do |prov| + expect(instances.size).to eq(1) + expect(instances.map do |prov| { :source => prov.get(:source), :destination => prov.get(:destination), :vhost => prov.get(:vhost), :routing_key => prov.get(:routing_key) } - end.should == [ + end).to eq([ { :source => 'exchange', :destination => 'dst_queue', :vhost => '/', :routing_key => '*' } - ] + ]) end it 'should return multiple instances' do @@ -53,15 +53,15 @@ exchange\tdst_queue\tqueue\trouting_two\t[] EOT instances = provider_class.instances - instances.size.should == 2 - instances.map do |prov| + expect(instances.size).to eq(2) + expect(instances.map do |prov| { :source => prov.get(:source), :destination => prov.get(:destination), :vhost => prov.get(:vhost), :routing_key => prov.get(:routing_key) } - end.should == [ + end).to eq([ { :source => 'exchange', :destination => 'dst_queue', @@ -74,7 +74,7 @@ :vhost => '/', :routing_key => 'routing_two' } - ] + ]) end end diff --git a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb index 10e39acfa..668c9dfc3 100644 --- a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb @@ -36,7 +36,7 @@ test.headers x-consistent-hash false true false [{"hash-header","message-distribution-hash"}] EOT instances = provider_class.instances - instances.size.should == 9 + expect(instances.size).to eq(9) end it 'should call rabbitmqadmin to create as guest' do diff --git a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb index bfacda5eb..8ebe530fd 100644 --- a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb @@ -40,8 +40,8 @@ :provider => described_class.name ) provider = described_class.new(resource) - provider.should_parameter.should == 'documentumShovel' - provider.should_vhost.should == '/' + expect(provider.should_parameter).to eq('documentumShovel') + expect(provider.should_vhost).to eq('/') end it 'should fail with invalid output from list' do @@ -53,7 +53,7 @@ provider.class.expects(:rabbitmqctl).with('list_parameters', '-q', '-p', '/').returns <<-EOT shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} EOT - provider.exists?.should == { + expect(provider.exists?).to eq({ :component_name => 'shovel', :value => { 'src-uri' => 'amqp://', @@ -61,12 +61,12 @@ 'dest-uri' => 'amqp://remote-server', 'dest-queue' => 'another-queue', } - } + }) end it 'should not match an empty list' do provider.class.expects(:rabbitmqctl).with('list_parameters', '-q', '-p', '/').returns '' - provider.exists?.should == nil + expect(provider.exists?).to eq(nil) end it 'should destroy parameter' do diff --git a/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb index c398b6292..af4649331 100644 --- a/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb @@ -13,7 +13,7 @@ end it 'should match plugins' do @provider.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\n") - @provider.exists?.should == 'foo' + expect(@provider.exists?).to eq('foo') end it 'should call rabbitmqplugins to enable' do @provider.expects(:rabbitmqplugins).with('enable', 'foo') diff --git a/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb index cddb6c0c0..35b669041 100644 --- a/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb @@ -34,8 +34,8 @@ :provider => described_class.name ) provider = described_class.new(resource) - provider.should_policy.should == 'ha@home' - provider.should_vhost.should == '/' + expect(provider.should_policy).to eq('ha@home') + expect(provider.should_vhost).to eq('/') end it 'should fail with invalid output from list' do @@ -48,14 +48,14 @@ / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 / test exchanges .* {"ha-mode":"all"} 0 EOT - provider.exists?.should == { + expect(provider.exists?).to eq({ :applyto => 'all', :pattern => '.*', :priority => '0', :definition => { 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic'} - } + }) end it 'should match policies from list (<3.2.0)' do @@ -63,19 +63,19 @@ / ha-all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 / test .* {"ha-mode":"all"} 0 EOT - provider.exists?.should == { + expect(provider.exists?).to eq({ :applyto => 'all', :pattern => '.*', :priority => '0', :definition => { 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic'} - } + }) end it 'should not match an empty list' do provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns '' - provider.exists?.should == nil + expect(provider.exists?).to eq(nil) end it 'should destroy policy' do diff --git a/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb index 85843da8a..ac5a0c7e2 100644 --- a/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb @@ -25,7 +25,7 @@ test2 true false [{"x-message-ttl",342423},{"x-expires",53253232},{"x-max-length",2332},{"x-max-length-bytes",32563324242},{"x-dead-letter-exchange","amq.direct"},{"x-dead-letter-routing-key","test.routing"}] EOT instances = provider_class.instances - instances.size.should == 2 + expect(instances.size).to eq(2) end it 'should call rabbitmqadmin to create' do diff --git a/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb index ed828ea94..78333da69 100644 --- a/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb @@ -15,24 +15,24 @@ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo EOT - @provider.exists?.should == 'foo' + expect(@provider.exists?).to eq('foo') end it 'should match user names with 2.4.1 syntax' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo bar EOT - @provider.exists?.should == 'foo bar' + expect(@provider.exists?).to eq('foo bar') end it 'should not match if no users on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT EOT - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil end it 'should not match if no matching users on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT fooey EOT - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil end it 'should match user names from list' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT @@ -41,7 +41,7 @@ foo bar EOT - @provider.exists?.should == 'foo' + expect(@provider.exists?).to eq('foo') end it 'should create user and set password' do @resource[:password] = 'bar' @@ -69,12 +69,12 @@ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] EOT - @provider.admin.should == :true + expect(@provider.admin).to eq(:true) @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT one [administrator] foo [] EOT - @provider.admin.should == :false + expect(@provider.admin).to eq(:false) end it 'should fail if admin value is invalid' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT @@ -200,7 +200,7 @@ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] EOT - @provider.tags.should == [] + expect(@provider.tags).to eq([]) end it 'should return the administrator tag for non-admins' do @@ -210,6 +210,6 @@ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] EOT - @provider.tags.should == ["administrator"] + expect(@provider.tags).to eq(["administrator"]) end end diff --git a/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb index bdbc73e82..21ba44f46 100644 --- a/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb @@ -18,13 +18,13 @@ @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 EOT - @provider.exists?.should == {:configure=>"1", :write=>"2", :read=>"3"} + expect(@provider.exists?).to eq({:configure=>"1", :write=>"2", :read=>"3"}) end it 'should match user permissions with empty columns' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 3 EOT - @provider.exists?.should == {:configure=>"", :write=>"", :read=>"3"} + expect(@provider.exists?).to eq({:configure=>"", :write=>"", :read=>"3"}) end it 'should not match user permissions with more than 3 columns' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT @@ -35,7 +35,7 @@ it 'should not match an empty list' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT EOT - @provider.exists?.should == nil + expect(@provider.exists?).to eq(nil) end it 'should create default permissions' do @provider.instance_variable_set(:@should_vhost, "bar") @@ -54,7 +54,7 @@ @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 EOT - @provider.send(k).should == v + expect(@provider.send(k)).to eq(v) end end {:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v| @@ -63,7 +63,7 @@ bar 1 2 3 EOT @provider.exists? - @provider.send(k).should == v + expect(@provider.send(k)).to eq(v) end end {:configure_permission => ['foo', '2', '3'], diff --git a/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb index 6c8cce8df..14122804a 100644 --- a/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb @@ -17,14 +17,14 @@ foo ...done. EOT - @provider.exists?.should == 'foo' + expect(@provider.exists?).to eq('foo') end it 'should not match if no vhosts on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT Listing vhosts ... ...done. EOT - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil end it 'should not match if no matching vhosts on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT @@ -32,7 +32,7 @@ fooey ...done. EOT - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil end it 'should call rabbitmqctl to create' do @provider.expects(:rabbitmqctl).with('add_vhost', 'foo') diff --git a/spec/unit/puppet/type/rabbitmq_binding_spec.rb b/spec/unit/puppet/type/rabbitmq_binding_spec.rb index a3646076c..8dbf7f6e3 100644 --- a/spec/unit/puppet/type/rabbitmq_binding_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_binding_spec.rb @@ -8,7 +8,7 @@ end it 'should accept an queue name' do @binding[:name] = 'dan@dude@pl' - @binding[:name].should == 'dan@dude@pl' + expect(@binding[:name]).to eq('dan@dude@pl') end it 'should require a name' do expect { @@ -33,14 +33,14 @@ end it 'should accept an binding destination_type' do @binding[:destination_type] = :exchange - @binding[:destination_type].should == :exchange + expect(@binding[:destination_type]).to eq(:exchange) end it 'should accept a user' do @binding[:user] = :root - @binding[:user].should == :root + expect(@binding[:user]).to eq(:root) end it 'should accept a password' do @binding[:password] = :PaSsw0rD - @binding[:password].should == :PaSsw0rD + expect(@binding[:password]).to eq(:PaSsw0rD) end end diff --git a/spec/unit/puppet/type/rabbitmq_exchange_spec.rb b/spec/unit/puppet/type/rabbitmq_exchange_spec.rb index addbe2749..eb27ef6fa 100644 --- a/spec/unit/puppet/type/rabbitmq_exchange_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_exchange_spec.rb @@ -11,7 +11,7 @@ end it 'should accept an exchange name' do @exchange[:name] = 'dan@pl' - @exchange[:name].should == 'dan@pl' + expect(@exchange[:name]).to eq('dan@pl') end it 'should require a name' do expect { @@ -31,7 +31,7 @@ it 'should accept an exchange type' do @exchange[:type] = :direct - @exchange[:type].should == :direct + expect(@exchange[:type]).to eq(:direct) end it 'should require a type' do expect { @@ -46,11 +46,11 @@ it 'should accept a user' do @exchange[:user] = :root - @exchange[:user].should == :root + expect(@exchange[:user]).to eq(:root) end it 'should accept a password' do @exchange[:password] = :PaSsw0rD - @exchange[:password].should == :PaSsw0rD + expect(@exchange[:password]).to eq(:PaSsw0rD) end end diff --git a/spec/unit/puppet/type/rabbitmq_parameter_spec.rb b/spec/unit/puppet/type/rabbitmq_parameter_spec.rb index fa023ac75..9b3e4a199 100644 --- a/spec/unit/puppet/type/rabbitmq_parameter_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_parameter_spec.rb @@ -15,7 +15,7 @@ it 'should accept a valid name' do @parameter[:name] = 'documentumShovel@/' - @parameter[:name].should == 'documentumShovel@/' + expect(@parameter[:name]).to eq('documentumShovel@/') end it 'should require a name' do @@ -32,7 +32,7 @@ it 'should accept a string' do @parameter[:component_name] = 'mystring' - @parameter[:component_name].should == 'mystring' + expect(@parameter[:component_name]).to eq('mystring') end it 'should not be empty' do @@ -44,7 +44,7 @@ it 'should accept a valid hash for value' do value = {'message-ttl' => '1800000'} @parameter[:value] = value - @parameter[:value].should == value + expect(@parameter[:value]).to eq(value) end it 'should not accept invalid hash for definition' do @@ -64,16 +64,16 @@ it 'should accept string as myparameter' do value = {'myparameter' => 'mystring'} @parameter[:value] = value - @parameter[:value]['myparameter'].should be_a(String) - @parameter[:value]['myparameter'].should == 'mystring' + expect(@parameter[:value]['myparameter']).to be_a(String) + expect(@parameter[:value]['myparameter']).to eq('mystring') end it 'should convert to integer when string only contains numbers' do value = {'myparameter' => '1800000'} @parameter[:value] = value - @parameter[:value]['myparameter'].should be_a(Fixnum) - @parameter[:value]['myparameter'].should == 1800000 + expect(@parameter[:value]['myparameter']).to be_a(Fixnum) + expect(@parameter[:value]['myparameter']).to eq(1800000) end end diff --git a/spec/unit/puppet/type/rabbitmq_plugin_spec.rb b/spec/unit/puppet/type/rabbitmq_plugin_spec.rb index b5f557ca7..1540a3333 100644 --- a/spec/unit/puppet/type/rabbitmq_plugin_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_plugin_spec.rb @@ -5,7 +5,7 @@ end it 'should accept a plugin name' do @plugin[:name] = 'plugin-name' - @plugin[:name].should == 'plugin-name' + expect(@plugin[:name]).to eq('plugin-name') end it 'should require a name' do expect { @@ -13,7 +13,7 @@ }.to raise_error(Puppet::Error, 'Title or name must be provided') end it 'should default to a umask of 0022' do - @plugin[:umask].should == 0022 + expect(@plugin[:umask]).to eq(0022) end it 'should not allow a non-octal value to be specified' do expect { diff --git a/spec/unit/puppet/type/rabbitmq_policy_spec.rb b/spec/unit/puppet/type/rabbitmq_policy_spec.rb index 1ba104d8b..ebb63f84a 100644 --- a/spec/unit/puppet/type/rabbitmq_policy_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_policy_spec.rb @@ -12,7 +12,7 @@ it 'should accept a valid name' do @policy[:name] = 'ha-all@/' - @policy[:name].should == 'ha-all@/' + expect(@policy[:name]).to eq('ha-all@/') end it 'should require a name' do @@ -29,12 +29,12 @@ it 'should accept a valid regex for pattern' do @policy[:pattern] = '.*?' - @policy[:pattern].should == '.*?' + expect(@policy[:pattern]).to eq('.*?') end it 'should accept an empty string for pattern' do @policy[:pattern] = '' - @policy[:pattern].should == '' + expect(@policy[:pattern]).to eq('') end it 'should not accept invalid regex for pattern' do @@ -46,7 +46,7 @@ it 'should accept valid value for applyto' do [:all, :exchanges, :queues].each do |v| @policy[:applyto] = v - @policy[:applyto].should == v + expect(@policy[:applyto]).to eq(v) end end @@ -59,7 +59,7 @@ it 'should accept a valid hash for definition' do definition = {'ha-mode' => 'all', 'ha-sync-mode' => 'automatic'} @policy[:definition] = definition - @policy[:definition].should == definition + expect(@policy[:definition]).to eq(definition) end it 'should not accept invalid hash for definition' do @@ -75,7 +75,7 @@ it 'should accept valid value for priority' do [0, 10, '0', '10'].each do |v| @policy[:priority] = v - @policy[:priority].should == v + expect(@policy[:priority]).to eq(v) end end @@ -90,8 +90,8 @@ it 'should accept and convert ha-params for ha-mode exactly' do definition = {'ha-mode' => 'exactly', 'ha-params' => '2'} @policy[:definition] = definition - @policy[:definition]['ha-params'].should be_a(Fixnum) - @policy[:definition]['ha-params'].should == 2 + expect(@policy[:definition]['ha-params']).to be_a(Fixnum) + expect(@policy[:definition]['ha-params']).to eq(2) end it 'should not accept non-numeric ha-params for ha-mode exactly' do @@ -104,8 +104,8 @@ it 'should accept and convert the expires value' do definition = {'expires' => '1800000'} @policy[:definition] = definition - @policy[:definition]['expires'].should be_a(Fixnum) - @policy[:definition]['expires'].should == 1800000 + expect(@policy[:definition]['expires']).to be_a(Fixnum) + expect(@policy[:definition]['expires']).to eq(1800000) end it 'should not accept non-numeric expires value' do @@ -118,8 +118,8 @@ it 'should accept and convert the message-ttl value' do definition = {'message-ttl' => '1800000'} @policy[:definition] = definition - @policy[:definition]['message-ttl'].should be_a(Fixnum) - @policy[:definition]['message-ttl'].should == 1800000 + expect(@policy[:definition]['message-ttl']).to be_a(Fixnum) + expect(@policy[:definition]['message-ttl']).to eq(1800000) end it 'should not accept non-numeric message-ttl value' do @@ -132,8 +132,8 @@ it 'should accept and convert the max-length value' do definition = {'max-length' => '1800000'} @policy[:definition] = definition - @policy[:definition]['max-length'].should be_a(Fixnum) - @policy[:definition]['max-length'].should == 1800000 + expect(@policy[:definition]['max-length']).to be_a(Fixnum) + expect(@policy[:definition]['max-length']).to eq(1800000) end it 'should not accept non-numeric max-length value' do @@ -146,8 +146,8 @@ it 'should accept and convert the shards-per-node value' do definition = {'shards-per-node' => '1800000'} @policy[:definition] = definition - @policy[:definition]['shards-per-node'].should be_a(Fixnum) - @policy[:definition]['shards-per-node'].should == 1800000 + expect(@policy[:definition]['shards-per-node']).to be_a(Fixnum) + expect(@policy[:definition]['shards-per-node']).to eq(1800000) end it 'should not accept non-numeric shards-per-node value' do @@ -160,8 +160,8 @@ it 'should accept and convert the ha-sync-batch-size value' do definition = {'ha-sync-batch-size' => '1800000'} @policy[:definition] = definition - @policy[:definition]['ha-sync-batch-size'].should be_a(Fixnum) - @policy[:definition]['ha-sync-batch-size'].should == 1800000 + expect(@policy[:definition]['ha-sync-batch-size']).to be_a(Fixnum) + expect(@policy[:definition]['ha-sync-batch-size']).to eq(1800000) end it 'should not accept non-numeric ha-sync-batch-size value' do @@ -174,10 +174,10 @@ it 'should accept list value in ha-params when ha-mode = nodes' do definition = {'ha-mode' => 'nodes', 'ha-params' => ['rabbit@rabbit-01', 'rabbit@rabbit-02']} @policy[:definition] = definition - @policy[:definition]['ha-mode'].should == 'nodes' - @policy[:definition]['ha-params'].should be_a(Array) - @policy[:definition]['ha-params'][0].should == 'rabbit@rabbit-01' - @policy[:definition]['ha-params'][1].should == 'rabbit@rabbit-02' + expect(@policy[:definition]['ha-mode']).to eq('nodes') + expect(@policy[:definition]['ha-params']).to be_a(Array) + expect(@policy[:definition]['ha-params'][0]).to eq('rabbit@rabbit-01') + expect(@policy[:definition]['ha-params'][1]).to eq('rabbit@rabbit-02') end it 'should not accept non-list value in ha-params when ha-mode = nodes' do diff --git a/spec/unit/puppet/type/rabbitmq_queue_spec.rb b/spec/unit/puppet/type/rabbitmq_queue_spec.rb index 8ca67e907..4b872439d 100644 --- a/spec/unit/puppet/type/rabbitmq_queue_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_queue_spec.rb @@ -12,7 +12,7 @@ end it 'should accept an queue name' do @queue[:name] = 'dan@pl' - @queue[:name].should == 'dan@pl' + expect(@queue[:name]).to eq('dan@pl') end it 'should require a name' do expect { @@ -32,27 +32,27 @@ it 'should accept an arguments with numbers value' do @queue[:arguments] = {'x-message-ttl' => 30} - @queue[:arguments].to_json.should == "{\"x-message-ttl\":30}" - @queue[:arguments]['x-message-ttl'].should == 30 + expect(@queue[:arguments].to_json).to eq("{\"x-message-ttl\":30}") + expect(@queue[:arguments]['x-message-ttl']).to eq(30) end it 'should accept an arguments with string value' do @queue[:arguments] = {'x-dead-letter-exchange' => 'catchallexchange'} - @queue[:arguments].to_json.should == "{\"x-dead-letter-exchange\":\"catchallexchange\"}" + expect(@queue[:arguments].to_json).to eq("{\"x-dead-letter-exchange\":\"catchallexchange\"}") end it 'should accept an queue durable' do @queue[:durable] = :true - @queue[:durable].should == :true + expect(@queue[:durable]).to eq(:true) end it 'should accept a user' do @queue[:user] = :root - @queue[:user].should == :root + expect(@queue[:user]).to eq(:root) end it 'should accept a password' do @queue[:password] = :PaSsw0rD - @queue[:password].should == :PaSsw0rD + expect(@queue[:password]).to eq(:PaSsw0rD) end end diff --git a/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb b/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb index 518050a8b..90424dc2a 100644 --- a/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb @@ -5,7 +5,7 @@ end it 'should accept a valid hostname name' do @perms[:name] = 'dan@bar' - @perms[:name].should == 'dan@bar' + expect(@perms[:name]).to eq('dan@bar') end it 'should require a name' do expect { @@ -19,15 +19,15 @@ end [:configure_permission, :read_permission, :write_permission].each do |param| it 'should not default to anything' do - @perms[param].should == nil + expect(@perms[param]).to eq(nil) end it "should accept a valid regex for #{param}" do @perms[param] = '.*?' - @perms[param].should == '.*?' + expect(@perms[param]).to eq('.*?') end it "should accept an empty string for #{param}" do @perms[param] = '' - @perms[param].should == '' + expect(@perms[param]).to eq('') end it "should not accept invalid regex for #{param}" do expect { @@ -47,8 +47,8 @@ [vhost, perm].each { |resource| conf.add_resource resource } end rel = perm.autorequire[0] - rel.source.ref.should == vhost.ref - rel.target.ref.should == perm.ref + expect(rel.source.ref).to eq(vhost.ref) + expect(rel.target.ref).to eq(perm.ref) end end end diff --git a/spec/unit/puppet/type/rabbitmq_user_spec.rb b/spec/unit/puppet/type/rabbitmq_user_spec.rb index 804ef7b1a..3a8f5cec8 100644 --- a/spec/unit/puppet/type/rabbitmq_user_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_user_spec.rb @@ -5,12 +5,12 @@ end it 'should accept a user name' do @user[:name] = 'dan' - @user[:name].should == 'dan' - @user[:admin].should == :false + expect(@user[:name]).to eq('dan') + expect(@user[:admin]).to eq(:false) end it 'should accept a password' do @user[:password] = 'foo' - @user[:password].should == 'foo' + expect(@user[:password]).to eq('foo') end it 'should require a password' do expect { @@ -30,7 +30,7 @@ [true, false, 'true', 'false'].each do |val| it "admin property should accept #{val}" do @user[:admin] = val - @user[:admin].should == val.to_s.to_sym + expect(@user[:admin]).to eq(val.to_s.to_sym) end end it 'should not accept non-boolean values for admin' do diff --git a/spec/unit/puppet/type/rabbitmq_vhost_spec.rb b/spec/unit/puppet/type/rabbitmq_vhost_spec.rb index 9c47d009e..03d7ebb68 100644 --- a/spec/unit/puppet/type/rabbitmq_vhost_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_vhost_spec.rb @@ -5,7 +5,7 @@ end it 'should accept a vhost name' do @vhost[:name] = 'dan' - @vhost[:name].should == 'dan' + expect(@vhost[:name]).to eq('dan') end it 'should require a name' do expect { From 929da0357e2cc4cdaaedad3263281473d6f67e9c Mon Sep 17 00:00:00 2001 From: William Yardley Date: Tue, 29 Aug 2017 13:19:39 -0700 Subject: [PATCH 3/4] auto-updates via rubocop -a --- .../rabbitmq_binding/rabbitmqadmin.rb | 82 +- .../provider/rabbitmq_erlang_cookie/ruby.rb | 12 +- .../rabbitmq_exchange/rabbitmqadmin.rb | 84 +- .../rabbitmq_parameter/rabbitmqctl.rb | 33 +- .../rabbitmq_plugin/rabbitmqplugins.rb | 32 +- .../provider/rabbitmq_policy/rabbitmqctl.rb | 62 +- .../provider/rabbitmq_queue/rabbitmqadmin.rb | 63 +- .../provider/rabbitmq_user/rabbitmqctl.rb | 71 +- .../rabbitmq_user_permissions/rabbitmqctl.rb | 40 +- .../provider/rabbitmq_vhost/rabbitmqctl.rb | 26 +- lib/puppet/provider/rabbitmqctl.rb | 11 +- lib/puppet/type/rabbitmq_binding.rb | 47 +- lib/puppet/type/rabbitmq_erlang_cookie.rb | 10 +- lib/puppet/type/rabbitmq_exchange.rb | 19 +- lib/puppet/type/rabbitmq_parameter.rb | 27 +- lib/puppet/type/rabbitmq_plugin.rb | 9 +- lib/puppet/type/rabbitmq_policy.rb | 22 +- lib/puppet/type/rabbitmq_queue.rb | 16 +- lib/puppet/type/rabbitmq_user.rb | 33 +- lib/puppet/type/rabbitmq_user_permissions.rb | 13 +- lib/puppet/type/rabbitmq_vhost.rb | 5 +- spec/acceptance/class_spec.rb | 55 +- spec/acceptance/clustering_spec.rb | 13 +- spec/acceptance/delete_guest_user_spec.rb | 6 +- spec/acceptance/parameter_spec.rb | 14 +- spec/acceptance/policy_spec.rb | 23 +- spec/acceptance/queue_spec.rb | 52 +- spec/acceptance/rabbitmqadmin_spec.rb | 15 +- spec/acceptance/server_spec.rb | 25 +- spec/acceptance/user_spec.rb | 15 +- spec/acceptance/vhost_spec.rb | 15 +- spec/classes/rabbitmq_spec.rb | 1299 +++++++++-------- spec/spec_helper.rb | 2 +- spec/spec_helper_acceptance.rb | 15 +- spec/spec_helper_local.rb | 46 +- .../rabbitmq_binding/rabbitmqadmin_spec.rb | 139 +- .../rabbitmq_exchange/rabbitmqadmin_spec.rb | 48 +- .../rabbitmq_parameter/rabbitmqctl_spec.rb | 63 +- .../rabbitmq_plugin/rabbitmqctl_spec.rb | 10 +- .../rabbitmq_policy/rabbitmqctl_spec.rb | 89 +- .../rabbitmq_queue/rabbitmqadmin_spec.rb | 34 +- .../rabbitmq_user/rabbitmqctl_spec.rb | 98 +- .../rabbitmqctl_spec.rb | 50 +- .../rabbitmq_vhost/rabbitmqctl_spec.rb | 14 +- .../unit/puppet/type/rabbitmq_binding_spec.rb | 40 +- .../puppet/type/rabbitmq_exchange_spec.rb | 54 +- .../puppet/type/rabbitmq_parameter_spec.rb | 68 +- spec/unit/puppet/type/rabbitmq_plugin_spec.rb | 22 +- spec/unit/puppet/type/rabbitmq_policy_spec.rb | 177 ++- spec/unit/puppet/type/rabbitmq_queue_spec.rb | 46 +- .../type/rabbitmq_user_permissions_spec.rb | 44 +- spec/unit/puppet/type/rabbitmq_user_spec.rb | 46 +- spec/unit/puppet/type/rabbitmq_vhost_spec.rb | 18 +- spec/unit/rabbitmq_nodename_spec.rb | 17 +- spec/unit/rabbitmq_version_spec.rb | 10 +- 55 files changed, 1676 insertions(+), 1723 deletions(-) diff --git a/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb index c41d21d1c..d20e52180 100644 --- a/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb @@ -3,19 +3,18 @@ require 'digest' Puppet::Type.type(:rabbitmq_binding).provide(:rabbitmqadmin) do - if Puppet::PUPPETVERSION.to_f < 3 - commands :rabbitmqctl => 'rabbitmqctl' - commands :rabbitmqadmin => '/usr/local/bin/rabbitmqadmin' + commands rabbitmqctl: 'rabbitmqctl' + commands rabbitmqadmin: '/usr/local/bin/rabbitmqadmin' else has_command(:rabbitmqctl, 'rabbitmqctl') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end end - defaultfor :feature => :posix + defaultfor feature: :posix # Without this, the composite namevar stuff doesn't work properly. mk_resource_methods @@ -30,44 +29,41 @@ def should_vhost def self.all_vhosts vhosts = [] - rabbitmqctl('list_vhosts', '-q').split(/\n/).collect do |vhost| + rabbitmqctl('list_vhosts', '-q').split(%r{\n}).map do |vhost| vhosts.push(vhost) end vhosts end def self.all_bindings(vhost) - rabbitmqctl('list_bindings', '-q', '-p', vhost, 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments').split(/\n/) + rabbitmqctl('list_bindings', '-q', '-p', vhost, 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments').split(%r{\n}) end def self.instances resources = [] all_vhosts.each do |vhost| - all_bindings(vhost).collect do |line| - source_name, destination_name, destination_type, routing_key, arguments = line.split(/\t/) + all_bindings(vhost).map do |line| + source_name, destination_name, destination_type, routing_key, arguments = line.split(%r{\t}) # Convert output of arguments from the rabbitmqctl command to a json string. if !arguments.nil? - arguments = arguments.gsub(/^\[(.*)\]$/, "").gsub(/\{("(?:.|\\")*?"),/, '{\1:').gsub(/\},\{/, ",") - if arguments == "" - arguments = '{}' - end + arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',') + arguments = '{}' if arguments == '' else arguments = '{}' end - hashed_name = Digest::SHA256.hexdigest "%s@%s@%s@%s" % [source_name, destination_name, vhost, routing_key] - unless(source_name.empty?) - binding = { - :source => source_name, - :destination => destination_name, - :vhost => vhost, - :destination_type => destination_type, - :routing_key => routing_key, - :arguments => JSON.parse(arguments), - :ensure => :present, - :name => hashed_name, - } - resources << new(binding) if binding[:name] - end + hashed_name = Digest::SHA256.hexdigest format('%s@%s@%s@%s', source_name, destination_name, vhost, routing_key) + next if source_name.empty? + binding = { + source: source_name, + destination: destination_name, + vhost: vhost, + destination_type: destination_type, + routing_key: routing_key, + arguments: JSON.parse(arguments), + ensure: :present, + name: hashed_name + } + resources << new(binding) if binding[:name] end end resources @@ -78,7 +74,7 @@ def self.instances def self.prefetch(resources) bindings = instances resources.each do |name, res| - if provider = bindings.find{ |binding| binding.source == res[:source] && binding.destination == res[:destination] && binding.vhost == res[:vhost] && binding.routing_key == res[:routing_key] } + if provider = bindings.find { |binding| binding.source == res[:source] && binding.destination == res[:destination] && binding.vhost == res[:vhost] && binding.routing_key == res[:routing_key] } resources[name].provider = provider end end @@ -91,22 +87,19 @@ def exists? def create vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : '' arguments = resource[:arguments] - if arguments.nil? - arguments = {} - end + arguments = {} if arguments.nil? rabbitmqadmin('declare', - 'binding', - vhost_opt, - "--user=#{resource[:user]}", - "--password=#{resource[:password]}", - '-c', - '/etc/rabbitmq/rabbitmqadmin.conf', - "source=#{resource[:source]}", - "destination=#{resource[:destination]}", - "arguments=#{arguments.to_json}", - "routing_key=#{resource[:routing_key]}", - "destination_type=#{resource[:destination_type]}" - ) + 'binding', + vhost_opt, + "--user=#{resource[:user]}", + "--password=#{resource[:password]}", + '-c', + '/etc/rabbitmq/rabbitmqadmin.conf', + "source=#{resource[:source]}", + "destination=#{resource[:destination]}", + "arguments=#{arguments.to_json}", + "routing_key=#{resource[:routing_key]}", + "destination_type=#{resource[:destination_type]}") @property_hash[:ensure] = :present end @@ -115,5 +108,4 @@ def destroy rabbitmqadmin('delete', 'binding', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "source=#{resource[:source]}", "destination_type=#{resource[:destination_type]}", "destination=#{resource[:destination]}", "properties_key=#{resource[:routing_key]}") @property_hash[:ensure] = :absent end - end diff --git a/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb b/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb index 5689d268f..c23e3ef8d 100644 --- a/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb +++ b/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb @@ -1,8 +1,7 @@ require 'puppet' require 'set' Puppet::Type.type(:rabbitmq_erlang_cookie).provide(:ruby) do - - defaultfor :feature => :posix + defaultfor feature: :posix def exists? # Hack to prevent the create method from being called. @@ -12,24 +11,23 @@ def exists? def content=(value) if resource[:force] == :true # Danger! - Puppet::Type.type(:service).new(:name => resource[:service_name]).provider.stop + Puppet::Type.type(:service).new(name: resource[:service_name]).provider.stop FileUtils.rm_rf(resource[:rabbitmq_home] + File::SEPARATOR + 'mnesia') File.open(resource[:path], 'w') do |cookie| - cookie.chmod(0400) + cookie.chmod(0o400) cookie.write(value) end FileUtils.chown(resource[:rabbitmq_user], resource[:rabbitmq_group], resource[:path]) else - fail('The current erlang cookie needs to change. In order to do this the RabbitMQ database needs to be wiped. Please set force => true to allow this to happen automatically.') + raise('The current erlang cookie needs to change. In order to do this the RabbitMQ database needs to be wiped. Please set force => true to allow this to happen automatically.') end end def content - if File.exists?(resource[:path]) + if File.exist?(resource[:path]) File.read(resource[:path]) else '' end end - end diff --git a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb index 663b2f0c7..c5cb613f9 100644 --- a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb @@ -1,19 +1,18 @@ require 'puppet' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_exchange).provide(:rabbitmqadmin, :parent => Puppet::Provider::Rabbitmqctl) do - +Puppet::Type.type(:rabbitmq_exchange).provide(:rabbitmqadmin, parent: Puppet::Provider::Rabbitmqctl) do if Puppet::PUPPETVERSION.to_f < 3 - commands :rabbitmqctl => 'rabbitmqctl' - commands :rabbitmqadmin => '/usr/local/bin/rabbitmqadmin' + commands rabbitmqctl: 'rabbitmqctl' + commands rabbitmqadmin: '/usr/local/bin/rabbitmqadmin' else has_command(:rabbitmqctl, 'rabbitmqctl') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end end - defaultfor :feature => :posix + defaultfor feature: :posix def should_vhost if @should_vhost @@ -25,9 +24,9 @@ def should_vhost def self.all_vhosts vhosts = [] - self.run_with_retries { + run_with_retries do rabbitmqctl('-q', 'list_vhosts') - }.split(/\n/).each do |vhost| + end.split(%r{\n}).each do |vhost| vhosts.push(vhost) end vhosts @@ -35,10 +34,10 @@ def self.all_vhosts def self.all_exchanges(vhost) exchanges = [] - self.run_with_retries { + run_with_retries do rabbitmqctl('-q', 'list_exchanges', '-p', vhost, 'name', 'type', 'internal', 'durable', 'auto_delete', 'arguments') - }.split(/\n/).each do |exchange| - next if exchange =~ /^federation:/ + end.split(%r{\n}).each do |exchange| + next if exchange =~ %r{^federation:} exchanges.push(exchange) end exchanges @@ -47,34 +46,32 @@ def self.all_exchanges(vhost) def self.instances resources = [] all_vhosts.each do |vhost| - all_exchanges(vhost).each do |line| - name, type, internal, durable, auto_delete, arguments = line.split() - if type.nil? - # if name is empty, it will wrongly get the type's value. - # This way type will get the correct value - type = name - name = '' - end - # Convert output of arguments from the rabbitmqctl command to a json string. - if !arguments.nil? - arguments = arguments.gsub(/^\[(.*)\]$/, "").gsub(/\{("(?:.|\\")*?"),/, '{\1:').gsub(/\},\{/, ",") - if arguments == "" - arguments = '{}' - end - else - arguments = '{}' - end - exchange = { - :type => type, - :ensure => :present, - :internal => internal, - :durable => durable, - :auto_delete => auto_delete, - :name => "%s@%s" % [name, vhost], - :arguments => JSON.parse(arguments), - } - resources << new(exchange) if exchange[:type] + all_exchanges(vhost).each do |line| + name, type, internal, durable, auto_delete, arguments = line.split + if type.nil? + # if name is empty, it will wrongly get the type's value. + # This way type will get the correct value + type = name + name = '' + end + # Convert output of arguments from the rabbitmqctl command to a json string. + if !arguments.nil? + arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',') + arguments = '{}' if arguments == '' + else + arguments = '{}' end + exchange = { + type: type, + ensure: :present, + internal: internal, + durable: durable, + auto_delete: auto_delete, + name: format('%s@%s', name, vhost), + arguments: JSON.parse(arguments) + } + resources << new(exchange) if exchange[:type] + end end resources end @@ -82,7 +79,7 @@ def self.instances def self.prefetch(resources) packages = instances resources.keys.each do |name| - if provider = packages.find{ |pkg| pkg.name == name } + if provider = packages.find { |pkg| pkg.name == name } resources[name].provider = provider end end @@ -96,10 +93,8 @@ def create vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : '' name = resource[:name].split('@')[0] arguments = resource[:arguments] - if arguments.nil? - arguments = {} - end - cmd = ['declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}",] + arguments = {} if arguments.nil? + cmd = ['declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}"] cmd << "internal=#{resource[:internal]}" if resource[:internal] cmd << "durable=#{resource[:durable]}" if resource[:durable] cmd << "auto_delete=#{resource[:auto_delete]}" if resource[:auto_delete] @@ -114,5 +109,4 @@ def destroy rabbitmqadmin('delete', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf') @property_hash[:ensure] = :absent end - end diff --git a/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb index fe476887a..c7d1d73fc 100644 --- a/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb @@ -2,22 +2,21 @@ require 'puppet/util/package' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_parameter).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmqctl) do - - defaultfor :feature => :posix +Puppet::Type.type(:rabbitmq_parameter).provide(:rabbitmqctl, parent: Puppet::Provider::Rabbitmqctl) do + defaultfor feature: :posix # cache parameters def self.parameters(name, vhost) @parameters = {} unless @parameters unless @parameters[vhost] @parameters[vhost] = {} - self.run_with_retries { + run_with_retries do rabbitmqctl('list_parameters', '-q', '-p', vhost) - }.split(/\n/).each do |line| - if line =~ /^(\S+)\s+(\S+)\s+(\S+)$/ - @parameters[vhost][$2] = { - :component_name => $1, - :value => JSON.parse($3), + end.split(%r{\n}).each do |line| + if line =~ %r{^(\S+)\s+(\S+)\s+(\S+)$} + @parameters[vhost][Regexp.last_match(2)] = { + component_name: Regexp.last_match(1), + value: JSON.parse(Regexp.last_match(3)) } else raise Puppet::Error, "cannot parse line from list_parameter:#{line}" @@ -55,7 +54,7 @@ def component_name parameters(should_vhost, should_parameter)[:component_name] end - def component_name=(component_name) + def component_name=(_component_name) set_parameter end @@ -63,7 +62,7 @@ def value parameters(should_vhost, should_parameter)[:value] end - def value=(value) + def value=(_value) set_parameter end @@ -71,14 +70,12 @@ def set_parameter unless @set_parameter @set_parameter = true resource[:value] ||= value - resource[:component_name] ||= component_name + resource[:component_name] ||= component_name rabbitmqctl('set_parameter', - '-p', should_vhost, - resource[:component_name], - should_parameter, - resource[:value].to_json - ) + '-p', should_vhost, + resource[:component_name], + should_parameter, + resource[:value].to_json) end end - end diff --git a/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb b/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb index c16e866a4..dce980135 100644 --- a/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb +++ b/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb @@ -1,32 +1,31 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, :parent => Puppet::Provider::Rabbitmqctl) do - +Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, parent: Puppet::Provider::Rabbitmqctl) do if Puppet::PUPPETVERSION.to_f < 3 if Facter.value(:osfamily) == 'RedHat' - commands :rabbitmqplugins => '/usr/lib/rabbitmq/bin/rabbitmq-plugins' + commands rabbitmqplugins: '/usr/lib/rabbitmq/bin/rabbitmq-plugins' else - commands :rabbitmqplugins => 'rabbitmq-plugins' + commands rabbitmqplugins: 'rabbitmq-plugins' end else if Facter.value(:osfamily) == 'RedHat' has_command(:rabbitmqplugins, '/usr/lib/rabbitmq/bin/rabbitmq-plugins') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end else has_command(:rabbitmqplugins, 'rabbitmq-plugins') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end end end - defaultfor :feature => :posix + defaultfor feature: :posix def self.instances - self.run_with_retries { + run_with_retries do rabbitmqplugins('list', '-E', '-m') - }.split(/\n/).map do |line| - if line =~ /^(\S+)$/ - new(:name => $1) + end.split(%r{\n}).map do |line| + if line =~ %r{^(\S+)$} + new(name: Regexp.last_match(1)) else raise Puppet::Error, "Cannot parse invalid plugins line: #{line}" end @@ -34,10 +33,10 @@ def self.instances end def create - if resource[:umask] == nil + if resource[:umask].nil? rabbitmqplugins('enable', resource[:name]) else - Puppet::Util::withumask(resource[:umask]) { rabbitmqplugins('enable', resource[:name]) } + Puppet::Util.withumask(resource[:umask]) { rabbitmqplugins('enable', resource[:name]) } end end @@ -46,11 +45,10 @@ def destroy end def exists? - self.class.run_with_retries { + self.class.run_with_retries do rabbitmqplugins('list', '-E', '-m') - }.split(/\n/).detect do |line| - line.match(/^#{resource[:name]}$/) + end.split(%r{\n}).find do |line| + line.match(%r{^#{resource[:name]}$}) end end - end diff --git a/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb index dbbef4fbc..6669d050e 100644 --- a/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb @@ -2,34 +2,34 @@ require 'puppet/util/package' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_policy).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmqctl) do - - defaultfor :feature => :posix +Puppet::Type.type(:rabbitmq_policy).provide(:rabbitmqctl, parent: Puppet::Provider::Rabbitmqctl) do + defaultfor feature: :posix # cache policies def self.policies(name, vhost) @policies = {} unless @policies unless @policies[vhost] @policies[vhost] = {} - self.run_with_retries { + run_with_retries do rabbitmqctl('list_policies', '-q', '-p', vhost) - }.split(/\n/).each do |line| + end.split(%r{\n}).each do |line| # rabbitmq<3.2 does not support the applyto field # 1 2 3? 4 5 6 # / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 - if line =~ /^(\S+)\s+(\S+)\s+(all|exchanges|queues)?\s*(\S+)\s+(\S+)\s+(\d+)$/ - n = $2 - applyto = $3 || 'all' - priority = $6 - definition = JSON.parse($5) + if line =~ %r{^(\S+)\s+(\S+)\s+(all|exchanges|queues)?\s*(\S+)\s+(\S+)\s+(\d+)$} + n = Regexp.last_match(2) + applyto = Regexp.last_match(3) || 'all' + priority = Regexp.last_match(6) + definition = JSON.parse(Regexp.last_match(5)) # be aware that the gsub will reset the captures # from the regexp above - pattern = $4.to_s.gsub(/\\\\/, '\\') + pattern = Regexp.last_match(4).to_s.gsub(%r{\\\\}, '\\') @policies[vhost][n] = { - :applyto => applyto, - :pattern => pattern, - :definition => definition, - :priority => priority} + applyto: applyto, + pattern: pattern, + definition: definition, + priority: priority + } else raise Puppet::Error, "cannot parse line from list_policies:#{line}" end @@ -66,7 +66,7 @@ def pattern policies(should_vhost, should_policy)[:pattern] end - def pattern=(pattern) + def pattern=(_pattern) set_policy end @@ -74,7 +74,7 @@ def applyto policies(should_vhost, should_policy)[:applyto] end - def applyto=(applyto) + def applyto=(_applyto) set_policy end @@ -82,7 +82,7 @@ def definition policies(should_vhost, should_policy)[:definition] end - def definition=(definition) + def definition=(_definition) set_policy end @@ -90,7 +90,7 @@ def priority policies(should_vhost, should_policy)[:priority] end - def priority=(priority) + def priority=(_priority) set_policy end @@ -104,21 +104,19 @@ def set_policy # rabbitmq>=3.2.0 if Puppet::Util::Package.versioncmp(self.class.rabbitmq_version, '3.2.0') >= 0 rabbitmqctl('set_policy', - '-p', should_vhost, - '--priority', resource[:priority], - '--apply-to', resource[:applyto].to_s, - should_policy, - resource[:pattern], - resource[:definition].to_json - ) + '-p', should_vhost, + '--priority', resource[:priority], + '--apply-to', resource[:applyto].to_s, + should_policy, + resource[:pattern], + resource[:definition].to_json) else rabbitmqctl('set_policy', - '-p', should_vhost, - should_policy, - resource[:pattern], - resource[:definition].to_json, - resource[:priority] - ) + '-p', should_vhost, + should_policy, + resource[:pattern], + resource[:definition].to_json, + resource[:priority]) end end end diff --git a/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb index 6825129d5..e8c68d82c 100644 --- a/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb @@ -1,19 +1,18 @@ require 'json' require 'puppet' Puppet::Type.type(:rabbitmq_queue).provide(:rabbitmqadmin) do - if Puppet::PUPPETVERSION.to_f < 3 - commands :rabbitmqctl => 'rabbitmqctl' - commands :rabbitmqadmin => '/usr/local/bin/rabbitmqadmin' + commands rabbitmqctl: 'rabbitmqctl' + commands rabbitmqadmin: '/usr/local/bin/rabbitmqadmin' else has_command(:rabbitmqctl, 'rabbitmqctl') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do - environment :HOME => "/tmp" + environment HOME: '/tmp' end end - defaultfor :feature => :posix + defaultfor feature: :posix def should_vhost if @should_vhost @@ -24,34 +23,32 @@ def should_vhost end def self.all_vhosts - rabbitmqctl('list_vhosts', '-q').split(/\n/) + rabbitmqctl('list_vhosts', '-q').split(%r{\n}) end def self.all_queues(vhost) - rabbitmqctl('list_queues', '-q', '-p', vhost, 'name', 'durable', 'auto_delete', 'arguments').split(/\n/) + rabbitmqctl('list_queues', '-q', '-p', vhost, 'name', 'durable', 'auto_delete', 'arguments').split(%r{\n}) end def self.instances resources = [] all_vhosts.each do |vhost| - all_queues(vhost).collect do |line| - next if line =~ /^federation:/ + all_queues(vhost).map do |line| + next if line =~ %r{^federation:} name, durable, auto_delete, arguments = line.split("\t") # Convert output of arguments from the rabbitmqctl command to a json string. if !arguments.nil? - arguments = arguments.gsub(/^\[(.*)\]$/, "").gsub(/\{("(?:.|\\")*?"),/, '{\1:').gsub(/\},\{/, ",") - if arguments == "" - arguments = '{}' - end + arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',') + arguments = '{}' if arguments == '' else arguments = '{}' end queue = { - :durable => durable, - :auto_delete => auto_delete, - :arguments => JSON.parse(arguments), - :ensure => :present, - :name => "%s@%s" % [name, vhost], + durable: durable, + auto_delete: auto_delete, + arguments: JSON.parse(arguments), + ensure: :present, + name: format('%s@%s', name, vhost) } resources << new(queue) if queue[:name] end @@ -62,7 +59,7 @@ def self.instances def self.prefetch(resources) packages = instances resources.keys.each do |name| - if provider = packages.find{ |pkg| pkg.name == name } + if provider = packages.find { |pkg| pkg.name == name } resources[name].provider = provider end end @@ -76,21 +73,18 @@ def create vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : '' name = resource[:name].rpartition('@').first arguments = resource[:arguments] - if arguments.nil? - arguments = {} - end + arguments = {} if arguments.nil? rabbitmqadmin('declare', - 'queue', - vhost_opt, - "--user=#{resource[:user]}", - "--password=#{resource[:password]}", - '-c', - '/etc/rabbitmq/rabbitmqadmin.conf', - "name=#{name}", - "durable=#{resource[:durable]}", - "auto_delete=#{resource[:auto_delete]}", - "arguments=#{arguments.to_json}" - ) + 'queue', + vhost_opt, + "--user=#{resource[:user]}", + "--password=#{resource[:password]}", + '-c', + '/etc/rabbitmq/rabbitmqadmin.conf', + "name=#{name}", + "durable=#{resource[:durable]}", + "auto_delete=#{resource[:auto_delete]}", + "arguments=#{arguments.to_json}") @property_hash[:ensure] = :present end @@ -100,5 +94,4 @@ def destroy rabbitmqadmin('delete', 'queue', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "name=#{name}") @property_hash[:ensure] = :absent end - end diff --git a/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb index fd3732d45..442e1eae1 100644 --- a/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb @@ -1,24 +1,23 @@ require 'puppet' require 'set' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmqctl) do - +Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl, parent: Puppet::Provider::Rabbitmqctl) do if Puppet::PUPPETVERSION.to_f < 3 - commands :rabbitmqctl => 'rabbitmqctl' + commands rabbitmqctl: 'rabbitmqctl' else - has_command(:rabbitmqctl, 'rabbitmqctl') do - environment :HOME => "/tmp" - end + has_command(:rabbitmqctl, 'rabbitmqctl') do + environment HOME: '/tmp' + end end - defaultfor :feature => :posix + defaultfor feature: :posix def self.instances - self.run_with_retries { + run_with_retries do rabbitmqctl('-q', 'list_users') - }.split(/\n/).collect do |line| - if line =~ /^(\S+)(\s+\[.*?\]|)$/ - new(:name => $1) + end.split(%r{\n}).map do |line| + if line =~ %r{^(\S+)(\s+\[.*?\]|)$} + new(name: Regexp.last_match(1)) else raise Puppet::Error, "Cannot parse invalid user line: #{line}" end @@ -27,12 +26,8 @@ def self.instances def create rabbitmqctl('add_user', resource[:name], resource[:password]) - if resource[:admin] == :true - make_user_admin() - end - if ! resource[:tags].empty? - set_user_tags(resource[:tags]) - end + make_user_admin if resource[:admin] == :true + set_user_tags(resource[:tags]) unless resource[:tags].empty? end def change_password @@ -43,15 +38,14 @@ def password nil end - def check_password - response = self.class.run_with_retries { - rabbitmqctl('eval', 'rabbit_access_control:check_user_pass_login(list_to_binary("' + resource[:name] + '"), list_to_binary("' + resource[:password] +'")).') - } + response = self.class.run_with_retries do + rabbitmqctl('eval', 'rabbit_access_control:check_user_pass_login(list_to_binary("' + resource[:name] + '"), list_to_binary("' + resource[:password] + '")).') + end if response.include? 'refused' - false + false else - true + true end end @@ -60,28 +54,22 @@ def destroy end def exists? - self.class.run_with_retries { + self.class.run_with_retries do rabbitmqctl('-q', 'list_users') - }.split(/\n/).detect do |line| - line.match(/^#{Regexp.escape(resource[:name])}(\s+(\[.*?\]|\S+)|)$/) + end.split(%r{\n}).find do |line| + line.match(%r{^#{Regexp.escape(resource[:name])}(\s+(\[.*?\]|\S+)|)$}) end end - def tags tags = get_user_tags # do not expose the administrator tag for admins - if resource[:admin] == :true - tags.delete('administrator') - end + tags.delete('administrator') if resource[:admin] == :true tags.entries.sort end - def tags=(tags) - if ! tags.nil? - set_user_tags(tags) - end + set_user_tags(tags) unless tags.nil? end def admin @@ -94,7 +82,7 @@ def admin def admin=(state) if state == :true - make_user_admin() + make_user_admin else usertags = get_user_tags usertags.delete('administrator') @@ -103,12 +91,10 @@ def admin=(state) end def set_user_tags(tags) - is_admin = get_user_tags().member?("administrator") \ + is_admin = get_user_tags.member?('administrator') \ || resource[:admin] == :true usertags = Set.new(tags) - if is_admin - usertags.add("administrator") - end + usertags.add('administrator') if is_admin rabbitmqctl('set_user_tags', resource[:name], usertags.entries.sort) end @@ -119,10 +105,11 @@ def make_user_admin end private + def get_user_tags - match = rabbitmqctl('-q', 'list_users').split(/\n/).collect do |line| - line.match(/^#{Regexp.escape(resource[:name])}\s+\[(.*?)\]/) + match = rabbitmqctl('-q', 'list_users').split(%r{\n}).map do |line| + line.match(%r{^#{Regexp.escape(resource[:name])}\s+\[(.*?)\]}) end.compact.first - Set.new(match[1].split(' ').map{|x| x.gsub(/,$/, '')}) if match + Set.new(match[1].split(' ').map { |x| x.gsub(%r{,$}, '') }) if match end end diff --git a/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb index a0b8b5a1a..dbc7576cc 100644 --- a/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb @@ -1,28 +1,27 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmqctl) do - +Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl, parent: Puppet::Provider::Rabbitmqctl) do if Puppet::PUPPETVERSION.to_f < 3 - commands :rabbitmqctl => 'rabbitmqctl' + commands rabbitmqctl: 'rabbitmqctl' else - has_command(:rabbitmqctl, 'rabbitmqctl') do - environment :HOME => "/tmp" - end + has_command(:rabbitmqctl, 'rabbitmqctl') do + environment HOME: '/tmp' + end end - defaultfor :feature=> :posix + defaultfor :feature => :posix # cache users permissions def self.users(name, vhost) @users = {} unless @users unless @users[name] @users[name] = {} - self.run_with_retries { + run_with_retries do rabbitmqctl('-q', 'list_user_permissions', name) - }.split(/\n/).each do |line| - line = self::strip_backslashes(line) - if line =~ /^(\S+)\s+(\S*)\s+(\S*)\s+(\S*)$/ - @users[name][$1] = - {:configure => $2, :read => $4, :write => $3} + end.split(%r{\n}).each do |line| + line = .strip_backslashes(line) + if line =~ %r{^(\S+)\s+(\S*)\s+(\S*)\s+(\S*)$} + @users[name][Regexp.last_match(1)] = + { configure: Regexp.last_match(2), read: Regexp.last_match(4), write: Regexp.last_match(3) } else raise Puppet::Error, "cannot parse line from list_user_permissions:#{line}" end @@ -72,7 +71,7 @@ def configure_permission users(should_user, should_vhost)[:configure] end - def configure_permission=(perm) + def configure_permission=(_perm) set_permissions end @@ -80,7 +79,7 @@ def read_permission users(should_user, should_vhost)[:read] end - def read_permission=(perm) + def read_permission=(_perm) set_permissions end @@ -88,7 +87,7 @@ def write_permission users(should_user, should_vhost)[:write] end - def write_permission=(perm) + def write_permission=(_perm) set_permissions end @@ -100,15 +99,14 @@ def set_permissions resource[:read_permission] ||= read_permission resource[:write_permission] ||= write_permission rabbitmqctl('set_permissions', '-p', should_vhost, should_user, - resource[:configure_permission], resource[:write_permission], - resource[:read_permission] - ) + resource[:configure_permission], resource[:write_permission], + resource[:read_permission] + ) end end def self.strip_backslashes(string) # See: https://github.com/rabbitmq/rabbitmq-server/blob/v1_7/docs/rabbitmqctl.1.pod#output-escaping - string.gsub(/\\\\/, '\\') + string.gsub(%r{\\\\}, '\\') end - end diff --git a/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb index 070cddf10..995b25783 100644 --- a/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb @@ -1,20 +1,19 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl')) -Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmqctl) do - +Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, parent: Puppet::Provider::Rabbitmqctl) do if Puppet::PUPPETVERSION.to_f < 3 - commands :rabbitmqctl => 'rabbitmqctl' + commands rabbitmqctl: 'rabbitmqctl' else - has_command(:rabbitmqctl, 'rabbitmqctl') do - environment :HOME => "/tmp" - end + has_command(:rabbitmqctl, 'rabbitmqctl') do + environment HOME: '/tmp' + end end def self.instances - self.run_with_retries { + run_with_retries do rabbitmqctl('-q', 'list_vhosts') - }.split(/\n/).map do |line| - if line =~ /^(\S+)$/ - new(:name => $1) + end.split(%r{\n}).map do |line| + if line =~ %r{^(\S+)$} + new(name: Regexp.last_match(1)) else raise Puppet::Error, "Cannot parse invalid vhost line: #{line}" end @@ -30,11 +29,10 @@ def destroy end def exists? - out = self.class.run_with_retries { + out = self.class.run_with_retries do rabbitmqctl('-q', 'list_vhosts') - }.split(/\n/).detect do |line| - line.match(/^#{Regexp.escape(resource[:name])}$/) + end.split(%r{\n}).find do |line| + line.match(%r{^#{Regexp.escape(resource[:name])}$}) end end - end diff --git a/lib/puppet/provider/rabbitmqctl.rb b/lib/puppet/provider/rabbitmqctl.rb index c2476dc28..bfc27cf9f 100644 --- a/lib/puppet/provider/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmqctl.rb @@ -1,10 +1,10 @@ class Puppet::Provider::Rabbitmqctl < Puppet::Provider initvars - commands :rabbitmqctl => 'rabbitmqctl' + commands rabbitmqctl: 'rabbitmqctl' def self.rabbitmq_version output = rabbitmqctl('-q', 'status') - version = output.match(/\{rabbit,"RabbitMQ","([\d\.]+)"\}/) + version = output.match(%r{\{rabbit,"RabbitMQ","([\d\.]+)"\}}) version[1] if version end @@ -13,10 +13,10 @@ def self.rabbitmq_version # Limit each query time by 'timeout'. # For example: # users = self.class.run_with_retries { rabbitmqctl 'list_users' } - def self.run_with_retries(count=30, step=6, timeout=10) - count.times do |n| + def self.run_with_retries(count = 30, step = 6, timeout = 10) + count.times do |_n| begin - output = Timeout::timeout(timeout) do + output = Timeout.timeout(timeout) do yield end rescue Puppet::ExecutionFailure, Timeout::Error @@ -29,5 +29,4 @@ def self.run_with_retries(count=30, step=6, timeout=10) end raise Puppet::Error, "Command is still failing after #{count * step} seconds expired!" end - end diff --git a/lib/puppet/type/rabbitmq_binding.rb b/lib/puppet/type/rabbitmq_binding.rb index 7de3b7dac..9da7ef19d 100644 --- a/lib/puppet/type/rabbitmq_binding.rb +++ b/lib/puppet/type/rabbitmq_binding.rb @@ -16,18 +16,18 @@ def self.title_patterns [ [ - /(^([^@]*)$)/m, + %r{(^([^@]*)$)}m, [ - [ :name ] + [:name] ] ], [ - /^((\S+)@(\S+)@(\S+))$/m, + %r{^((\S+)@(\S+)@(\S+))$}m, [ - [ :name ], - [ :source ], - [ :destination], - [ :vhost ] + [:name], + [:source], + [:destination], + [:vhost] ] ] ] @@ -42,21 +42,21 @@ def self.title_patterns newproperty(:source) do desc 'source of binding' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) isnamevar end newproperty(:destination) do desc 'destination of binding' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) isnamevar end newproperty(:vhost) do desc 'vhost' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) defaultto('/') isnamevar end @@ -64,13 +64,13 @@ def self.title_patterns newproperty(:routing_key) do desc 'binding routing_key' - newvalues(/^\S*$/) + newvalues(%r{^\S*$}) isnamevar end newproperty(:destination_type) do desc 'binding destination_type' - newvalues(/queue|exchange/) + newvalues(%r{queue|exchange}) defaultto('queue') end @@ -85,19 +85,19 @@ def self.title_patterns newparam(:user) do desc 'The user to use to connect to rabbitmq' defaultto('guest') - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end newparam(:password) do desc 'The password to use to connect to rabbitmq' defaultto('guest') - newvalues(/\S+/) + newvalues(%r{\S+}) end autorequire(:rabbitmq_vhost) do setup_autorequire('vhost') end - + autorequire(:rabbitmq_exchange) do setup_autorequire('exchange') end @@ -125,27 +125,26 @@ def setup_autorequire(type) rval.push("#{self[:destination]}@#{self[:vhost]}") end else - if destination_type == type - rval = ["#{self[:destination]}@#{self[:vhost]}"] - else - rval = [] - end + rval = if destination_type == type + ["#{self[:destination]}@#{self[:vhost]}"] + else + [] + end end rval end def validate_argument(argument) unless [Hash].include?(argument.class) - raise ArgumentError, "Invalid argument" + raise ArgumentError, 'Invalid argument' end end # Validate that we have both source and destination now that these are not # necessarily only coming from the resource title. validate do - unless self[:source] and self[:destination] - raise ArgumentError, "Source and destination must both be defined." + unless self[:source] && self[:destination] + raise ArgumentError, 'Source and destination must both be defined.' end end - end diff --git a/lib/puppet/type/rabbitmq_erlang_cookie.rb b/lib/puppet/type/rabbitmq_erlang_cookie.rb index c2e5898dc..6f96717c8 100644 --- a/lib/puppet/type/rabbitmq_erlang_cookie.rb +++ b/lib/puppet/type/rabbitmq_erlang_cookie.rb @@ -1,13 +1,13 @@ Puppet::Type.newtype(:rabbitmq_erlang_cookie) do desc 'Type to manage the rabbitmq erlang cookie securely' - newparam(:path, :namevar => true) + newparam(:path, namevar: true) newproperty(:content) do desc 'Content of cookie' - newvalues(/^\S+$/) - def change_to_s(current, desired) - "The rabbitmq erlang cookie was changed" + newvalues(%r{^\S+$}) + def change_to_s(_current, _desired) + 'The rabbitmq erlang cookie was changed' end end @@ -29,6 +29,6 @@ def change_to_s(current, desired) end newparam(:service_name) do - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end end diff --git a/lib/puppet/type/rabbitmq_exchange.rb b/lib/puppet/type/rabbitmq_exchange.rb index 7dd0a1ff9..1d594d2f9 100644 --- a/lib/puppet/type/rabbitmq_exchange.rb +++ b/lib/puppet/type/rabbitmq_exchange.rb @@ -11,31 +11,31 @@ end end - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'Name of exchange' - newvalues(/^\S*@\S+$/) + newvalues(%r{^\S*@\S+$}) end newparam(:type) do desc 'Exchange type to be set *on creation*' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end newparam(:durable) do desc 'Exchange durability to be set *on creation*' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) defaultto 'false' end newparam(:auto_delete) do desc 'Exchange auto delete option to be set *on creation*' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) defaultto 'false' end newparam(:internal) do desc 'Exchange internal option to be set *on creation*' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) defaultto 'false' end @@ -47,17 +47,17 @@ newparam(:user) do desc 'The user to use to connect to rabbitmq' defaultto('guest') - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end newparam(:password) do desc 'The password to use to connect to rabbitmq' defaultto('guest') - newvalues(/\S+/) + newvalues(%r{\S+}) end validate do - if self[:ensure] == :present and self[:type].nil? + if self[:ensure] == :present && self[:type].nil? raise ArgumentError, "must set type when creating exchange for #{self[:name]} whose type is #{self[:type]}" end end @@ -73,5 +73,4 @@ autorequire(:rabbitmq_user_permissions) do ["#{self[:user]}@#{self[:name].split('@')[1]}"] end - end diff --git a/lib/puppet/type/rabbitmq_parameter.rb b/lib/puppet/type/rabbitmq_parameter.rb index 03934c7e1..f7c486ce2 100644 --- a/lib/puppet/type/rabbitmq_parameter.rb +++ b/lib/puppet/type/rabbitmq_parameter.rb @@ -1,5 +1,4 @@ Puppet::Type.newtype(:rabbitmq_parameter) do - desc 'Type for managing rabbitmq parameters' ensurable do @@ -15,13 +14,13 @@ autorequire(:service) { 'rabbitmq-server' } validate do - fail('component_name parameter is required.') if self[:ensure] == :present and self[:component_name].nil? - fail('value parameter is required.') if self[:ensure] == :present and self[:value].nil? + raise('component_name parameter is required.') if self[:ensure] == :present && self[:component_name].nil? + raise('value parameter is required.') if self[:ensure] == :present && self[:value].nil? end - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'combination of name@vhost to set parameter for' - newvalues(/^\S+@\S+$/) + newvalues(%r{^\S+@\S+$}) end newproperty(:component_name) do @@ -46,27 +45,21 @@ end def validate_component_name(value) - if value.empty? - raise ArgumentError, "component_name must be defined" - end + raise ArgumentError, 'component_name must be defined' if value.empty? end def validate_value(value) - unless [Hash].include?(value.class) - raise ArgumentError, "Invalid value" - end - value.each do |k,v| + raise ArgumentError, 'Invalid value' unless [Hash].include?(value.class) + value.each do |_k, v| unless [String, TrueClass, FalseClass].include?(v.class) - raise ArgumentError, "Invalid value" + raise ArgumentError, 'Invalid value' end end end def munge_value(value) - value.each do |k,v| - if (v =~ /\A[-+]?[0-9]+\z/) - value[k] = v.to_i - end + value.each do |k, v| + value[k] = v.to_i if v =~ %r{\A[-+]?[0-9]+\z} end value end diff --git a/lib/puppet/type/rabbitmq_plugin.rb b/lib/puppet/type/rabbitmq_plugin.rb index cc9f10c6f..0f900c081 100644 --- a/lib/puppet/type/rabbitmq_plugin.rb +++ b/lib/puppet/type/rabbitmq_plugin.rb @@ -11,21 +11,20 @@ end end - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do 'name of the plugin to enable' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end newparam(:umask) do - desc "Sets the octal umask to be used while creating this resource" + desc 'Sets the octal umask to be used while creating this resource' defaultto '0022' munge do |value| - if value =~ /^0?[0-7]{1,3}$/ + if value =~ %r{^0?[0-7]{1,3}$} return value.to_i(8) else raise Puppet::Error, "The umask specification is invalid: #{value.inspect}" end end end - end diff --git a/lib/puppet/type/rabbitmq_policy.rb b/lib/puppet/type/rabbitmq_policy.rb index 03a3e613e..e80f25e7d 100644 --- a/lib/puppet/type/rabbitmq_policy.rb +++ b/lib/puppet/type/rabbitmq_policy.rb @@ -14,13 +14,13 @@ autorequire(:service) { 'rabbitmq-server' } validate do - fail('pattern parameter is required.') if self[:ensure] == :present and self[:pattern].nil? - fail('definition parameter is required.') if self[:ensure] == :present and self[:definition].nil? + raise('pattern parameter is required.') if self[:ensure] == :present && self[:pattern].nil? + raise('definition parameter is required.') if self[:ensure] == :present && self[:definition].nil? end - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'combination of policy@vhost to create policy for' - newvalues(/^\S+@\S+$/) + newvalues(%r{^\S+@\S+$}) end newproperty(:pattern) do @@ -50,7 +50,7 @@ newproperty(:priority) do desc 'policy priority' - newvalues(/^\d+$/) + newvalues(%r{^\d+$}) defaultto 0 end @@ -59,18 +59,16 @@ end def validate_pattern(value) - begin - Regexp.new(value) - rescue RegexpError - raise ArgumentError, "Invalid regexp #{value}" - end + Regexp.new(value) + rescue RegexpError + raise ArgumentError, "Invalid regexp #{value}" end def validate_definition(definition) unless [Hash].include?(definition.class) - raise ArgumentError, "Invalid definition" + raise ArgumentError, 'Invalid definition' end - definition.each do |k,v| + definition.each do |k, v| if k == 'ha-params' && definition['ha-mode'] == 'nodes' unless [Array].include?(v.class) raise ArgumentError, "Invalid definition, value #{v} for key #{k} is not an array" diff --git a/lib/puppet/type/rabbitmq_queue.rb b/lib/puppet/type/rabbitmq_queue.rb index 464a2ca6e..642ba4ed3 100644 --- a/lib/puppet/type/rabbitmq_queue.rb +++ b/lib/puppet/type/rabbitmq_queue.rb @@ -11,20 +11,20 @@ end end - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'Name of queue' - newvalues(/^\S*@\S+$/) + newvalues(%r{^\S*@\S+$}) end newparam(:durable) do desc 'Queue is durable' - newvalues(/true|false/) + newvalues(%r{true|false}) defaultto('true') end - + newparam(:auto_delete) do desc 'Queue will be auto deleted' - newvalues(/true|false/) + newvalues(%r{true|false}) defaultto('false') end @@ -39,13 +39,13 @@ newparam(:user) do desc 'The user to use to connect to rabbitmq' defaultto('guest') - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end newparam(:password) do desc 'The password to use to connect to rabbitmq' defaultto('guest') - newvalues(/\S+/) + newvalues(%r{\S+}) end autorequire(:rabbitmq_vhost) do @@ -62,7 +62,7 @@ def validate_argument(argument) unless [Hash].include?(argument.class) - raise ArgumentError, "Invalid argument" + raise ArgumentError, 'Invalid argument' end end end diff --git a/lib/puppet/type/rabbitmq_user.rb b/lib/puppet/type/rabbitmq_user.rb index c541afe46..0b51f9bc4 100644 --- a/lib/puppet/type/rabbitmq_user.rb +++ b/lib/puppet/type/rabbitmq_user.rb @@ -13,30 +13,33 @@ autorequire(:service) { 'rabbitmq-server' } - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'Name of user' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end newproperty(:password) do desc 'User password to be set *on creation* and validated each run' - def insync?(is) + def insync?(_is) provider.check_password end - def set(value) + + def set(_value) provider.change_password end - def change_to_s(current, desired) - "password has been changed" + + def change_to_s(_current, _desired) + 'password has been changed' end - def should_to_s(newvalue = @should) + + def should_to_s(_newvalue = @should) '' end end newproperty(:admin) do desc 'whether or not user should be an admin' - newvalues(/true|false/) + newvalues(%r{true|false}) munge do |value| # converting to_s in case its a boolean value.to_s.to_sym @@ -44,21 +47,21 @@ def should_to_s(newvalue = @should) defaultto :false end - newproperty(:tags, :array_matching => :all) do + newproperty(:tags, array_matching: :all) do desc 'additional tags for the user' validate do |value| - unless value =~ /^\S+$/ + unless value =~ %r{^\S+$} raise ArgumentError, "Invalid tag: #{value.inspect}" end - if value == "administrator" - raise ArgumentError, "must use admin property instead of administrator tag" + if value == 'administrator' + raise ArgumentError, 'must use admin property instead of administrator tag' end end defaultto [] def insync?(is) - self.is_to_s(is) == self.should_to_s + is_to_s(is) == should_to_s end def is_to_s(currentvalue = @is) @@ -76,13 +79,11 @@ def should_to_s(newvalue = @should) '[]' end end - end validate do - if self[:ensure] == :present and ! self[:password] + if self[:ensure] == :present && !self[:password] raise ArgumentError, 'must set password when creating user' unless self[:password] end end - end diff --git a/lib/puppet/type/rabbitmq_user_permissions.rb b/lib/puppet/type/rabbitmq_user_permissions.rb index 1dbbda8a6..48931ad6c 100644 --- a/lib/puppet/type/rabbitmq_user_permissions.rb +++ b/lib/puppet/type/rabbitmq_user_permissions.rb @@ -13,9 +13,9 @@ autorequire(:service) { 'rabbitmq-server' } - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'combination of user@vhost to grant privileges to' - newvalues(/^\S+@\S+$/) + newvalues(%r{^\S+@\S+$}) end newproperty(:configure_permission) do @@ -48,11 +48,8 @@ end def validate_permissions(value) - begin - Regexp.new(value) - rescue RegexpError - raise ArgumentError, "Invalid regexp #{value}" - end + Regexp.new(value) + rescue RegexpError + raise ArgumentError, "Invalid regexp #{value}" end - end diff --git a/lib/puppet/type/rabbitmq_vhost.rb b/lib/puppet/type/rabbitmq_vhost.rb index 1349be6e5..ecb0cc4a5 100644 --- a/lib/puppet/type/rabbitmq_vhost.rb +++ b/lib/puppet/type/rabbitmq_vhost.rb @@ -13,9 +13,8 @@ autorequire(:service) { 'rabbitmq-server' } - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do 'name of the vhost to add' - newvalues(/^\S+$/) + newvalues(%r{^\S+$}) end - end diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 5e19f6235..6b7f91adf 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -16,8 +16,8 @@ service_name = 'rabbitmq' end - context "default class inclusion" do - it 'should run successfully' do + context 'default class inclusion' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': } if $::osfamily == 'RedHat' { @@ -27,12 +27,12 @@ class { 'erlang': epel_enable => true} EOS # Apply twice to ensure no errors the second time. - apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero + apply_manifest(pp, catch_failures: true) + expect(apply_manifest(pp, catch_changes: true).exit_code).to be_zero end describe package(package_name) do - it { is_expected.to be_installed } + it { is_expected.to be_installed } end describe service(service_name) do @@ -41,8 +41,8 @@ class { 'erlang': epel_enable => true} end end - context "disable and stop service" do - it 'should run successfully' do + context 'disable and stop service' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': service_ensure => 'stopped', @@ -53,7 +53,7 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do @@ -62,8 +62,8 @@ class { 'erlang': epel_enable => true} end end - context "service is unmanaged" do - it 'should run successfully' do + context 'service is unmanaged' do + it 'runs successfully' do pp_pre = <<-EOS class { 'rabbitmq': } if $::osfamily == 'RedHat' { @@ -83,8 +83,8 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp_pre, :catch_failures => true) - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp_pre, catch_failures: true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do @@ -94,7 +94,7 @@ class { 'erlang': epel_enable => true} end context 'binding on all interfaces' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': service_manage => true, @@ -104,7 +104,7 @@ class { 'rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do @@ -113,18 +113,18 @@ class { 'rabbitmq': describe port(5672) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end - describe port(15672) do + describe port(15_672) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end - describe port(25672) do - xit "Is on 55672 instead on older rmq versions" do + describe port(25_672) do + xit 'Is on 55672 instead on older rmq versions' do is_expected.to be_listening.on('0.0.0.0').with('tcp') end end end context 'binding to localhost only' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': service_manage => true, @@ -134,7 +134,7 @@ class { 'rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do @@ -143,19 +143,19 @@ class { 'rabbitmq': describe port(5672) do it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end - describe port(15672) do + describe port(15_672) do it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end # This listens on all interfaces regardless of these settings - describe port(25672) do - xit "Is on 55672 instead on older rmq versions" do + describe port(25_672) do + xit 'Is on 55672 instead on older rmq versions' do is_expected.to be_listening.on('0.0.0.0').with('tcp') end end end context 'different management_ip_address and node_ip_address' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': service_manage => true, @@ -166,7 +166,7 @@ class { 'rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do @@ -175,14 +175,13 @@ class { 'rabbitmq': describe port(5672) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end - describe port(15672) do + describe port(15_672) do it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end - describe port(25672) do - xit "Is on 55672 instead on older rmq versions" do + describe port(25_672) do + xit 'Is on 55672 instead on older rmq versions' do is_expected.to be_listening.on('0.0.0.0').with('tcp') end end end - end diff --git a/spec/acceptance/clustering_spec.rb b/spec/acceptance/clustering_spec.rb index 274284be9..9d1539f04 100644 --- a/spec/acceptance/clustering_spec.rb +++ b/spec/acceptance/clustering_spec.rb @@ -2,9 +2,9 @@ describe 'rabbitmq clustering' do context 'rabbitmq::wipe_db_on_cookie_change => false' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS - class { 'rabbitmq': + class { 'rabbitmq': config_cluster => true, cluster_nodes => ['rabbit1', 'rabbit2'], cluster_node_type => 'ram', @@ -17,18 +17,17 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp, :expect_failures => true) + apply_manifest(pp, expect_failures: true) end describe file('/var/lib/rabbitmq/.erlang.cookie') do it { is_expected.not_to contain 'TESTCOOKIE' } end - end context 'rabbitmq::wipe_db_on_cookie_change => true' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS - class { 'rabbitmq': + class { 'rabbitmq': config_cluster => true, cluster_nodes => ['rabbit1', 'rabbit2'], cluster_node_type => 'ram', @@ -41,7 +40,7 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe file('/etc/rabbitmq/rabbitmq.config') do diff --git a/spec/acceptance/delete_guest_user_spec.rb b/spec/acceptance/delete_guest_user_spec.rb index 6d2494248..462160edb 100644 --- a/spec/acceptance/delete_guest_user_spec.rb +++ b/spec/acceptance/delete_guest_user_spec.rb @@ -2,9 +2,9 @@ describe 'rabbitmq with delete_guest_user' do context 'delete_guest_user' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS - class { 'rabbitmq': + class { 'rabbitmq': port => 5672, delete_guest_user => true, } @@ -14,7 +14,7 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) shell('rabbitmqctl list_users > /tmp/rabbitmqctl_users') end diff --git a/spec/acceptance/parameter_spec.rb b/spec/acceptance/parameter_spec.rb index e7914f606..e80ad70df 100644 --- a/spec/acceptance/parameter_spec.rb +++ b/spec/acceptance/parameter_spec.rb @@ -1,9 +1,8 @@ require 'spec_helper_acceptance' describe 'rabbitmq parameter on a vhost:' do - - context "create parameter resource" do - it 'should run successfully' do + context 'create parameter resource' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -33,16 +32,15 @@ class { '::rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - it 'should have the parameter' do + it 'has the parameter' do shell('rabbitmqctl list_parameters -p fedhost') do |r| - expect(r.stdout).to match(/federation-upstream.*documentumFed.*expires.*3600000/) + expect(r.stdout).to match(%r{federation-upstream.*documentumFed.*expires.*3600000}) expect(r.exit_code).to be_zero end end - end end diff --git a/spec/acceptance/policy_spec.rb b/spec/acceptance/policy_spec.rb index 4757a00a1..aca77f813 100644 --- a/spec/acceptance/policy_spec.rb +++ b/spec/acceptance/policy_spec.rb @@ -1,10 +1,8 @@ require 'spec_helper_acceptance' describe 'rabbitmq policy on a vhost:' do - - - context "create policy resource" do - it 'should run successfully' do + context 'create policy resource' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -41,23 +39,20 @@ class { '::rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) # Apply twice to ensure no changes the second time. - apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero - + apply_manifest(pp, catch_failures: true) + expect(apply_manifest(pp, catch_changes: true).exit_code).to be_zero end - it 'should have the policy' do + it 'has the policy' do shell('rabbitmqctl list_policies -p myhost') do |r| - expect(r.stdout).to match(/myhost.*ha-all.*ha-sync-mode/) - expect(r.stdout).to match(/myhost.*eu-federation/) + expect(r.stdout).to match(%r{myhost.*ha-all.*ha-sync-mode}) + expect(r.stdout).to match(%r{myhost.*eu-federation}) expect(r.exit_code).to be_zero end end - end end diff --git a/spec/acceptance/queue_spec.rb b/spec/acceptance/queue_spec.rb index 45f59ca42..ffa9d003e 100644 --- a/spec/acceptance/queue_spec.rb +++ b/spec/acceptance/queue_spec.rb @@ -1,9 +1,8 @@ require 'spec_helper_acceptance' describe 'rabbitmq binding:' do - - context "create binding and queue resources when using default management port" do - it 'should run successfully' do + context 'create binding and queue resources when using default management port' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -57,29 +56,27 @@ class { '::rabbitmq': EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - it 'should have the binding' do + it 'has the binding' do shell('rabbitmqctl list_bindings -q -p host1') do |r| - expect(r.stdout).to match(/exchange1\sexchange\squeue1\squeue\s#/) + expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#}) expect(r.exit_code).to be_zero end end - it 'should have the queue' do + it 'has the queue' do shell('rabbitmqctl list_queues -q -p host1') do |r| - expect(r.stdout).to match(/queue1/) + expect(r.stdout).to match(%r{queue1}) expect(r.exit_code).to be_zero end end - end - - context "create multiple bindings when same source / destination / vhost but different routing keys" do - it 'should run successfully' do + context 'create multiple bindings when same source / destination / vhost but different routing keys' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -147,22 +144,21 @@ class { '::rabbitmq': EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - it 'should have the bindings' do + it 'has the bindings' do shell('rabbitmqctl list_bindings -q -p host1') do |r| - expect(r.stdout).to match(/exchange1\sexchange\squeue1\squeue\stest1/) - expect(r.stdout).to match(/exchange1\sexchange\squeue1\squeue\stest2/) + expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1}) + expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest2}) expect(r.exit_code).to be_zero end end - end - context "create binding and queue resources when using a non-default management port" do - it 'should run successfully' do + context 'create binding and queue resources when using a non-default management port' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -217,24 +213,22 @@ class { '::rabbitmq': EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - it 'should have the binding' do + it 'has the binding' do shell('rabbitmqctl list_bindings -q -p host2') do |r| - expect(r.stdout).to match(/exchange2\sexchange\squeue2\squeue\s#/) + expect(r.stdout).to match(%r{exchange2\sexchange\squeue2\squeue\s#}) expect(r.exit_code).to be_zero end end - it 'should have the queue' do + it 'has the queue' do shell('rabbitmqctl list_queues -q -p host2') do |r| - expect(r.stdout).to match(/queue2/) + expect(r.stdout).to match(%r{queue2}) expect(r.exit_code).to be_zero end end - end - end diff --git a/spec/acceptance/rabbitmqadmin_spec.rb b/spec/acceptance/rabbitmqadmin_spec.rb index ecd603c5c..fb1b0d192 100644 --- a/spec/acceptance/rabbitmqadmin_spec.rb +++ b/spec/acceptance/rabbitmqadmin_spec.rb @@ -2,7 +2,7 @@ describe 'rabbitmq::install::rabbitmqadmin class' do context 'downloads the cli tools' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': admin_enable => true, @@ -14,7 +14,7 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe file('/var/lib/rabbitmq/rabbitmqadmin') do @@ -23,7 +23,7 @@ class { 'erlang': epel_enable => true} end context 'does nothing if service is unmanaged' do - it 'should run successfully' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq': admin_enable => true, @@ -36,7 +36,7 @@ class { 'erlang': epel_enable => true} EOS shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe file('/var/lib/rabbitmq/rabbitmqadmin') do @@ -45,7 +45,7 @@ class { 'erlang': epel_enable => true} end context 'works with specified default credentials' do - it 'should run successfully' do + it 'runs successfully' do # make sure credential change takes effect before admin_enable pp_pre = <<-EOS class { 'rabbitmq': @@ -73,13 +73,12 @@ class { 'erlang': epel_enable => true} EOS shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') - apply_manifest(pp_pre, :catch_failures => true) - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp_pre, catch_failures: true) + apply_manifest(pp, catch_failures: true) end describe file('/var/lib/rabbitmq/rabbitmqadmin') do it { is_expected.to be_file } end end - end diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index 89929b44a..120c9d3f3 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -16,8 +16,8 @@ service_name = 'rabbitmq' end - context "default class inclusion" do - it 'should run successfully' do + context 'default class inclusion' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq::server': } if $::osfamily == 'RedHat' { @@ -27,12 +27,12 @@ class { 'erlang': epel_enable => true} EOS # Apply twice to ensure no errors the second time. - apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero + apply_manifest(pp, catch_failures: true) + expect(apply_manifest(pp, catch_changes: true).exit_code).to be_zero end describe package(package_name) do - it { is_expected.to be_installed } + it { is_expected.to be_installed } end describe service(service_name) do @@ -41,8 +41,8 @@ class { 'erlang': epel_enable => true} end end - context "disable and stop service" do - it 'should run successfully' do + context 'disable and stop service' do + it 'runs successfully' do pp = <<-EOS class { 'rabbitmq::server': service_ensure => 'stopped', @@ -53,7 +53,7 @@ class { 'erlang': epel_enable => true} } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do @@ -62,8 +62,8 @@ class { 'erlang': epel_enable => true} end end - context "service is unmanaged" do - it 'should run successfully' do + context 'service is unmanaged' do + it 'runs successfully' do pp_pre = <<-EOS class { 'rabbitmq::server': } if $::osfamily == 'RedHat' { @@ -83,9 +83,8 @@ class { 'erlang': epel_enable => true} } EOS - - apply_manifest(pp_pre, :catch_failures => true) - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp_pre, catch_failures: true) + apply_manifest(pp, catch_failures: true) end describe service(service_name) do diff --git a/spec/acceptance/user_spec.rb b/spec/acceptance/user_spec.rb index ed88bfb7d..b8e09aea7 100644 --- a/spec/acceptance/user_spec.rb +++ b/spec/acceptance/user_spec.rb @@ -1,10 +1,8 @@ require 'spec_helper_acceptance' describe 'rabbitmq user:' do - - - context "create user resource" do - it 'should run successfully' do + context 'create user resource' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -23,16 +21,15 @@ class { '::rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - it 'should have the user' do + it 'has the user' do shell('rabbitmqctl list_users') do |r| - expect(r.stdout).to match(/dan.*administrator/) + expect(r.stdout).to match(%r{dan.*administrator}) expect(r.exit_code).to be_zero end end - end end diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index 88edcf904..6b5fad161 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -1,10 +1,8 @@ require 'spec_helper_acceptance' describe 'rabbitmq vhost:' do - - - context "create vhost resource" do - it 'should run successfully' do + context 'create vhost resource' do + it 'runs successfully' do pp = <<-EOS if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true } @@ -22,16 +20,15 @@ class { '::rabbitmq': } EOS - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end - it 'should have the vhost' do + it 'has the vhost' do shell('rabbitmqctl list_vhosts') do |r| - expect(r.stdout).to match(/myhost/) + expect(r.stdout).to match(%r{myhost}) expect(r.exit_code).to be_zero end end - end end diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index 189a17efe..a58b04e5d 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -1,19 +1,18 @@ require 'spec_helper' describe 'rabbitmq' do - context 'on unsupported distributions' do - let(:facts) {{ :osfamily => 'Unsupported' }} + let(:facts) { { osfamily: 'Unsupported' } } it 'we fail' do - expect { catalogue }.to raise_error(Puppet::Error, /not supported on an Unsupported/) + expect { catalogue }.to raise_error(Puppet::Error, %r{not supported on an Unsupported}) end end context 'on Debian' do with_debian_facts - it 'should not include rabbitmq::repo::apt' do - is_expected.not_to contain_class('rabbitmq::repo::apt') + it 'does not include rabbitmq::repo::apt' do + is_expected.not_to contain_class('rabbitmq::repo::apt') end it 'does ensure rabbitmq apt::source is absent when repos_ensure is false' do @@ -22,7 +21,8 @@ end context 'on Debian' do - let(:params) {{ :repos_ensure => true }} + let(:params) { { repos_ensure: true } } + with_debian_facts it 'includes rabbitmq::repo::apt' do @@ -30,244 +30,275 @@ end describe 'apt::source default values' do - it 'should add a repo with default values' do - is_expected.to contain_apt__source('rabbitmq').with( { - :ensure => 'present', - :location => 'http://www.rabbitmq.com/debian/', - :release => 'testing', - :repos => 'main', - }) + it 'adds a repo with default values' do + is_expected.to contain_apt__source('rabbitmq').with(ensure: 'present', + location: 'http://www.rabbitmq.com/debian/', + release: 'testing', + repos: 'main') end end context 'with file_limit => unlimited' do - let(:params) {{ :file_limit => 'unlimited' }} - it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n unlimited/) } + let(:params) { { file_limit: 'unlimited' } } + + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n unlimited}) } end context 'with file_limit => infinity' do - let(:params) {{ :file_limit => 'infinity' }} - it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n infinity/) } + let(:params) { { file_limit: 'infinity' } } + + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n infinity}) } end context 'with file_limit => \'-1\'' do - let(:params) {{ :file_limit => '-1' }} - it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n -1/) } + let(:params) { { file_limit: '-1' } } + + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n -1}) } end context 'with file_limit => \'1234\'' do - let(:params) {{ :file_limit => '1234' }} - it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) } + let(:params) { { file_limit: '1234' } } + + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n 1234}) } end context 'with file_limit => 1234' do - let(:params) {{ :file_limit => 1234 }} - it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) } + let(:params) { { file_limit: 1234 } } + + it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n 1234}) } end context 'with file_limit => \'-42\'' do - let(:params) {{ :file_limit => '-42' }} + let(:params) { { file_limit: '-42' } } + it 'does not compile' do - expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'/) + expect { catalogue }.to raise_error(Puppet::Error, %r{\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'}) end end context 'with file_limit => \'foo\'' do - let(:params) {{ :file_limit => 'foo' }} + let(:params) { { file_limit: 'foo' } } + it 'does not compile' do - expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'/) + expect { catalogue }.to raise_error(Puppet::Error, %r{\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'}) end end end context 'on Redhat' do with_redhat_facts - it 'should not include rabbitmq::repo::rhel' do + it 'does not include rabbitmq::repo::rhel' do is_expected.not_to contain_class('rabbitmq::repo::rhel') end context 'with file_limit => \'unlimited\'' do - let(:params) {{ :file_limit => 'unlimited' }} - it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile unlimited -rabbitmq hard nofile unlimited -' - ) } + let(:params) { { file_limit: 'unlimited' } } + + it { + is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Class[Rabbitmq::Service]', + 'content' => 'rabbitmq soft nofile unlimited + rabbitmq hard nofile unlimited + ' + ) + } end context 'with file_limit => \'infinity\'' do - let(:params) {{ :file_limit => 'infinity' }} - it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile infinity -rabbitmq hard nofile infinity -' - ) } + let(:params) { { file_limit: 'infinity' } } + + it { + is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Class[Rabbitmq::Service]', + 'content' => 'rabbitmq soft nofile infinity + rabbitmq hard nofile infinity + ' + ) + } end context 'with file_limit => \'-1\'' do - let(:params) {{ :file_limit => '-1' }} - it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile -1 -rabbitmq hard nofile -1 -' - ) } + let(:params) { { file_limit: '-1' } } + + it { + is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Class[Rabbitmq::Service]', + 'content' => 'rabbitmq soft nofile -1 + rabbitmq hard nofile -1 + ' + ) + } end context 'with file_limit => \'1234\'' do - let(:params) {{ :file_limit => '1234' }} - it { is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile 1234 -rabbitmq hard nofile 1234 -' - ) } + let(:params) { { file_limit: '1234' } } + + it { + is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Class[Rabbitmq::Service]', + 'content' => 'rabbitmq soft nofile 1234 + rabbitmq hard nofile 1234 + ' + ) + } end context 'with file_limit => \'-42\'' do - let(:params) {{ :file_limit => '-42' }} + let(:params) { { file_limit: '-42' } } + it 'does not compile' do - expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'/) + expect { catalogue }.to raise_error(Puppet::Error, %r{\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'}) end end context 'with file_limit => \'foo\'' do - let(:params) {{ :file_limit => 'foo' }} + let(:params) { { file_limit: 'foo' } } + it 'does not compile' do - expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'/) + expect { catalogue }.to raise_error(Puppet::Error, %r{\$file_limit must be a positive integer, '-1', 'unlimited', or 'infinity'}) end end end context 'on Redhat' do - let(:params) {{ :repos_ensure => false }} + let(:params) { { repos_ensure: false } } + with_redhat_facts it 'does not contain class rabbitmq::repo::rhel when repos_ensure is false' do is_expected.not_to contain_class('rabbitmq::repo::rhel') end - it 'should not contain "rabbitmq" repo' do + it 'does not contain "rabbitmq" repo' do is_expected.not_to contain_yumrepo('rabbitmq') end end context 'on Redhat' do - let(:params) {{ :repos_ensure => true }} + let(:params) { { repos_ensure: true } } + with_redhat_facts - it 'should contain class rabbitmq::repo::rhel' do + it 'contains class rabbitmq::repo::rhel' do is_expected.to contain_class('rabbitmq::repo::rhel') end - it 'should contain "rabbitmq" repo' do + it 'contains "rabbitmq" repo' do is_expected.to contain_yumrepo('rabbitmq') end it 'the repo should be present, and contain the expected values' do - is_expected.to contain_yumrepo('rabbitmq').with( { - :ensure => 'present', - :baseurl => 'https://packagecloud.io/rabbitmq/rabbitmq-server/el/$releasever/$basearch', - :gpgkey => 'https://www.rabbitmq.com/rabbitmq-release-signing-key.asc', - }) + is_expected.to contain_yumrepo('rabbitmq').with(ensure: 'present', + baseurl: 'https://packagecloud.io/rabbitmq/rabbitmq-server/el/$releasever/$basearch', + gpgkey: 'https://www.rabbitmq.com/rabbitmq-release-signing-key.asc') end end context 'on RedHat 7.0 or higher' do with_redhat_facts - it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d').with( - 'ensure' => 'directory', - 'owner' => '0', - 'group' => '0', - 'mode' => '0755', - 'selinux_ignore_defaults' => true - ) } - - it { is_expected.to contain_exec('rabbitmq-systemd-reload').with( - 'command' => '/usr/bin/systemctl daemon-reload', - 'notify' => 'Class[Rabbitmq::Service]', - 'refreshonly' => true - ) } + it { + is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d').with( + 'ensure' => 'directory', + 'owner' => '0', + 'group' => '0', + 'mode' => '0755', + 'selinux_ignore_defaults' => true + ) + } + + it { + is_expected.to contain_exec('rabbitmq-systemd-reload').with( + 'command' => '/usr/bin/systemctl daemon-reload', + 'notify' => 'Class[Rabbitmq::Service]', + 'refreshonly' => true + ) + } context 'with file_limit => \'unlimited\'' do - let(:params) {{ :file_limit => 'unlimited' }} - it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] -LimitNOFILE=unlimited -' - ) } + let(:params) { { file_limit: 'unlimited' } } + + it { + is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Exec[rabbitmq-systemd-reload]', + 'content' => '[Service] + LimitNOFILE=unlimited + ' + ) + } end context 'with file_limit => \'infinity\'' do - let(:params) {{ :file_limit => 'infinity' }} - it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] -LimitNOFILE=infinity -' - ) } + let(:params) { { file_limit: 'infinity' } } + + it { + is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Exec[rabbitmq-systemd-reload]', + 'content' => '[Service] + LimitNOFILE=infinity + ' + ) + } end context 'with file_limit => \'-1\'' do - let(:params) {{ :file_limit => '-1' }} - it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] -LimitNOFILE=-1 -' - ) } + let(:params) { { file_limit: '-1' } } + + it { + is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Exec[rabbitmq-systemd-reload]', + 'content' => '[Service] + LimitNOFILE=-1 + ' + ) + } end context 'with file_limit => \'1234\'' do - let(:params) {{ :file_limit => '1234' }} - it { is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644', - 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] -LimitNOFILE=1234 -' - ) } + let(:params) { { file_limit: '1234' } } + + it { + is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644', + 'notify' => 'Exec[rabbitmq-systemd-reload]', + 'content' => '[Service] + LimitNOFILE=1234 + ' + ) + } end end - ['Debian', 'RedHat', 'SUSE', 'Archlinux'].each do |distro| + %w[Debian RedHat SUSE Archlinux].each do |distro| osfacts = { - :osfamily => distro, - :staging_http_get => '', - :puppetversion => Puppet.version, + osfamily: distro, + staging_http_get: '', + puppetversion: Puppet.version } case distro when 'Debian' - osfacts.merge!({ - :lsbdistcodename => 'squeeze', - :lsbdistid => 'Debian' - }) + osfacts[:lsbdistcodename] = 'squeeze' + osfacts[:lsbdistid] = 'Debian' when 'RedHat' - osfacts.merge!({ - :operatingsystemmajrelease => '7', - }) + osfacts[:operatingsystemmajrelease] = '7' end context "on #{distro}" do @@ -277,8 +308,9 @@ it { is_expected.to contain_class('rabbitmq::config') } it { is_expected.to contain_class('rabbitmq::service') } - context 'with admin_enable set to true' do - let(:params) {{ :admin_enable => true, :management_ip_address => '1.1.1.1' }} + context 'with admin_enable set to true' do + let(:params) { { admin_enable: true, management_ip_address: '1.1.1.1' } } + context 'with service_manage set to true' do it 'we enable the admin interface by default' do is_expected.to contain_class('rabbitmq::install::rabbitmqadmin') @@ -286,61 +318,67 @@ 'require' => 'Class[Rabbitmq::Install]', 'notify' => 'Class[Rabbitmq::Service]' ) - is_expected.to contain_staging__file('rabbitmqadmin').with_source("http://1.1.1.1:15672/cli/rabbitmqadmin") + is_expected.to contain_staging__file('rabbitmqadmin').with_source('http://1.1.1.1:15672/cli/rabbitmqadmin') end end context 'with $management_ip_address undef and service_manage set to true' do - let(:params) {{ :admin_enable => true, :management_ip_address => :undef }} + let(:params) { { admin_enable: true, management_ip_address: :undef } } + it 'we enable the admin interface by default' do is_expected.to contain_class('rabbitmq::install::rabbitmqadmin') is_expected.to contain_rabbitmq_plugin('rabbitmq_management').with( 'require' => 'Class[Rabbitmq::Install]', 'notify' => 'Class[Rabbitmq::Service]' ) - is_expected.to contain_staging__file('rabbitmqadmin').with_source("http://127.0.0.1:15672/cli/rabbitmqadmin") + is_expected.to contain_staging__file('rabbitmqadmin').with_source('http://127.0.0.1:15672/cli/rabbitmqadmin') end end context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified' do - let(:params) {{ :admin_enable => true, :default_user => 'foobar', :default_pass => 'hunter2', :node_ip_address => :undef }} + let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', node_ip_address: :undef } } + it 'we use the correct URL to rabbitmqadmin' do is_expected.to contain_staging__file('rabbitmqadmin').with( - :source => 'http://127.0.0.1:15672/cli/rabbitmqadmin', - :curl_option => '-u "foobar:hunter2" -k --retry 30 --retry-delay 6', + source: 'http://127.0.0.1:15672/cli/rabbitmqadmin', + curl_option: '-u "foobar:hunter2" -k --retry 30 --retry-delay 6' ) end end context 'with service_manage set to true and default user/pass specified' do - let(:params) {{ :admin_enable => true, :default_user => 'foobar', :default_pass => 'hunter2', :management_ip_address => '1.1.1.1' }} + let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', management_ip_address: '1.1.1.1' } } + it 'we use the correct URL to rabbitmqadmin' do is_expected.to contain_staging__file('rabbitmqadmin').with( - :source => 'http://1.1.1.1:15672/cli/rabbitmqadmin', - :curl_option => '-u "foobar:hunter2" -k --noproxy 1.1.1.1 --retry 30 --retry-delay 6', + source: 'http://1.1.1.1:15672/cli/rabbitmqadmin', + curl_option: '-u "foobar:hunter2" -k --noproxy 1.1.1.1 --retry 30 --retry-delay 6' ) end end context 'with service_manage set to true and management port specified' do # note that the 2.x management port is 55672 not 15672 - let(:params) {{ :admin_enable => true, :management_port => 55672, :management_ip_address => '1.1.1.1' }} + let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '1.1.1.1' } } + it 'we use the correct URL to rabbitmqadmin' do is_expected.to contain_staging__file('rabbitmqadmin').with( - :source => 'http://1.1.1.1:55672/cli/rabbitmqadmin', - :curl_option => '-u "guest:guest" -k --noproxy 1.1.1.1 --retry 30 --retry-delay 6', + source: 'http://1.1.1.1:55672/cli/rabbitmqadmin', + curl_option: '-u "guest:guest" -k --noproxy 1.1.1.1 --retry 30 --retry-delay 6' ) end end context 'with ipv6, service_manage set to true and management port specified' do # note that the 2.x management port is 55672 not 15672 - let(:params) {{ :admin_enable => true, :management_port => 55672, :management_ip_address => '::1' }} + let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '::1' } } + it 'we use the correct URL to rabbitmqadmin' do is_expected.to contain_staging__file('rabbitmqadmin').with( - :source => 'http://[::1]:55672/cli/rabbitmqadmin', - :curl_option => '-u "guest:guest" -k --noproxy ::1 -g -6 --retry 30 --retry-delay 6', + source: 'http://[::1]:55672/cli/rabbitmqadmin', + curl_option: '-u "guest:guest" -k --noproxy ::1 -g -6 --retry 30 --retry-delay 6' ) end end context 'with service_manage set to false' do - let(:params) {{ :admin_enable => true, :service_manage => false }} - it 'should do nothing' do + let(:params) { { admin_enable: true, service_manage: false } } + + it 'does nothing' do is_expected.not_to contain_class('rabbitmq::install::rabbitmqadmin') is_expected.not_to contain_rabbitmq_plugin('rabbitmq_management') end @@ -348,107 +386,124 @@ end describe 'manages configuration directory correctly' do - it { is_expected.to contain_file('/etc/rabbitmq').with( - 'ensure' => 'directory', - 'mode' => '0755' - )} + it { + is_expected.to contain_file('/etc/rabbitmq').with( + 'ensure' => 'directory', + 'mode' => '0755' + ) + } end describe 'manages configuration file correctly' do - it { is_expected.to contain_file('rabbitmq.config').with( - 'owner' => '0', - 'group' => 'rabbitmq', - 'mode' => '0640' - )} + it { + is_expected.to contain_file('rabbitmq.config').with( + 'owner' => '0', + 'group' => 'rabbitmq', + 'mode' => '0640' + ) + } end context 'configures config_cluster' do - let(:params) {{ - :config_cluster => true, - :cluster_nodes => ['hare-1', 'hare-2'], - :cluster_node_type => 'ram', - :wipe_db_on_cookie_change => false - }} + let(:params) do + { + config_cluster: true, + cluster_nodes: ['hare-1', 'hare-2'], + cluster_node_type: 'ram', + wipe_db_on_cookie_change: false + } + end describe 'with erlang_cookie set' do - let(:params) {{ - :config_cluster => true, - :cluster_nodes => ['hare-1', 'hare-2'], - :cluster_node_type => 'ram', - :erlang_cookie => 'TESTCOOKIE', - :wipe_db_on_cookie_change => true - }} + let(:params) do + { + config_cluster: true, + cluster_nodes: ['hare-1', 'hare-2'], + cluster_node_type: 'ram', + erlang_cookie: 'TESTCOOKIE', + wipe_db_on_cookie_change: true + } + end + it 'contains the rabbitmq_erlang_cookie' do is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') end end describe 'with erlang_cookie set but without config_cluster' do - let(:params) {{ - :config_cluster => false, - :erlang_cookie => 'TESTCOOKIE', - }} + let(:params) do + { + config_cluster: false, + erlang_cookie: 'TESTCOOKIE' + } + end + it 'contains the rabbitmq_erlang_cookie' do is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') end end describe 'without erlang_cookie and without config_cluster' do - let(:params) {{ - :config_cluster => false, - }} + let(:params) do + { + config_cluster: false + } + end + it 'contains the rabbitmq_erlang_cookie' do is_expected.not_to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie') end end describe 'and sets appropriate configuration' do - let(:params) {{ - :config_cluster => true, - :cluster_nodes => ['hare-1', 'hare-2'], - :cluster_node_type => 'ram', - :erlang_cookie => 'ORIGINAL', - :wipe_db_on_cookie_change => true - }} - it 'for cluster_nodes' do - is_expected.to contain_file('rabbitmq.config').with({ - 'content' => /cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram/, - }) + let(:params) do + { + config_cluster: true, + cluster_nodes: ['hare-1', 'hare-2'], + cluster_node_type: 'ram', + erlang_cookie: 'ORIGINAL', + wipe_db_on_cookie_change: true + } end + it 'for cluster_nodes' do + is_expected.to contain_file('rabbitmq.config').with('content' => %r{cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram}) + end end end describe 'rabbitmq-env configuration' do - context 'with default params' do - it 'should set environment variables' do - is_expected.to contain_file('rabbitmq-env.config') \ - .with_content(%r{ERL_INETRC=/etc/rabbitmq/inetrc}) + it 'sets environment variables' do + is_expected.to contain_file('rabbitmq-env.config'). \ + with_content(%r{ERL_INETRC=/etc/rabbitmq/inetrc}) end end context 'with environment_variables set' do - let(:params) {{ :environment_variables => { - 'NODE_IP_ADDRESS' => '1.1.1.1', - 'NODE_PORT' => '5656', - 'NODENAME' => 'HOSTNAME', - 'SERVICENAME' => 'RabbitMQ', - 'CONSOLE_LOG' => 'RabbitMQ.debug', - 'CTL_ERL_ARGS' => 'verbose', - 'SERVER_ERL_ARGS' => 'v', - 'SERVER_START_ARGS' => 'debug' - }}} - it 'should set environment variables' do - is_expected.to contain_file('rabbitmq-env.config') \ - .with_content(/NODE_IP_ADDRESS=1.1.1.1/) \ - .with_content(/NODE_PORT=5656/) \ - .with_content(/NODENAME=HOSTNAME/) \ - .with_content(/SERVICENAME=RabbitMQ/) \ - .with_content(/CONSOLE_LOG=RabbitMQ.debug/) \ - .with_content(/CTL_ERL_ARGS=verbose/) \ - .with_content(/SERVER_ERL_ARGS=v/) \ - .with_content(/SERVER_START_ARGS=debug/) + let(:params) do + { environment_variables: { + 'NODE_IP_ADDRESS' => '1.1.1.1', + 'NODE_PORT' => '5656', + 'NODENAME' => 'HOSTNAME', + 'SERVICENAME' => 'RabbitMQ', + 'CONSOLE_LOG' => 'RabbitMQ.debug', + 'CTL_ERL_ARGS' => 'verbose', + 'SERVER_ERL_ARGS' => 'v', + 'SERVER_START_ARGS' => 'debug' + } } + end + + it 'sets environment variables' do + is_expected.to contain_file('rabbitmq-env.config'). \ + with_content(%r{NODE_IP_ADDRESS=1.1.1.1}). \ + with_content(%r{NODE_PORT=5656}). \ + with_content(%r{NODENAME=HOSTNAME}). \ + with_content(%r{SERVICENAME=RabbitMQ}). \ + with_content(%r{CONSOLE_LOG=RabbitMQ.debug}). \ + with_content(%r{CTL_ERL_ARGS=verbose}). \ + with_content(%r{SERVER_ERL_ARGS=v}). \ + with_content(%r{SERVER_START_ARGS=debug}) end end end @@ -459,7 +514,8 @@ end describe 'delete user when delete_guest_user set' do - let(:params) {{ :delete_guest_user => true }} + let(:params) { { delete_guest_user: true } } + it 'removes the user' do is_expected.to contain_rabbitmq_user('guest').with( 'ensure' => 'absent', @@ -471,102 +527,98 @@ context 'configuration setting' do describe 'node_ip_address when set' do - let(:params) {{ :node_ip_address => '172.0.0.1' }} - it 'should set NODE_IP_ADDRESS to specified value' do + let(:params) { { node_ip_address: '172.0.0.1' } } + + it 'sets NODE_IP_ADDRESS to specified value' do is_expected.to contain_file('rabbitmq-env.config'). with_content(%r{NODE_IP_ADDRESS=172\.0\.0\.1}) end end describe 'stomp by default' do - it 'should not specify stomp parameters in rabbitmq.config' do - is_expected.to contain_file('rabbitmq.config').without({ - 'content' => /stomp/,}) + it 'does not specify stomp parameters in rabbitmq.config' do + is_expected.to contain_file('rabbitmq.config').without('content' => %r{stomp}) end end describe 'stomp when set' do - let(:params) {{ :config_stomp => true, :stomp_port => 5679 }} - it 'should specify stomp port in rabbitmq.config' do - is_expected.to contain_file('rabbitmq.config').with({ - 'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\]/m, - }) + let(:params) { { config_stomp: true, stomp_port: 5679 } } + + it 'specifies stomp port in rabbitmq.config' do + is_expected.to contain_file('rabbitmq.config').with('content' => %r{rabbitmq_stomp.*tcp_listeners, \[5679\]}m) end end describe 'stomp when set ssl port w/o ssl enabled' do - let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => false, :ssl_stomp_port => 5680 }} - it 'should not configure ssl_listeners in rabbitmq.config' do - is_expected.to contain_file('rabbitmq.config').without({ - 'content' => /rabbitmq_stomp.*ssl_listeners, \[5680\]/m, - }) + let(:params) { { config_stomp: true, stomp_port: 5679, ssl: false, ssl_stomp_port: 5680 } } + + it 'does not configure ssl_listeners in rabbitmq.config' do + is_expected.to contain_file('rabbitmq.config').without('content' => %r{rabbitmq_stomp.*ssl_listeners, \[5680\]}m) end end describe 'stomp when set with ssl' do - let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => true, :ssl_stomp_port => 5680 }} - it 'should specify stomp port and ssl stomp port in rabbitmq.config' do - is_expected.to contain_file('rabbitmq.config').with({ - 'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]/m, - }) + let(:params) { { config_stomp: true, stomp_port: 5679, ssl: true, ssl_stomp_port: 5680 } } + + it 'specifies stomp port and ssl stomp port in rabbitmq.config' do + is_expected.to contain_file('rabbitmq.config').with('content' => %r{rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]}m) end end end describe 'configuring ldap authentication' do let :params do - { :config_stomp => true, - :ldap_auth => true, - :ldap_server => 'ldap.example.com', - :ldap_user_dn_pattern => 'ou=users,dc=example,dc=com', - :ldap_other_bind => 'as_user', - :ldap_use_ssl => false, - :ldap_port => 389, - :ldap_log => true, - :ldap_config_variables => { 'foo' => 'bar' } - } + { config_stomp: true, + ldap_auth: true, + ldap_server: 'ldap.example.com', + ldap_user_dn_pattern: 'ou=users,dc=example,dc=com', + ldap_other_bind: 'as_user', + ldap_use_ssl: false, + ldap_port: 389, + ldap_log: true, + ldap_config_variables: { 'foo' => 'bar' } } end it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') } - it 'should contain ldap parameters' do + it 'contains ldap parameters' do verify_contents(catalogue, 'rabbitmq.config', ['[', ' {rabbit, [', ' {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', ' ]}', - ' {rabbitmq_auth_backend_ldap, [', ' {other_bind, as_user},', - ' {servers, ["ldap.example.com"]},', - ' {user_dn_pattern, "ou=users,dc=example,dc=com"},', ' {use_ssl, false},', - ' {port, 389},', ' {foo, bar},', ' {log, true}']) + ' {rabbitmq_auth_backend_ldap, [', ' {other_bind, as_user},', + ' {servers, ["ldap.example.com"]},', + ' {user_dn_pattern, "ou=users,dc=example,dc=com"},', ' {use_ssl, false},', + ' {port, 389},', ' {foo, bar},', ' {log, true}']) end end describe 'configuring ldap authentication' do let :params do - { :config_stomp => false, - :ldap_auth => true, - :ldap_server => 'ldap.example.com', - :ldap_user_dn_pattern => 'ou=users,dc=example,dc=com', - :ldap_other_bind => 'as_user', - :ldap_use_ssl => false, - :ldap_port => 389, - :ldap_log => true, - :ldap_config_variables => { 'foo' => 'bar' } - } + { config_stomp: false, + ldap_auth: true, + ldap_server: 'ldap.example.com', + ldap_user_dn_pattern: 'ou=users,dc=example,dc=com', + ldap_other_bind: 'as_user', + ldap_use_ssl: false, + ldap_port: 389, + ldap_log: true, + ldap_config_variables: { 'foo' => 'bar' } } end it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') } - it 'should contain ldap parameters' do + it 'contains ldap parameters' do verify_contents(catalogue, 'rabbitmq.config', ['[', ' {rabbit, [', ' {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', ' ]}', - ' {rabbitmq_auth_backend_ldap, [', ' {other_bind, as_user},', - ' {servers, ["ldap.example.com"]},', - ' {user_dn_pattern, "ou=users,dc=example,dc=com"},', ' {use_ssl, false},', - ' {port, 389},', ' {foo, bar},', ' {log, true}']) + ' {rabbitmq_auth_backend_ldap, [', ' {other_bind, as_user},', + ' {servers, ["ldap.example.com"]},', + ' {user_dn_pattern, "ou=users,dc=example,dc=com"},', ' {use_ssl, false},', + ' {port, 389},', ' {foo, bar},', ' {log, true}']) end end describe 'configuring auth_backends' do let :params do - { :auth_backends => ['{baz, foo}', 'bar'] } + { auth_backends: ['{baz, foo}', 'bar'] } end - it 'should contain auth_backends' do + + it 'contains auth_backends' do verify_contents(catalogue, 'rabbitmq.config', [' {auth_backends, [{baz, foo}, bar]},']) end @@ -574,10 +626,11 @@ describe 'auth_backends overrides ldap_auth' do let :params do - { :auth_backends => ['{baz, foo}', 'bar'], - :ldap_auth => true, } + { auth_backends: ['{baz, foo}', 'bar'], + ldap_auth: true } end - it 'should contain auth_backends' do + + it 'contains auth_backends' do verify_contents(catalogue, 'rabbitmq.config', [' {auth_backends, [{baz, foo}, bar]},']) end @@ -586,7 +639,7 @@ describe 'configuring shovel plugin' do let :params do { - :config_shovel => true + config_shovel: true } end @@ -597,8 +650,8 @@ describe 'with admin_enable false' do let :params do { - :config_shovel => true, - :admin_enable => false + config_shovel: true, + admin_enable: false } end @@ -608,29 +661,30 @@ describe 'with static shovels' do let :params do { - :config_shovel => true, - :config_shovel_statics => { - 'shovel_first' => %q({sources,[{broker,"amqp://"}]}, + config_shovel: true, + config_shovel_statics: { + 'shovel_first' => '{sources,[{broker,"amqp://"}]}, {destinations,[{broker,"amqp://site1.example.com"}]}, - {queue,<<"source_one">>}), - 'shovel_second' => %q({sources,[{broker,"amqp://"}]}, + {queue,<<"source_one">>}', + 'shovel_second' => '{sources,[{broker,"amqp://"}]}, {destinations,[{broker,"amqp://site2.example.com"}]}, - {queue,<<"source_two">>}) + {queue,<<"source_two">>}' } } end - it "should generate correct configuration" do + it 'generates correct configuration' do verify_contents(catalogue, 'rabbitmq.config', [ -' {rabbitmq_shovel,', -' [{shovels,[', -' {shovel_first,[{sources,[{broker,"amqp://"}]},', -' {destinations,[{broker,"amqp://site1.example.com"}]},', -' {queue,<<"source_one">>}]},', -' {shovel_second,[{sources,[{broker,"amqp://"}]},', -' {destinations,[{broker,"amqp://site2.example.com"}]},', -' {queue,<<"source_two">>}]}', -' ]}]}' ]) + ' {rabbitmq_shovel,', + ' [{shovels,[', + ' {shovel_first,[{sources,[{broker,"amqp://"}]},', + ' {destinations,[{broker,"amqp://site1.example.com"}]},', + ' {queue,<<"source_one">>}]},', + ' {shovel_second,[{sources,[{broker,"amqp://"}]},', + ' {destinations,[{broker,"amqp://site2.example.com"}]},', + ' {queue,<<"source_two">>}]}', + ' ]}]}' + ]) end end end @@ -638,7 +692,7 @@ describe 'configuring shovel plugin' do let :params do { - :config_shovel => true + config_shovel: true } end @@ -649,8 +703,8 @@ describe 'with admin_enable false' do let :params do { - :config_shovel => true, - :admin_enable => false + config_shovel: true, + admin_enable: false } end @@ -660,64 +714,64 @@ describe 'with static shovels' do let :params do { - :config_shovel => true, - :config_shovel_statics => { - 'shovel_first' => %q({sources,[{broker,"amqp://"}]}, + config_shovel: true, + config_shovel_statics: { + 'shovel_first' => '{sources,[{broker,"amqp://"}]}, {destinations,[{broker,"amqp://site1.example.com"}]}, - {queue,<<"source_one">>}), - 'shovel_second' => %q({sources,[{broker,"amqp://"}]}, + {queue,<<"source_one">>}', + 'shovel_second' => '{sources,[{broker,"amqp://"}]}, {destinations,[{broker,"amqp://site2.example.com"}]}, - {queue,<<"source_two">>}) + {queue,<<"source_two">>}' } } end - it "should generate correct configuration" do + it 'generates correct configuration' do verify_contents(catalogue, 'rabbitmq.config', [ -' {rabbitmq_shovel,', -' [{shovels,[', -' {shovel_first,[{sources,[{broker,"amqp://"}]},', -' {destinations,[{broker,"amqp://site1.example.com"}]},', -' {queue,<<"source_one">>}]},', -' {shovel_second,[{sources,[{broker,"amqp://"}]},', -' {destinations,[{broker,"amqp://site2.example.com"}]},', -' {queue,<<"source_two">>}]}', -' ]}]}' ]) + ' {rabbitmq_shovel,', + ' [{shovels,[', + ' {shovel_first,[{sources,[{broker,"amqp://"}]},', + ' {destinations,[{broker,"amqp://site1.example.com"}]},', + ' {queue,<<"source_one">>}]},', + ' {shovel_second,[{sources,[{broker,"amqp://"}]},', + ' {destinations,[{broker,"amqp://site2.example.com"}]},', + ' {queue,<<"source_two">>}]}', + ' ]}]}' + ]) end end end describe 'default_user and default_pass set' do - let(:params) {{ :default_user => 'foo', :default_pass => 'bar' }} - it 'should set default_user and default_pass to specified values' do - is_expected.to contain_file('rabbitmq.config').with({ - 'content' => /default_user, <<"foo">>.*default_pass, <<"bar">>/m, - }) + let(:params) { { default_user: 'foo', default_pass: 'bar' } } + + it 'sets default_user and default_pass to specified values' do + is_expected.to contain_file('rabbitmq.config').with('content' => %r{default_user, <<"foo">>.*default_pass, <<"bar">>}m) end end describe 'interfaces option with no ssl' do - let(:params) { - { :interface => '0.0.0.0', - } } + let(:params) do + { interface: '0.0.0.0' } + end - it 'should set ssl options to specified values' do + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\{"0.0.0.0", 5672\}\]}) end end describe 'ssl options and mangament_ssl false' do - let(:params) { - { :ssl => true, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :management_ssl => false, - :management_port => 13142 - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + management_ssl: false, + management_port: 13_142 } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_listeners, \[3141\]} ) @@ -734,7 +788,7 @@ %r{keyfile,"/path/to/key"} ) end - it 'should set non ssl port for management port' do + it 'sets non ssl port for management port' do is_expected.to contain_file('rabbitmq.config').with_content( %r{port, 13142} ) @@ -745,17 +799,17 @@ end describe 'ssl options and mangament_ssl true' do - let(:params) { - { :ssl => true, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :management_ssl => true, - :ssl_management_port => 13141 - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + management_ssl: true, + ssl_management_port: 13_141 } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_listeners, \[3141\]} ) @@ -775,12 +829,12 @@ %r{keyfile,"/path/to/key"} ) end - it 'should set ssl managment port to specified values' do + it 'sets ssl managment port to specified values' do is_expected.to contain_file('rabbitmq.config').with_content( %r{port, 13141} ) end - it 'should set ssl options in the rabbitmqadmin.conf' do + it 'sets ssl options in the rabbitmqadmin.conf' do is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{ssl_ca_cert_file\s=\s/path/to/cacert} ) @@ -800,15 +854,15 @@ end describe 'ssl options' do - let(:params) { - { :ssl => true, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key' - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key' } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content( %r{ssl_listeners, \[3141\]} ) @@ -827,18 +881,17 @@ end end - describe 'ssl options with ssl_interfaces' do - let(:params) { - { :ssl => true, - :ssl_port => 3141, - :ssl_interface => '0.0.0.0', - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key' - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_port: 3141, + ssl_interface: '0.0.0.0', + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key' } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]}) is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) @@ -846,19 +899,17 @@ end end - - describe 'ssl options with ssl_only' do - let(:params) { - { :ssl => true, - :ssl_only => true, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key' - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_only: true, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key' } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]}) is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]}) is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_options, \[}) @@ -866,25 +917,25 @@ is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) end - it 'should not set TCP listener environment defaults' do - is_expected.to contain_file('rabbitmq-env.config') \ - .without_content(%r{NODE_PORT=}) \ - .without_content(%r{NODE_IP_ADDRESS=}) + it 'does not set TCP listener environment defaults' do + is_expected.to contain_file('rabbitmq-env.config'). \ + without_content(%r{NODE_PORT=}). \ + without_content(%r{NODE_IP_ADDRESS=}) end end describe 'ssl options with ssl_only and ssl_interfaces' do - let(:params) { - { :ssl => true, - :ssl_only => true, - :ssl_port => 3141, - :ssl_interface => '0.0.0.0', - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key' - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_only: true, + ssl_port: 3141, + ssl_interface: '0.0.0.0', + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key' } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]}) is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]}) is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) @@ -894,16 +945,16 @@ end describe 'ssl options with specific ssl versions' do - let(:params) { - { :ssl => true, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :ssl_versions => ['tlsv1.2', 'tlsv1.1'] - } } - - it 'should set ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + ssl_versions: ['tlsv1.2', 'tlsv1.1'] } + end + + it 'sets ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]}) is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_options, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"}) @@ -915,47 +966,47 @@ end describe 'ssl options with ssl_versions and not ssl' do - let(:params) { - { :ssl => false, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :ssl_versions => ['tlsv1.2', 'tlsv1.1'] - } } + let(:params) do + { ssl: false, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + ssl_versions: ['tlsv1.2', 'tlsv1.1'] } + end it 'fails' do - expect { catalogue }.to raise_error(Puppet::Error, /\$ssl_versions requires that \$ssl => true/) + expect { catalogue }.to raise_error(Puppet::Error, %r{\$ssl_versions requires that \$ssl => true}) end end describe 'ssl options with ssl ciphers' do - let(:params) { - { :ssl => true, - :ssl_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :ssl_ciphers => ['ecdhe_rsa,aes_256_cbc,sha', 'dhe_rsa,aes_256_cbc,sha'] - } } - - it 'should set ssl ciphers to specified values' do + let(:params) do + { ssl: true, + ssl_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + ssl_ciphers: ['ecdhe_rsa,aes_256_cbc,sha', 'dhe_rsa,aes_256_cbc,sha'] } + end + + it 'sets ssl ciphers to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{ciphers,\[[[:space:]]+{dhe_rsa,aes_256_cbc,sha},[[:space:]]+{ecdhe_rsa,aes_256_cbc,sha}[[:space:]]+\]}) end end describe 'ssl admin options with specific ssl versions' do - let(:params) { - { :ssl => true, - :ssl_management_port => 5926, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :ssl_versions => ['tlsv1.2', 'tlsv1.1'], - :admin_enable => true - } } - - it 'should set admin ssl opts to specified values' do + let(:params) do + { ssl: true, + ssl_management_port: 5926, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + ssl_versions: ['tlsv1.2', 'tlsv1.1'], + admin_enable: true } + end + + it 'sets admin ssl opts to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 5926\}}) @@ -969,16 +1020,16 @@ end describe 'ssl admin options' do - let(:params) { - { :ssl => true, - :ssl_management_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :admin_enable => true - } } - - it 'should set rabbitmq_management ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_management_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + admin_enable: true } + end + + it 'sets rabbitmq_management ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\}}) @@ -991,13 +1042,13 @@ end describe 'admin without ssl' do - let(:params) { - { :ssl => false, - :management_port => 3141, - :admin_enable => true - } } + let(:params) do + { ssl: false, + management_port: 3141, + admin_enable: true } + end - it 'should set rabbitmq_management options to specified values' do + it 'sets rabbitmq_management options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\}}) @@ -1005,16 +1056,16 @@ end describe 'ssl admin options' do - let(:params) { - { :ssl => true, - :ssl_management_port => 3141, - :ssl_cacert => '/path/to/cacert', - :ssl_cert => '/path/to/cert', - :ssl_key => '/path/to/key', - :admin_enable => true - } } - - it 'should set rabbitmq_management ssl options to specified values' do + let(:params) do + { ssl: true, + ssl_management_port: 3141, + ssl_cacert: '/path/to/cacert', + ssl_cert: '/path/to/cert', + ssl_key: '/path/to/key', + admin_enable: true } + end + + it 'sets rabbitmq_management ssl options to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\},}) @@ -1027,179 +1078,189 @@ end describe 'admin without ssl' do - let(:params) { - { :ssl => false, - :management_port => 3141, - :admin_enable => true - } } - - it 'should set rabbitmq_management options to specified values' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{rabbitmq_management, \[/) \ - .with_content(/\{listener, \[/) \ - .with_content(/\{port, 3141\}/) + let(:params) do + { ssl: false, + management_port: 3141, + admin_enable: true } + end + + it 'sets rabbitmq_management options to specified values' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{rabbitmq_management, \[}). \ + with_content(%r{\{listener, \[}). \ + with_content(%r{\{port, 3141\}}) end end describe 'ipv6 enabled' do - let(:params) { { :ipv6 => true } } + let(:params) { { ipv6: true } } - it 'should enable resolver inet6 in inetrc' do + it 'enables resolver inet6 in inetrc' do is_expected.to contain_file('rabbitmq-inetrc').with_content(%r{{inet6, true}.}) end context 'without other erl args' do - it 'should enable inet6 distribution' do - is_expected.to contain_file('rabbitmq-env.config') \ - .with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="-proto_dist inet6_tcp"$}) \ - .with_content(%r{^RABBITMQ_CTL_ERL_ARGS="-proto_dist inet6_tcp"$}) + it 'enables inet6 distribution' do + is_expected.to contain_file('rabbitmq-env.config'). \ + with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="-proto_dist inet6_tcp"$}). \ + with_content(%r{^RABBITMQ_CTL_ERL_ARGS="-proto_dist inet6_tcp"$}) end end context 'with other quoted erl args' do - let(:params) { - { :ipv6 => true, - :environment_variables => { 'RABBITMQ_SERVER_ERL_ARGS' => '"some quoted args"', - 'RABBITMQ_CTL_ERL_ARGS' => '"other quoted args"'} } - } + let(:params) do + { ipv6: true, + environment_variables: { 'RABBITMQ_SERVER_ERL_ARGS' => '"some quoted args"', + 'RABBITMQ_CTL_ERL_ARGS' => '"other quoted args"' } } + end - it 'should enable inet6 distribution and quote properly' do - is_expected.to contain_file('rabbitmq-env.config') \ - .with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="some quoted args -proto_dist inet6_tcp"$}) \ - .with_content(%r{^RABBITMQ_CTL_ERL_ARGS="other quoted args -proto_dist inet6_tcp"$}) + it 'enables inet6 distribution and quote properly' do + is_expected.to contain_file('rabbitmq-env.config'). \ + with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="some quoted args -proto_dist inet6_tcp"$}). \ + with_content(%r{^RABBITMQ_CTL_ERL_ARGS="other quoted args -proto_dist inet6_tcp"$}) end end context 'with other unquoted erl args' do - let(:params) { - { :ipv6 => true, - :environment_variables => { 'RABBITMQ_SERVER_ERL_ARGS' => 'foo', - 'RABBITMQ_CTL_ERL_ARGS' => 'bar'} } - } - - it 'should enable inet6 distribution and quote properly' do - is_expected.to contain_file('rabbitmq-env.config') \ - .with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="foo -proto_dist inet6_tcp"$}) \ - .with_content(%r{^RABBITMQ_CTL_ERL_ARGS="bar -proto_dist inet6_tcp"$}) + let(:params) do + { ipv6: true, + environment_variables: { 'RABBITMQ_SERVER_ERL_ARGS' => 'foo', + 'RABBITMQ_CTL_ERL_ARGS' => 'bar' } } end + it 'enables inet6 distribution and quote properly' do + is_expected.to contain_file('rabbitmq-env.config'). \ + with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="foo -proto_dist inet6_tcp"$}). \ + with_content(%r{^RABBITMQ_CTL_ERL_ARGS="bar -proto_dist inet6_tcp"$}) + end end end describe 'config_variables options' do - let(:params) {{ :config_variables => { - 'hipe_compile' => true, + let(:params) do + { config_variables: { + 'hipe_compile' => true, 'vm_memory_high_watermark' => 0.4, - 'frame_max' => 131072, - 'collect_statistics' => "none", - 'auth_mechanisms' => "['PLAIN', 'AMQPLAIN']", - }}} - it 'should set environment variables' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{hipe_compile, true\}/) \ - .with_content(/\{vm_memory_high_watermark, 0.4\}/) \ - .with_content(/\{frame_max, 131072\}/) \ - .with_content(/\{collect_statistics, none\}/) \ - .with_content(/\{auth_mechanisms, \['PLAIN', 'AMQPLAIN'\]\}/) + 'frame_max' => 131_072, + 'collect_statistics' => 'none', + 'auth_mechanisms' => "['PLAIN', 'AMQPLAIN']" + } } + end + + it 'sets environment variables' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{hipe_compile, true\}}). \ + with_content(%r{\{vm_memory_high_watermark, 0.4\}}). \ + with_content(%r{\{frame_max, 131072\}}). \ + with_content(%r{\{collect_statistics, none\}}). \ + with_content(%r{\{auth_mechanisms, \['PLAIN', 'AMQPLAIN'\]\}}) end end describe 'config_kernel_variables options' do - let(:params) {{ :config_kernel_variables => { - 'inet_dist_listen_min' => 9100, - 'inet_dist_listen_max' => 9105, - }}} - it 'should set config variables' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{inet_dist_listen_min, 9100\}/) \ - .with_content(/\{inet_dist_listen_max, 9105\}/) + let(:params) do + { config_kernel_variables: { + 'inet_dist_listen_min' => 9100, + 'inet_dist_listen_max' => 9105 + } } + end + + it 'sets config variables' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{inet_dist_listen_min, 9100\}}). \ + with_content(%r{\{inet_dist_listen_max, 9105\}}) end end describe 'config_management_variables' do - let(:params) {{ :config_management_variables => { - 'rates_mode' => 'none', - }}} - it 'should set config variables' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{rates_mode, none\}/) + let(:params) do + { config_management_variables: { + 'rates_mode' => 'none' + } } + end + + it 'sets config variables' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{rates_mode, none\}}) end end describe 'tcp_keepalive enabled' do - let(:params) {{ :tcp_keepalive => true }} - it 'should set tcp_listen_options keepalive true' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{keepalive, true\}/) + let(:params) { { tcp_keepalive: true } } + + it 'sets tcp_listen_options keepalive true' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{keepalive, true\}}) end end describe 'tcp_keepalive disabled (default)' do - it 'should not set tcp_listen_options' do - is_expected.to contain_file('rabbitmq.config') \ - .without_content(/\{keepalive, true\}/) + it 'does not set tcp_listen_options' do + is_expected.to contain_file('rabbitmq.config'). \ + without_content(%r{\{keepalive, true\}}) end end describe 'tcp_backlog with default value' do - it 'should set tcp_listen_options backlog to 128' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{backlog, 128\}/) + it 'sets tcp_listen_options backlog to 128' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{backlog, 128\}}) end end describe 'tcp_backlog with non-default value' do let(:params) do - { :tcp_backlog => 256 } + { tcp_backlog: 256 } end - it 'should set tcp_listen_options backlog to 256' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{backlog, 256\}/) + it 'sets tcp_listen_options backlog to 256' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{backlog, 256\}}) end end describe 'tcp_sndbuf with default value' do - it 'should not set tcp_listen_options sndbuf' do - is_expected.to contain_file('rabbitmq.config') \ - .without_content(/sndbuf/) + it 'does not set tcp_listen_options sndbuf' do + is_expected.to contain_file('rabbitmq.config'). \ + without_content(%r{sndbuf}) end end describe 'tcp_sndbuf with non-default value' do let(:params) do - { :tcp_sndbuf => 128 } + { tcp_sndbuf: 128 } end - it 'should set tcp_listen_options sndbuf to 128' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{sndbuf, 128\}/) + it 'sets tcp_listen_options sndbuf to 128' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{sndbuf, 128\}}) end end describe 'tcp_recbuf with default value' do - it 'should not set tcp_listen_options recbuf' do - is_expected.to contain_file('rabbitmq.config') \ - .without_content(/recbuf/) + it 'does not set tcp_listen_options recbuf' do + is_expected.to contain_file('rabbitmq.config'). \ + without_content(%r{recbuf}) end end describe 'tcp_recbuf with non-default value' do let(:params) do - { :tcp_recbuf => 128 } + { tcp_recbuf: 128 } end - it 'should set tcp_listen_options recbuf to 128' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{recbuf, 128\}/) + it 'sets tcp_listen_options recbuf to 128' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{recbuf, 128\}}) end end describe 'rabbitmq-heartbeat options' do - let(:params) {{ :heartbeat => 60 }} - it 'should set heartbeat paramter in config file' do - is_expected.to contain_file('rabbitmq.config') \ - .with_content(/\{heartbeat, 60\}/) + let(:params) { { heartbeat: 60 } } + + it 'sets heartbeat paramter in config file' do + is_expected.to contain_file('rabbitmq.config'). \ + with_content(%r{\{heartbeat, 60\}}) end end @@ -1209,7 +1270,8 @@ end describe 'delete user when delete_guest_user set' do - let(:params) {{ :delete_guest_user => true }} + let(:params) { { delete_guest_user: true } } + it 'removes the user' do is_expected.to contain_rabbitmq_user('guest').with( 'ensure' => 'absent', @@ -1223,86 +1285,91 @@ ## rabbitmq::service ## describe 'service with default params' do - it { is_expected.to contain_service('rabbitmq-server').with( - 'ensure' => 'running', - 'enable' => 'true', - 'hasstatus' => 'true', - 'hasrestart' => 'true' - )} + it { + is_expected.to contain_service('rabbitmq-server').with( + 'ensure' => 'running', + 'enable' => 'true', + 'hasstatus' => 'true', + 'hasrestart' => 'true' + ) + } end describe 'service with ensure stopped' do let :params do - { :service_ensure => 'stopped' } + { service_ensure: 'stopped' } end - it { is_expected.to contain_service('rabbitmq-server').with( - 'ensure' => 'stopped', - 'enable' => false - ) } + it { + is_expected.to contain_service('rabbitmq-server').with( + 'ensure' => 'stopped', + 'enable' => false + ) + } end describe 'service with service_manage equal to false' do let :params do - { :service_manage => false } + { service_manage: false } end it { is_expected.not_to contain_service('rabbitmq-server') } end - end end ## ## rabbitmq::install ## - context "on RHEL with repos_ensure" do + context 'on RHEL with repos_ensure' do with_redhat_facts - let(:params) {{ :repos_ensure => true }} + let(:params) { { repos_ensure: true } } + it 'installs the rabbitmq package' do is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', - 'name' => 'rabbitmq-server', + 'name' => 'rabbitmq-server' ) end end - context "on RHEL" do + context 'on RHEL' do with_redhat_facts - let(:params) {{ :repos_ensure => false}} + let(:params) { { repos_ensure: false } } + it 'installs the rabbitmq package [from EPEL] when $repos_ensure is false' do is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', - 'name' => 'rabbitmq-server', + 'name' => 'rabbitmq-server' ) end end - context "on Debian" do + context 'on Debian' do with_debian_facts it 'installs the rabbitmq package' do is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', - 'name' => 'rabbitmq-server', + 'name' => 'rabbitmq-server' ) end end - context "on Archlinux" do + context 'on Archlinux' do with_archlinux_facts it 'installs the rabbitmq package' do is_expected.to contain_package('rabbitmq-server').with( - 'ensure' => 'installed', + 'ensure' => 'installed' ) end end - context "on OpenBSD" do + context 'on OpenBSD' do with_openbsd_facts it 'installs the rabbitmq package' do is_expected.to contain_package('rabbitmq-server').with( 'ensure' => 'installed', - 'name' => 'rabbitmq', + 'name' => 'rabbitmq' ) end end @@ -1311,37 +1378,41 @@ with_debian_facts context 'with no pin' do - let(:params) {{:repos_ensure => true, :package_apt_pin => '' }} - describe 'it sets up an apt::source' do + let(:params) { { repos_ensure: true, package_apt_pin: '' } } - it { is_expected.to contain_apt__source('rabbitmq').with( - 'location' => 'http://www.rabbitmq.com/debian/', - 'release' => 'testing', - 'repos' => 'main', - 'key' => '{"id"=>"0A9AF2115F4687BD29803A206B73A36E6026DFCA", "source"=>"https://www.rabbitmq.com/rabbitmq-release-signing-key.asc", "content"=>:undef}' - ) } + describe 'it sets up an apt::source' do + it { + is_expected.to contain_apt__source('rabbitmq').with( + 'location' => 'http://www.rabbitmq.com/debian/', + 'release' => 'testing', + 'repos' => 'main', + 'key' => '{"id"=>"0A9AF2115F4687BD29803A206B73A36E6026DFCA", "source"=>"https://www.rabbitmq.com/rabbitmq-release-signing-key.asc", "content"=>:undef}' + ) + } end end context 'with pin' do - let(:params) {{:repos_ensure => true, :package_apt_pin => '700' }} - describe 'it sets up an apt::source and pin' do - - it { is_expected.to contain_apt__source('rabbitmq').with( - 'location' => 'http://www.rabbitmq.com/debian/', - 'release' => 'testing', - 'repos' => 'main', - 'key' => '{"id"=>"0A9AF2115F4687BD29803A206B73A36E6026DFCA", "source"=>"https://www.rabbitmq.com/rabbitmq-release-signing-key.asc", "content"=>:undef}' - ) } + let(:params) { { repos_ensure: true, package_apt_pin: '700' } } - it { is_expected.to contain_apt__pin('rabbitmq').with( - 'packages' => '*', - 'priority' => '700', - 'origin' => 'www.rabbitmq.com' - ) } + describe 'it sets up an apt::source and pin' do + it { + is_expected.to contain_apt__source('rabbitmq').with( + 'location' => 'http://www.rabbitmq.com/debian/', + 'release' => 'testing', + 'repos' => 'main', + 'key' => '{"id"=>"0A9AF2115F4687BD29803A206B73A36E6026DFCA", "source"=>"https://www.rabbitmq.com/rabbitmq-release-signing-key.asc", "content"=>:undef}' + ) + } + it { + is_expected.to contain_apt__pin('rabbitmq').with( + 'packages' => '*', + 'priority' => '700', + 'origin' => 'www.rabbitmq.com' + ) + } end end end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22d5d689f..1b8480d41 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -#This file is generated by ModuleSync, do not edit. +# This file is generated by ModuleSync, do not edit. require 'puppetlabs_spec_helper/module_spec_helper' # put local configuration and setup into spec_helper_local diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 880c61040..c259a42fc 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -3,7 +3,7 @@ run_puppet_install_helper -UNSUPPORTED_PLATFORMS = [] +UNSUPPORTED_PLATFORMS = [].freeze RSpec.configure do |c| # Project root @@ -12,26 +12,25 @@ # Readable test descriptions c.formatter = :documentation c.before :suite do - puppet_module_install(:source => proj_root, :module_name => 'rabbitmq') + puppet_module_install(source: proj_root, module_name: 'rabbitmq') hosts.each do |host| if fact('osfamily') == 'RedHat' && fact('selinux') == 'true' # Make sure selinux is disabled so the tests work. on host, puppet('apply', '-e', - %{"exec { 'setenforce 0': path => '/bin:/sbin:/usr/bin:/usr/sbin', onlyif => 'which setenforce && getenforce | grep Enforcing', }"}) + %("exec { 'setenforce 0': path => '/bin:/sbin:/usr/bin:/usr/sbin', onlyif => 'which setenforce && getenforce | grep Enforcing', }")) end - on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } - on host, puppet('module', 'install', 'puppet-staging'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] + on host, puppet('module', 'install', 'puppet-staging'), acceptable_exit_codes: [0, 1] if fact('osfamily') == 'Debian' - on host, puppet('module', 'install', 'puppetlabs-apt'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-apt'), acceptable_exit_codes: [0, 1] end if fact('osfamily') == 'RedHat' - on host, puppet('module', 'install', 'garethr-erlang'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'garethr-erlang'), acceptable_exit_codes: [0, 1] end end end end - diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 338ae800b..90061b7c5 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,25 +1,25 @@ -RSpec.shared_context "default facts" do - let(:facts) { { :puppetversion => Puppet.version, - :staging_http_get => '', - :rabbitmq_version => '3.6.1' } } +RSpec.shared_context 'default facts' do + let(:facts) do + { puppetversion: Puppet.version, + staging_http_get: '', + rabbitmq_version: '3.6.1' } + end end RSpec.configure do |rspec| - rspec.include_context "default facts" + rspec.include_context 'default facts' end def with_debian_facts let :facts do - super().merge({ - :operatingsystemmajrelease => '6', - :lsbdistcodename => 'squeeze', - :lsbdistid => 'Debian', - :osfamily => 'Debian', - :os => { - :name => 'Debian', - :release => { :full => '6.0'}, - }, - }) + super().merge(operatingsystemmajrelease: '6', + lsbdistcodename: 'squeeze', + lsbdistid: 'Debian', + osfamily: 'Debian', + os: { + name: 'Debian', + release: { full: '6.0' } + }) end end @@ -28,31 +28,27 @@ def with_openbsd_facts # operatingsystemrelease may contain X.X-current # or other prefixes let :facts do - super().merge({ - :kernelversion => '5.9', - :osfamily => 'OpenBSD', - }) + super().merge(kernelversion: '5.9', + osfamily: 'OpenBSD') end end def with_redhat_facts let :facts do - super().merge({ - :operatingsystemmajrelease => '7', - :osfamily => 'Redhat', - }) + super().merge(operatingsystemmajrelease: '7', + osfamily: 'Redhat') end end def with_suse_facts let :facts do - super().merge({ :osfamily => 'SUSE' }) + super().merge(osfamily: 'SUSE') end end def with_archlinux_facts let :facts do - super().merge({ :osfamily => 'Archlinux' }) + super().merge(osfamily: 'Archlinux') end end diff --git a/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb index d3dac2309..a924b262f 100644 --- a/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb @@ -5,20 +5,18 @@ end provider_class = Puppet::Type.type(:rabbitmq_binding).provider(:rabbitmqadmin) describe provider_class do - before :each do + before do @resource = Puppet::Type::Rabbitmq_binding.new( - { - :name => 'source@target@/', - :destination_type => :queue, - :routing_key => 'blablub', - :arguments => {} - } + name: 'source@target@/', + destination_type: :queue, + routing_key: 'blablub', + arguments: {} ) @provider = provider_class.new(@resource) end - describe "#instances" do - it 'should return instances' do + describe '#instances' do + it 'returns instances' do provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT / EOT @@ -29,22 +27,22 @@ expect(instances.size).to eq(1) expect(instances.map do |prov| { - :source => prov.get(:source), - :destination => prov.get(:destination), - :vhost => prov.get(:vhost), - :routing_key => prov.get(:routing_key) + source: prov.get(:source), + destination: prov.get(:destination), + vhost: prov.get(:vhost), + routing_key: prov.get(:routing_key) } end).to eq([ - { - :source => 'exchange', - :destination => 'dst_queue', - :vhost => '/', - :routing_key => '*' - } - ]) + { + source: 'exchange', + destination: 'dst_queue', + vhost: '/', + routing_key: '*' + } + ]) end - it 'should return multiple instances' do + it 'returns multiple instances' do provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT / EOT @@ -56,30 +54,30 @@ expect(instances.size).to eq(2) expect(instances.map do |prov| { - :source => prov.get(:source), - :destination => prov.get(:destination), - :vhost => prov.get(:vhost), - :routing_key => prov.get(:routing_key) + source: prov.get(:source), + destination: prov.get(:destination), + vhost: prov.get(:vhost), + routing_key: prov.get(:routing_key) } end).to eq([ - { - :source => 'exchange', - :destination => 'dst_queue', - :vhost => '/', - :routing_key => 'routing_one' - }, - { - :source => 'exchange', - :destination => 'dst_queue', - :vhost => '/', - :routing_key => 'routing_two' - } - ]) + { + source: 'exchange', + destination: 'dst_queue', + vhost: '/', + routing_key: 'routing_one' + }, + { + source: 'exchange', + destination: 'dst_queue', + vhost: '/', + routing_key: 'routing_two' + } + ]) end end - describe "Test for prefetch error" do - it "exists" do + describe 'Test for prefetch error' do + it 'exists' do provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT / EOT @@ -90,17 +88,15 @@ provider_class.prefetch({}) end - it "matches" do + it 'matches' do # Test resource to match against @resource = Puppet::Type::Rabbitmq_binding.new( - { - :name => 'binding1', - :source => 'exchange1', - :destination => 'destqueue', - :destination_type => :queue, - :routing_key => 'blablubd', - :arguments => {} - } + name: 'binding1', + source: 'exchange1', + destination: 'destqueue', + destination_type: :queue, + routing_key: 'blablubd', + arguments: {} ) provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT @@ -110,60 +106,55 @@ exchange\tdst_queue\tqueue\t*\t[] EOT - provider_class.prefetch({ "binding1" => @resource}) + provider_class.prefetch('binding1' => @resource) end end - - it 'should call rabbitmqadmin to create' do + + it 'calls rabbitmqadmin to create' do @provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination=target', 'arguments={}', 'routing_key=blablub', 'destination_type=queue') @provider.create end - it 'should call rabbitmqadmin to destroy' do + it 'calls rabbitmqadmin to destroy' do @provider.expects(:rabbitmqadmin).with('delete', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination_type=queue', 'destination=target', 'properties_key=blablub') @provider.destroy end context 'specifying credentials' do - before :each do + before do @resource = Puppet::Type::Rabbitmq_binding.new( - { - :name => 'source@test2@/', - :destination_type => :queue, - :routing_key => 'blablubd', - :arguments => {}, - :user => 'colin', - :password => 'secret' - } + name: 'source@test2@/', + destination_type: :queue, + routing_key: 'blablubd', + arguments: {}, + user: 'colin', + password: 'secret' ) @provider = provider_class.new(@resource) end - it 'should call rabbitmqadmin to create' do + it 'calls rabbitmqadmin to create' do @provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination=test2', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue') @provider.create end end context 'new queue_bindings' do - before :each do + before do @resource = Puppet::Type::Rabbitmq_binding.new( - { - :name => 'binding1', - :source => 'exchange1', - :destination => 'destqueue', - :destination_type => :queue, - :routing_key => 'blablubd', - :arguments => {} - } + name: 'binding1', + source: 'exchange1', + destination: 'destqueue', + destination_type: :queue, + routing_key: 'blablubd', + arguments: {} ) @provider = provider_class.new(@resource) end - it 'should call rabbitmqadmin to create' do + it 'calls rabbitmqadmin to create' do @provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=exchange1', 'destination=destqueue', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue') @provider.create end end - end diff --git a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb index 668c9dfc3..96d011233 100644 --- a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb @@ -5,22 +5,21 @@ end provider_class = Puppet::Type.type(:rabbitmq_exchange).provider(:rabbitmqadmin) describe provider_class do - before :each do + before do @resource = Puppet::Type::Rabbitmq_exchange.new( - {:name => 'test.headers@/', - :type => :headers, - :internal => :false, - :durable => :true, - :auto_delete => :false, - :arguments => { - "hash-headers" => "message-distribution-hash" - }, + name: 'test.headers@/', + type: :headers, + internal: :false, + durable: :true, + auto_delete: :false, + arguments: { + 'hash-headers' => 'message-distribution-hash' } ) @provider = provider_class.new(@resource) end - it 'should return instances' do + it 'returns instances' do provider_class.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT / EOT @@ -39,35 +38,34 @@ expect(instances.size).to eq(9) end - it 'should call rabbitmqadmin to create as guest' do + it 'calls rabbitmqadmin to create as guest' do @provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=test.headers', 'type=headers', 'internal=false', 'durable=true', 'auto_delete=false', 'arguments={"hash-headers":"message-distribution-hash"}', '-c', '/etc/rabbitmq/rabbitmqadmin.conf') @provider.create end - it 'should call rabbitmqadmin to destroy' do + it 'calls rabbitmqadmin to destroy' do @provider.expects(:rabbitmqadmin).with('delete', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=test.headers', '-c', '/etc/rabbitmq/rabbitmqadmin.conf') @provider.destroy end context 'specifying credentials' do - before :each do + before do @resource = Puppet::Type::Rabbitmq_exchange.new( - {:name => 'test.headers@/', - :type => :headers, - :internal => 'false', - :durable => 'true', - :auto_delete => 'false', - :user => 'colin', - :password => 'secret', - :arguments => { - "hash-header" => "message-distribution-hash" - }, - } + name: 'test.headers@/', + type: :headers, + internal: 'false', + durable: 'true', + auto_delete: 'false', + user: 'colin', + password: 'secret', + arguments: { + 'hash-header' => 'message-distribution-hash' + } ) @provider = provider_class.new(@resource) end - it 'should call rabbitmqadmin to create with credentials' do + it 'calls rabbitmqadmin to create with credentials' do @provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=colin', '--password=secret', 'name=test.headers', 'type=headers', 'internal=false', 'durable=true', 'auto_delete=false', 'arguments={"hash-header":"message-distribution-hash"}', '-c', '/etc/rabbitmq/rabbitmqadmin.conf') @provider.create end diff --git a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb index 8ebe530fd..41dc8bcbb 100644 --- a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb @@ -6,82 +6,77 @@ end describe Puppet::Type.type(:rabbitmq_parameter).provider(:rabbitmqctl) do - let(:resource) do Puppet::Type.type(:rabbitmq_parameter).new( - :name => 'documentumShovel@/', - :component_name => 'shovel', - :value => { + name: 'documentumShovel@/', + component_name: 'shovel', + value: { 'src-uri' => 'amqp://', 'src-queue' => 'my-queue', 'dest-uri' => 'amqp://remote-server', - 'dest-queue' => 'another-queue', + 'dest-queue' => 'another-queue' }, - :provider => described_class.name + provider: described_class.name ) end let(:provider) { resource.provider } - after(:each) do + after do described_class.instance_variable_set(:@parameters, nil) end - it 'should accept @ in parameter name' do + it 'accepts @ in parameter name' do resource = Puppet::Type.type(:rabbitmq_parameter).new( - :name => 'documentumShovel@/', - :component_name => 'shovel', - :value => { + name: 'documentumShovel@/', + component_name: 'shovel', + value: { 'src-uri' => 'amqp://', 'src-queue' => 'my-queue', 'dest-uri' => 'amqp://remote-server', - 'dest-queue' => 'another-queue', + 'dest-queue' => 'another-queue' }, - :provider => described_class.name + provider: described_class.name ) provider = described_class.new(resource) expect(provider.should_parameter).to eq('documentumShovel') expect(provider.should_vhost).to eq('/') end - it 'should fail with invalid output from list' do + it 'fails with invalid output from list' do provider.class.expects(:rabbitmqctl).with('list_parameters', '-q', '-p', '/').returns 'foobar' - expect { provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_parameter/) + expect { provider.exists? }.to raise_error(Puppet::Error, %r{cannot parse line from list_parameter}) end - it 'should match parameters from list' do + it 'matches parameters from list' do provider.class.expects(:rabbitmqctl).with('list_parameters', '-q', '-p', '/').returns <<-EOT shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} EOT - expect(provider.exists?).to eq({ - :component_name => 'shovel', - :value => { - 'src-uri' => 'amqp://', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', - 'dest-queue' => 'another-queue', - } - }) + expect(provider.exists?).to eq(component_name: 'shovel', + value: { + 'src-uri' => 'amqp://', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', + 'dest-queue' => 'another-queue' + }) end - it 'should not match an empty list' do + it 'does not match an empty list' do provider.class.expects(:rabbitmqctl).with('list_parameters', '-q', '-p', '/').returns '' expect(provider.exists?).to eq(nil) end - it 'should destroy parameter' do + it 'destroys parameter' do provider.expects(:rabbitmqctl).with('clear_parameter', '-p', '/', 'shovel', 'documentumShovel') provider.destroy end - it 'should only call set_parameter once' do + it 'onlies call set_parameter once' do provider.expects(:rabbitmqctl).with('set_parameter', - '-p', '/', - 'shovel', - 'documentumShovel', - '{"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"}' - ).once + '-p', '/', + 'shovel', + 'documentumShovel', + '{"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"}').once provider.create end - end diff --git a/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb index af4649331..4aaf163a5 100644 --- a/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb @@ -5,21 +5,21 @@ end provider_class = Puppet::Type.type(:rabbitmq_plugin).provider(:rabbitmqplugins) describe provider_class do - before :each do + before do @resource = Puppet::Type::Rabbitmq_plugin.new( - {:name => 'foo'} + name: 'foo' ) @provider = provider_class.new(@resource) end - it 'should match plugins' do + it 'matches plugins' do @provider.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\n") expect(@provider.exists?).to eq('foo') end - it 'should call rabbitmqplugins to enable' do + it 'calls rabbitmqplugins to enable' do @provider.expects(:rabbitmqplugins).with('enable', 'foo') @provider.create end - it 'should call rabbitmqplugins to disable' do + it 'calls rabbitmqplugins to disable' do @provider.expects(:rabbitmqplugins).with('disable', 'foo') @provider.destroy end diff --git a/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb index 35b669041..5c98364a5 100644 --- a/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb @@ -6,108 +6,105 @@ end describe Puppet::Type.type(:rabbitmq_policy).provider(:rabbitmqctl) do - let(:resource) do Puppet::Type.type(:rabbitmq_policy).new( - :name => 'ha-all@/', - :pattern => '.*', - :definition => { + name: 'ha-all@/', + pattern: '.*', + definition: { 'ha-mode' => 'all' }, - :provider => described_class.name + provider: described_class.name ) end let(:provider) { resource.provider } - after(:each) do + after do described_class.instance_variable_set(:@policies, nil) end - it 'should accept @ in policy name' do + it 'accepts @ in policy name' do resource = Puppet::Type.type(:rabbitmq_policy).new( - :name => 'ha@home@/', - :pattern => '.*', - :definition => { + name: 'ha@home@/', + pattern: '.*', + definition: { 'ha-mode' => 'all' }, - :provider => described_class.name + provider: described_class.name ) provider = described_class.new(resource) expect(provider.should_policy).to eq('ha@home') expect(provider.should_vhost).to eq('/') end - it 'should fail with invalid output from list' do + it 'fails with invalid output from list' do provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns 'foobar' - expect { provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_policies/) + expect { provider.exists? }.to raise_error(Puppet::Error, %r{cannot parse line from list_policies}) end - it 'should match policies from list (>=3.2.0)' do + it 'matches policies from list (>=3.2.0)' do provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 / test exchanges .* {"ha-mode":"all"} 0 EOT - expect(provider.exists?).to eq({ - :applyto => 'all', - :pattern => '.*', - :priority => '0', - :definition => { - 'ha-mode' => 'all', - 'ha-sync-mode' => 'automatic'} - }) + expect(provider.exists?).to eq(applyto: 'all', + pattern: '.*', + priority: '0', + definition: { + 'ha-mode' => 'all', + 'ha-sync-mode' => 'automatic' + }) end - it 'should match policies from list (<3.2.0)' do + it 'matches policies from list (<3.2.0)' do provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT / ha-all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 / test .* {"ha-mode":"all"} 0 EOT - expect(provider.exists?).to eq({ - :applyto => 'all', - :pattern => '.*', - :priority => '0', - :definition => { - 'ha-mode' => 'all', - 'ha-sync-mode' => 'automatic'} - }) + expect(provider.exists?).to eq(applyto: 'all', + pattern: '.*', + priority: '0', + definition: { + 'ha-mode' => 'all', + 'ha-sync-mode' => 'automatic' + }) end - it 'should not match an empty list' do + it 'does not match an empty list' do provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns '' expect(provider.exists?).to eq(nil) end - it 'should destroy policy' do + it 'destroys policy' do provider.expects(:rabbitmqctl).with('clear_policy', '-p', '/', 'ha-all') provider.destroy end - it 'should only call set_policy once (<3.2.0)' do + it 'onlies call set_policy once (<3.2.0)' do provider.class.expects(:rabbitmq_version).returns '3.1.0' provider.resource[:priority] = '10' provider.resource[:applyto] = 'exchanges' provider.expects(:rabbitmqctl).with('set_policy', - '-p', '/', - 'ha-all', - '.*', - '{"ha-mode":"all"}', - '10').once + '-p', '/', + 'ha-all', + '.*', + '{"ha-mode":"all"}', + '10').once provider.priority = '10' provider.applyto = 'exchanges' end - it 'should only call set_policy once (>=3.2.0)' do + it 'onlies call set_policy once (>=3.2.0)' do provider.class.expects(:rabbitmq_version).returns '3.2.0' provider.resource[:priority] = '10' provider.resource[:applyto] = 'exchanges' provider.expects(:rabbitmqctl).with('set_policy', - '-p', '/', - '--priority', '10', - '--apply-to', 'exchanges', - 'ha-all', - '.*', - '{"ha-mode":"all"}').once + '-p', '/', + '--priority', '10', + '--apply-to', 'exchanges', + 'ha-all', + '.*', + '{"ha-mode":"all"}').once provider.priority = '10' provider.applyto = 'exchanges' end diff --git a/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb index ac5a0c7e2..f47fcb740 100644 --- a/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb @@ -5,18 +5,17 @@ end provider_class = Puppet::Type.type(:rabbitmq_queue).provider(:rabbitmqadmin) describe provider_class do - before :each do + before do @resource = Puppet::Type::Rabbitmq_queue.new( - {:name => 'test@/', - :durable => :true, - :auto_delete => :false, - :arguments => {} - } + name: 'test@/', + durable: :true, + auto_delete: :false, + arguments: {} ) @provider = provider_class.new(@resource) end - it 'should return instances' do + it 'returns instances' do provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT / EOT @@ -28,31 +27,30 @@ expect(instances.size).to eq(2) end - it 'should call rabbitmqadmin to create' do + it 'calls rabbitmqadmin to create' do @provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}') @provider.create end - it 'should call rabbitmqadmin to destroy' do + it 'calls rabbitmqadmin to destroy' do @provider.expects(:rabbitmqadmin).with('delete', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test') @provider.destroy end context 'specifying credentials' do - before :each do + before do @resource = Puppet::Type::Rabbitmq_queue.new( - {:name => 'test@/', - :durable => 'true', - :auto_delete => 'false', - :arguments => {}, - :user => 'colin', - :password => 'secret', - } + name: 'test@/', + durable: 'true', + auto_delete: 'false', + arguments: {}, + user: 'colin', + password: 'secret' ) @provider = provider_class.new(@resource) end - it 'should call rabbitmqadmin to create' do + it 'calls rabbitmqadmin to create' do @provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}') @provider.create end diff --git a/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb index 78333da69..95ae225fd 100644 --- a/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb @@ -5,36 +5,36 @@ end provider_class = Puppet::Type.type(:rabbitmq_user).provider(:rabbitmqctl) describe provider_class do - before :each do + before do @resource = Puppet::Type::Rabbitmq_user.new( - {:name => 'foo', :password => 'bar'} + name: 'foo', password: 'bar' ) @provider = provider_class.new(@resource) end - it 'should match user names' do + it 'matches user names' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo EOT expect(@provider.exists?).to eq('foo') end - it 'should match user names with 2.4.1 syntax' do + it 'matches user names with 2.4.1 syntax' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo bar EOT expect(@provider.exists?).to eq('foo bar') end - it 'should not match if no users on system' do + it 'does not match if no users on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT EOT expect(@provider.exists?).to be_nil end - it 'should not match if no matching users on system' do + it 'does not match if no matching users on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT fooey EOT expect(@provider.exists?).to be_nil end - it 'should match user names from list' do + it 'matches user names from list' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT one two three @@ -43,12 +43,12 @@ EOT expect(@provider.exists?).to eq('foo') end - it 'should create user and set password' do + it 'creates user and set password' do @resource[:password] = 'bar' @provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar') @provider.create end - it 'should create user, set password and set to admin' do + it 'creates user, set password and set to admin' do @resource[:password] = 'bar' @resource[:admin] = 'true' @provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar') @@ -61,11 +61,11 @@ @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator']) @provider.create end - it 'should call rabbitmqctl to delete' do + it 'calls rabbitmqctl to delete' do @provider.expects(:rabbitmqctl).with('delete_user', 'foo') @provider.destroy end - it 'should be able to retrieve admin value' do + it 'is able to retrieve admin value' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] EOT @@ -76,13 +76,13 @@ EOT expect(@provider.admin).to eq(:false) end - it 'should fail if admin value is invalid' do + it 'fails if admin value is invalid' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo fail EOT - expect { @provider.admin }.to raise_error(Puppet::Error, /Could not match line/) + expect { @provider.admin }.to raise_error(Puppet::Error, %r{Could not match line}) end - it 'should be able to set admin value' do + it 'is able to set admin value' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [] icinga [monitoring] @@ -90,39 +90,39 @@ kitchen2 [abc, def, ghi] EOT @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator']) - @provider.admin=:true + @provider.admin = :true end - it 'should not interfere with existing tags on the user when setting admin value' do + it 'does not interfere with existing tags on the user when setting admin value' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [bar, baz] icinga [monitoring] kitchen [] kitchen2 [abc, def, ghi] EOT - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz', 'administrator'].sort) - @provider.admin=:true + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', %w[bar baz administrator].sort) + @provider.admin = :true end - it 'should be able to unset admin value' do + it 'is able to unset admin value' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] guest [administrator] icinga [] EOT @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', []) - @provider.admin=:false + @provider.admin = :false end - it 'should not interfere with existing tags on the user when unsetting admin value' do + it 'does not interfere with existing tags on the user when unsetting admin value' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator, bar, baz] icinga [monitoring] kitchen [] kitchen2 [abc, def, ghi] EOT - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz'].sort) - @provider.admin=:false + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', %w[bar baz].sort) + @provider.admin = :false end - it 'should clear all tags on existing user' do + it 'clears all tags on existing user' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT one [administrator] foo [tag1,tag2] @@ -131,10 +131,10 @@ kitchen2 [abc, def, ghi] EOT @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', []) - @provider.tags=[] + @provider.tags = [] end - it 'should set multiple tags' do + it 'sets multiple tags' do @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT one [administrator] foo [] @@ -142,12 +142,12 @@ kitchen [] kitchen2 [abc, def, ghi] EOT - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['tag1','tag2']) - @provider.tags=['tag1','tag2'] + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', %w[tag1 tag2]) + @provider.tags = %w[tag1 tag2] end - it 'should clear tags while keep admin tag' do - @resource[:admin] = true + it 'clears tags while keep admin tag' do + @resource[:admin] = true @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT one [administrator] foo [administrator, tag1, tag2] @@ -155,12 +155,12 @@ kitchen [] kitchen2 [abc, def, ghi] EOT - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator"]) - @provider.tags=[] + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator']) + @provider.tags = [] end - it 'should change tags while keep admin tag' do - @resource[:admin] = true + it 'changes tags while keep admin tag' do + @resource[:admin] = true @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT one [administrator] foo [administrator, tag1, tag2] @@ -168,48 +168,48 @@ kitchen [] kitchen2 [abc, def, ghi] EOT - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator","tag1","tag3","tag7"]) - @provider.tags=['tag1','tag7','tag3'] + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', %w[administrator tag1 tag3 tag7]) + @provider.tags = %w[tag1 tag7 tag3] end - it 'should create user with tags and without admin' do - @resource[:tags] = [ "tag1", "tag2" ] + it 'creates user with tags and without admin' do + @resource[:tags] = %w[tag1 tag2] @provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar') - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["tag1","tag2"]) + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', %w[tag1 tag2]) @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [] EOT @provider.create end - it 'should create user with tags and with admin' do - @resource[:tags] = [ "tag1", "tag2" ] - @resource[:admin] = true + it 'creates user with tags and with admin' do + @resource[:tags] = %w[tag1 tag2] + @resource[:admin] = true @provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar') @provider.expects(:rabbitmqctl).with('-q', 'list_users').twice.returns <<-EOT foo [] EOT - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator"]) - @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator","tag1","tag2"]) + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator']) + @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', %w[administrator tag1 tag2]) @provider.create end - it 'should not return the administrator tag in tags for admins' do + it 'does not return the administrator tag in tags for admins' do @resource[:tags] = [] - @resource[:admin] = true + @resource[:admin] = true @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] EOT expect(@provider.tags).to eq([]) end - it 'should return the administrator tag for non-admins' do + it 'returns the administrator tag for non-admins' do # this should not happen though. @resource[:tags] = [] - @resource[:admin] = :false + @resource[:admin] = :false @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT foo [administrator] EOT - expect(@provider.tags).to eq(["administrator"]) + expect(@provider.tags).to eq(['administrator']) end end diff --git a/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb index 21ba44f46..dfac1e9f3 100644 --- a/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb @@ -4,52 +4,52 @@ config.mock_with :mocha end describe 'Puppet::Type.type(:rabbitmq_user_permissions).provider(:rabbitmqctl)' do - before :each do + before do @provider_class = Puppet::Type.type(:rabbitmq_user_permissions).provider(:rabbitmqctl) @resource = Puppet::Type::Rabbitmq_user_permissions.new( - {:name => 'foo@bar'} + name: 'foo@bar' ) @provider = @provider_class.new(@resource) end - after :each do + after do @provider_class.instance_variable_set(:@users, nil) end - it 'should match user permissions from list' do + it 'matches user permissions from list' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 EOT - expect(@provider.exists?).to eq({:configure=>"1", :write=>"2", :read=>"3"}) + expect(@provider.exists?).to eq(configure: '1', write: '2', read: '3') end - it 'should match user permissions with empty columns' do + it 'matches user permissions with empty columns' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 3 EOT - expect(@provider.exists?).to eq({:configure=>"", :write=>"", :read=>"3"}) + expect(@provider.exists?).to eq(configure: '', write: '', read: '3') end - it 'should not match user permissions with more than 3 columns' do + it 'does not match user permissions with more than 3 columns' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 4 EOT - expect { @provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_user_permissions/) + expect { @provider.exists? }.to raise_error(Puppet::Error, %r{cannot parse line from list_user_permissions}) end - it 'should not match an empty list' do + it 'does not match an empty list' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT EOT expect(@provider.exists?).to eq(nil) end - it 'should create default permissions' do - @provider.instance_variable_set(:@should_vhost, "bar") - @provider.instance_variable_set(:@should_user, "foo") + it 'creates default permissions' do + @provider.instance_variable_set(:@should_vhost, 'bar') + @provider.instance_variable_set(:@should_user, 'foo') @provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', "''", "''", "''") @provider.create end - it 'should destroy permissions' do - @provider.instance_variable_set(:@should_vhost, "bar") - @provider.instance_variable_set(:@should_user, "foo") + it 'destroys permissions' do + @provider.instance_variable_set(:@should_vhost, 'bar') + @provider.instance_variable_set(:@should_user, 'foo') @provider.expects(:rabbitmqctl).with('clear_permissions', '-p', 'bar', 'foo') @provider.destroy end - {:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v| + { configure_permission: '1', write_permission: '2', read_permission: '3' }.each do |k, v| it "should be able to retrieve #{k}" do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 @@ -57,7 +57,7 @@ expect(@provider.send(k)).to eq(v) end end - {:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v| + { configure_permission: '1', write_permission: '2', read_permission: '3' }.each do |k, v| it "should be able to retrieve #{k} after exists has been called" do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 @@ -66,10 +66,9 @@ expect(@provider.send(k)).to eq(v) end end - {:configure_permission => ['foo', '2', '3'], - :read_permission => ['1', '2', 'foo'], - :write_permission => ['1', 'foo', '3'] - }.each do |perm, columns| + { configure_permission: %w[foo 2 3], + read_permission: %w[1 2 foo], + write_permission: %w[1 foo 3] }.each do |perm, columns| it "should be able to sync #{perm}" do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 @@ -79,15 +78,14 @@ @provider.send("#{perm}=".to_sym, 'foo') end end - it 'should only call set_permissions once' do + it 'onlies call set_permissions once' do @provider.class.expects(:rabbitmqctl).with('-q', 'list_user_permissions', 'foo').returns <<-EOT bar 1 2 3 EOT @provider.resource[:configure_permission] = 'foo' @provider.resource[:read_permission] = 'foo' @provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', 'foo', '2', 'foo').once - @provider.configure_permission='foo' - @provider.read_permission='foo' + @provider.configure_permission = 'foo' + @provider.read_permission = 'foo' end end - diff --git a/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb index 14122804a..17b02872d 100644 --- a/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb @@ -5,13 +5,13 @@ end provider_class = Puppet::Type.type(:rabbitmq_vhost).provider(:rabbitmqctl) describe provider_class do - before :each do + before do @resource = Puppet::Type::Rabbitmq_vhost.new( - {:name => 'foo'} + name: 'foo' ) @provider = provider_class.new(@resource) end - it 'should match vhost names' do + it 'matches vhost names' do @provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT Listing vhosts ... foo @@ -19,14 +19,14 @@ EOT expect(@provider.exists?).to eq('foo') end - it 'should not match if no vhosts on system' do + it 'does not match if no vhosts on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT Listing vhosts ... ...done. EOT expect(@provider.exists?).to be_nil end - it 'should not match if no matching vhosts on system' do + it 'does not match if no matching vhosts on system' do @provider.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT Listing vhosts ... fooey @@ -34,11 +34,11 @@ EOT expect(@provider.exists?).to be_nil end - it 'should call rabbitmqctl to create' do + it 'calls rabbitmqctl to create' do @provider.expects(:rabbitmqctl).with('add_vhost', 'foo') @provider.create end - it 'should call rabbitmqctl to create' do + it 'calls rabbitmqctl to create' do @provider.expects(:rabbitmqctl).with('delete_vhost', 'foo') @provider.destroy end diff --git a/spec/unit/puppet/type/rabbitmq_binding_spec.rb b/spec/unit/puppet/type/rabbitmq_binding_spec.rb index 8dbf7f6e3..7a302d079 100644 --- a/spec/unit/puppet/type/rabbitmq_binding_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_binding_spec.rb @@ -1,45 +1,45 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_binding) do - before :each do + before do @binding = Puppet::Type.type(:rabbitmq_binding).new( - :name => 'foo@blub@bar', - :destination_type => :queue + name: 'foo@blub@bar', + destination_type: :queue ) end - it 'should accept an queue name' do + it 'accepts an queue name' do @binding[:name] = 'dan@dude@pl' expect(@binding[:name]).to eq('dan@dude@pl') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_binding).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should error when missing source' do - expect { + it 'errors when missing source' do + expect do Puppet::Type.type(:rabbitmq_binding).new( - :name => 'test binding', - :destination => 'foobar' + name: 'test binding', + destination: 'foobar' ) - }.to raise_error(Puppet::Error, /Source and destination must both be defined/) + end.to raise_error(Puppet::Error, %r{Source and destination must both be defined}) end - it 'should error when missing destination' do - expect { + it 'errors when missing destination' do + expect do Puppet::Type.type(:rabbitmq_binding).new( - :name => 'test binding', - :source => 'foobar' + name: 'test binding', + source: 'foobar' ) - }.to raise_error(Puppet::Error, /Source and destination must both be defined/) + end.to raise_error(Puppet::Error, %r{Source and destination must both be defined}) end - it 'should accept an binding destination_type' do + it 'accepts an binding destination_type' do @binding[:destination_type] = :exchange expect(@binding[:destination_type]).to eq(:exchange) end - it 'should accept a user' do + it 'accepts a user' do @binding[:user] = :root expect(@binding[:user]).to eq(:root) end - it 'should accept a password' do + it 'accepts a password' do @binding[:password] = :PaSsw0rD expect(@binding[:password]).to eq(:PaSsw0rD) end diff --git a/spec/unit/puppet/type/rabbitmq_exchange_spec.rb b/spec/unit/puppet/type/rabbitmq_exchange_spec.rb index eb27ef6fa..bcf383cf7 100644 --- a/spec/unit/puppet/type/rabbitmq_exchange_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_exchange_spec.rb @@ -1,55 +1,55 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_exchange) do - before :each do + before do @exchange = Puppet::Type.type(:rabbitmq_exchange).new( - :name => 'foo@bar', - :type => :topic, - :internal => false, - :auto_delete => false, - :durable => true + name: 'foo@bar', + type: :topic, + internal: false, + auto_delete: false, + durable: true ) end - it 'should accept an exchange name' do + it 'accepts an exchange name' do @exchange[:name] = 'dan@pl' expect(@exchange[:name]).to eq('dan@pl') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_exchange).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should not allow whitespace in the name' do - expect { + it 'does not allow whitespace in the name' do + expect do @exchange[:name] = 'b r' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should not allow names without @' do - expect { + it 'does not allow names without @' do + expect do @exchange[:name] = 'b_r' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should accept an exchange type' do + it 'accepts an exchange type' do @exchange[:type] = :direct expect(@exchange[:type]).to eq(:direct) end - it 'should require a type' do - expect { - Puppet::Type.type(:rabbitmq_exchange).new(:name => 'foo@bar') - }.to raise_error(/.*must set type when creating exchange.*/) + it 'requires a type' do + expect do + Puppet::Type.type(:rabbitmq_exchange).new(name: 'foo@bar') + end.to raise_error(%r{.*must set type when creating exchange.*}) end - it 'should not require a type when destroying' do - expect { - Puppet::Type.type(:rabbitmq_exchange).new(:name => 'foo@bar', :ensure => :absent) - }.to_not raise_error + it 'does not require a type when destroying' do + expect do + Puppet::Type.type(:rabbitmq_exchange).new(name: 'foo@bar', ensure: :absent) + end.not_to raise_error end - it 'should accept a user' do + it 'accepts a user' do @exchange[:user] = :root expect(@exchange[:user]).to eq(:root) end - it 'should accept a password' do + it 'accepts a password' do @exchange[:password] = :PaSsw0rD expect(@exchange[:password]).to eq(:PaSsw0rD) end diff --git a/spec/unit/puppet/type/rabbitmq_parameter_spec.rb b/spec/unit/puppet/type/rabbitmq_parameter_spec.rb index 9b3e4a199..9b5190d80 100644 --- a/spec/unit/puppet/type/rabbitmq_parameter_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_parameter_spec.rb @@ -1,79 +1,77 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_parameter) do - before do @parameter = Puppet::Type.type(:rabbitmq_parameter).new( - :name => 'documentumShovel@/', - :component_name => 'shovel', - :value => { + name: 'documentumShovel@/', + component_name: 'shovel', + value: { 'src-uri' => 'amqp://myremote-server', 'src-queue' => 'queue.docs.outgoing', 'dest-uri' => 'amqp://', - 'dest-queue' => 'queue.docs.incoming', - }) + 'dest-queue' => 'queue.docs.incoming' + } + ) end - it 'should accept a valid name' do + it 'accepts a valid name' do @parameter[:name] = 'documentumShovel@/' expect(@parameter[:name]).to eq('documentumShovel@/') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_parameter).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should fail when name does not have a @' do - expect { + it 'fails when name does not have a @' do + expect do @parameter[:name] = 'documentumShovel' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should accept a string' do + it 'accepts a string' do @parameter[:component_name] = 'mystring' expect(@parameter[:component_name]).to eq('mystring') end - it 'should not be empty' do - expect { + it 'is not empty' do + expect do @parameter[:component_name] = '' - }.to raise_error(Puppet::Error, /component_name must be defined/) + end.to raise_error(Puppet::Error, %r{component_name must be defined}) end - it 'should accept a valid hash for value' do - value = {'message-ttl' => '1800000'} + it 'accepts a valid hash for value' do + value = { 'message-ttl' => '1800000' } @parameter[:value] = value expect(@parameter[:value]).to eq(value) end - it 'should not accept invalid hash for definition' do - expect { + it 'does not accept invalid hash for definition' do + expect do @parameter[:value] = '' - }.to raise_error(Puppet::Error, /Invalid value/) + end.to raise_error(Puppet::Error, %r{Invalid value}) - expect { + expect do @parameter[:value] = 'guest' - }.to raise_error(Puppet::Error, /Invalid value/) + end.to raise_error(Puppet::Error, %r{Invalid value}) - expect { - @parameter[:value] = {'message-ttl' => ['999', '100']} - }.to raise_error(Puppet::Error, /Invalid value/) + expect do + @parameter[:value] = { 'message-ttl' => %w[999 100] } + end.to raise_error(Puppet::Error, %r{Invalid value}) end - it 'should accept string as myparameter' do - value = {'myparameter' => 'mystring'} + it 'accepts string as myparameter' do + value = { 'myparameter' => 'mystring' } @parameter[:value] = value expect(@parameter[:value]['myparameter']).to be_a(String) expect(@parameter[:value]['myparameter']).to eq('mystring') end - - it 'should convert to integer when string only contains numbers' do - value = {'myparameter' => '1800000'} + it 'converts to integer when string only contains numbers' do + value = { 'myparameter' => '1800000' } @parameter[:value] = value - expect(@parameter[:value]['myparameter']).to be_a(Fixnum) - expect(@parameter[:value]['myparameter']).to eq(1800000) + expect(@parameter[:value]['myparameter']).to be_a(Integer) + expect(@parameter[:value]['myparameter']).to eq(1_800_000) end - end diff --git a/spec/unit/puppet/type/rabbitmq_plugin_spec.rb b/spec/unit/puppet/type/rabbitmq_plugin_spec.rb index 1540a3333..42e160c9f 100644 --- a/spec/unit/puppet/type/rabbitmq_plugin_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_plugin_spec.rb @@ -1,23 +1,23 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_plugin) do - before :each do - @plugin = Puppet::Type.type(:rabbitmq_plugin).new(:name => 'foo') + before do + @plugin = Puppet::Type.type(:rabbitmq_plugin).new(name: 'foo') end - it 'should accept a plugin name' do + it 'accepts a plugin name' do @plugin[:name] = 'plugin-name' expect(@plugin[:name]).to eq('plugin-name') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_plugin).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should default to a umask of 0022' do - expect(@plugin[:umask]).to eq(0022) + it 'defaults to a umask of 0022' do + expect(@plugin[:umask]).to eq(0o022) end - it 'should not allow a non-octal value to be specified' do - expect { + it 'does not allow a non-octal value to be specified' do + expect do @plugin[:umask] = '198' - }.to raise_error(Puppet::Error, /The umask specification is invalid: "198"/) + end.to raise_error(Puppet::Error, %r{The umask specification is invalid: "198"}) end end diff --git a/spec/unit/puppet/type/rabbitmq_policy_spec.rb b/spec/unit/puppet/type/rabbitmq_policy_spec.rb index ebb63f84a..f20a5f7fd 100644 --- a/spec/unit/puppet/type/rabbitmq_policy_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_policy_spec.rb @@ -1,178 +1,178 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_policy) do - before do @policy = Puppet::Type.type(:rabbitmq_policy).new( - :name => 'ha-all@/', - :pattern => '.*', - :definition => { + name: 'ha-all@/', + pattern: '.*', + definition: { 'ha-mode' => 'all' - }) + } + ) end - it 'should accept a valid name' do + it 'accepts a valid name' do @policy[:name] = 'ha-all@/' expect(@policy[:name]).to eq('ha-all@/') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_policy).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should fail when name does not have a @' do - expect { + it 'fails when name does not have a @' do + expect do @policy[:name] = 'ha-all' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should accept a valid regex for pattern' do + it 'accepts a valid regex for pattern' do @policy[:pattern] = '.*?' expect(@policy[:pattern]).to eq('.*?') end - it 'should accept an empty string for pattern' do + it 'accepts an empty string for pattern' do @policy[:pattern] = '' expect(@policy[:pattern]).to eq('') end - it 'should not accept invalid regex for pattern' do - expect { + it 'does not accept invalid regex for pattern' do + expect do @policy[:pattern] = '*' - }.to raise_error(Puppet::Error, /Invalid regexp/) + end.to raise_error(Puppet::Error, %r{Invalid regexp}) end - it 'should accept valid value for applyto' do + it 'accepts valid value for applyto' do [:all, :exchanges, :queues].each do |v| @policy[:applyto] = v expect(@policy[:applyto]).to eq(v) end end - it 'should not accept invalid value for applyto' do - expect { + it 'does not accept invalid value for applyto' do + expect do @policy[:applyto] = 'me' - }.to raise_error(Puppet::Error, /Invalid value/) + end.to raise_error(Puppet::Error, %r{Invalid value}) end - it 'should accept a valid hash for definition' do - definition = {'ha-mode' => 'all', 'ha-sync-mode' => 'automatic'} + it 'accepts a valid hash for definition' do + definition = { 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic' } @policy[:definition] = definition expect(@policy[:definition]).to eq(definition) end - it 'should not accept invalid hash for definition' do - expect { + it 'does not accept invalid hash for definition' do + expect do @policy[:definition] = 'ha-mode' - }.to raise_error(Puppet::Error, /Invalid definition/) + end.to raise_error(Puppet::Error, %r{Invalid definition}) - expect { - @policy[:definition] = {'ha-mode' => ['a', 'b']} - }.to raise_error(Puppet::Error, /Invalid definition/) + expect do + @policy[:definition] = { 'ha-mode' => %w[a b] } + end.to raise_error(Puppet::Error, %r{Invalid definition}) end - it 'should accept valid value for priority' do + it 'accepts valid value for priority' do [0, 10, '0', '10'].each do |v| @policy[:priority] = v expect(@policy[:priority]).to eq(v) end end - it 'should not accept invalid value for priority' do + it 'does not accept invalid value for priority' do ['-1', -1, '1.0', 1.0, 'abc', ''].each do |v| - expect { + expect do @policy[:priority] = v - }.to raise_error(Puppet::Error, /Invalid value/) + end.to raise_error(Puppet::Error, %r{Invalid value}) end end - it 'should accept and convert ha-params for ha-mode exactly' do - definition = {'ha-mode' => 'exactly', 'ha-params' => '2'} + it 'accepts and convert ha-params for ha-mode exactly' do + definition = { 'ha-mode' => 'exactly', 'ha-params' => '2' } @policy[:definition] = definition - expect(@policy[:definition]['ha-params']).to be_a(Fixnum) + expect(@policy[:definition]['ha-params']).to be_a(Integer) expect(@policy[:definition]['ha-params']).to eq(2) end - it 'should not accept non-numeric ha-params for ha-mode exactly' do - definition = {'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric'} - expect { + it 'does not accept non-numeric ha-params for ha-mode exactly' do + definition = { 'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid ha-params.*nonnumeric.*exactly/) + end.to raise_error(Puppet::Error, %r{Invalid ha-params.*nonnumeric.*exactly}) end - it 'should accept and convert the expires value' do - definition = {'expires' => '1800000'} + it 'accepts and convert the expires value' do + definition = { 'expires' => '1800000' } @policy[:definition] = definition - expect(@policy[:definition]['expires']).to be_a(Fixnum) - expect(@policy[:definition]['expires']).to eq(1800000) + expect(@policy[:definition]['expires']).to be_a(Integer) + expect(@policy[:definition]['expires']).to eq(1_800_000) end - it 'should not accept non-numeric expires value' do - definition = {'expires' => 'future'} - expect { + it 'does not accept non-numeric expires value' do + definition = { 'expires' => 'future' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid expires value.*future/) + end.to raise_error(Puppet::Error, %r{Invalid expires value.*future}) end - it 'should accept and convert the message-ttl value' do - definition = {'message-ttl' => '1800000'} + it 'accepts and convert the message-ttl value' do + definition = { 'message-ttl' => '1800000' } @policy[:definition] = definition - expect(@policy[:definition]['message-ttl']).to be_a(Fixnum) - expect(@policy[:definition]['message-ttl']).to eq(1800000) + expect(@policy[:definition]['message-ttl']).to be_a(Integer) + expect(@policy[:definition]['message-ttl']).to eq(1_800_000) end - it 'should not accept non-numeric message-ttl value' do - definition = {'message-ttl' => 'future'} - expect { + it 'does not accept non-numeric message-ttl value' do + definition = { 'message-ttl' => 'future' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid message-ttl value.*future/) + end.to raise_error(Puppet::Error, %r{Invalid message-ttl value.*future}) end - it 'should accept and convert the max-length value' do - definition = {'max-length' => '1800000'} + it 'accepts and convert the max-length value' do + definition = { 'max-length' => '1800000' } @policy[:definition] = definition - expect(@policy[:definition]['max-length']).to be_a(Fixnum) - expect(@policy[:definition]['max-length']).to eq(1800000) + expect(@policy[:definition]['max-length']).to be_a(Integer) + expect(@policy[:definition]['max-length']).to eq(1_800_000) end - it 'should not accept non-numeric max-length value' do - definition = {'max-length' => 'future'} - expect { + it 'does not accept non-numeric max-length value' do + definition = { 'max-length' => 'future' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid max-length value.*future/) + end.to raise_error(Puppet::Error, %r{Invalid max-length value.*future}) end - it 'should accept and convert the shards-per-node value' do - definition = {'shards-per-node' => '1800000'} + it 'accepts and convert the shards-per-node value' do + definition = { 'shards-per-node' => '1800000' } @policy[:definition] = definition - expect(@policy[:definition]['shards-per-node']).to be_a(Fixnum) - expect(@policy[:definition]['shards-per-node']).to eq(1800000) + expect(@policy[:definition]['shards-per-node']).to be_a(Integer) + expect(@policy[:definition]['shards-per-node']).to eq(1_800_000) end - it 'should not accept non-numeric shards-per-node value' do - definition = {'shards-per-node' => 'future'} - expect { + it 'does not accept non-numeric shards-per-node value' do + definition = { 'shards-per-node' => 'future' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid shards-per-node value.*future/) + end.to raise_error(Puppet::Error, %r{Invalid shards-per-node value.*future}) end - - it 'should accept and convert the ha-sync-batch-size value' do - definition = {'ha-sync-batch-size' => '1800000'} + + it 'accepts and convert the ha-sync-batch-size value' do + definition = { 'ha-sync-batch-size' => '1800000' } @policy[:definition] = definition - expect(@policy[:definition]['ha-sync-batch-size']).to be_a(Fixnum) - expect(@policy[:definition]['ha-sync-batch-size']).to eq(1800000) + expect(@policy[:definition]['ha-sync-batch-size']).to be_a(Integer) + expect(@policy[:definition]['ha-sync-batch-size']).to eq(1_800_000) end - - it 'should not accept non-numeric ha-sync-batch-size value' do - definition = {'ha-sync-batch-size' => 'future'} - expect { + + it 'does not accept non-numeric ha-sync-batch-size value' do + definition = { 'ha-sync-batch-size' => 'future' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid ha-sync-batch-size value.*future/) + end.to raise_error(Puppet::Error, %r{Invalid ha-sync-batch-size value.*future}) end - it 'should accept list value in ha-params when ha-mode = nodes' do - definition = {'ha-mode' => 'nodes', 'ha-params' => ['rabbit@rabbit-01', 'rabbit@rabbit-02']} + it 'accepts list value in ha-params when ha-mode = nodes' do + definition = { 'ha-mode' => 'nodes', 'ha-params' => ['rabbit@rabbit-01', 'rabbit@rabbit-02'] } @policy[:definition] = definition expect(@policy[:definition]['ha-mode']).to eq('nodes') expect(@policy[:definition]['ha-params']).to be_a(Array) @@ -180,11 +180,10 @@ expect(@policy[:definition]['ha-params'][1]).to eq('rabbit@rabbit-02') end - it 'should not accept non-list value in ha-params when ha-mode = nodes' do - definition = {'ha-mode' => 'nodes', 'ha-params' => 'this-will-fail'} - expect { + it 'does not accept non-list value in ha-params when ha-mode = nodes' do + definition = { 'ha-mode' => 'nodes', 'ha-params' => 'this-will-fail' } + expect do @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid definition, value this-will-fail for key ha-params is not an array/) + end.to raise_error(Puppet::Error, %r{Invalid definition, value this-will-fail for key ha-params is not an array}) end - end diff --git a/spec/unit/puppet/type/rabbitmq_queue_spec.rb b/spec/unit/puppet/type/rabbitmq_queue_spec.rb index 4b872439d..123a5d74f 100644 --- a/spec/unit/puppet/type/rabbitmq_queue_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_queue_spec.rb @@ -1,57 +1,57 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_queue) do - before :each do + before do @queue = Puppet::Type.type(:rabbitmq_queue).new( - :name => 'foo@bar', - :durable => :true, - :arguments => { + name: 'foo@bar', + durable: :true, + arguments: { 'x-message-ttl' => 45, 'x-dead-letter-exchange' => 'deadexchange' } ) end - it 'should accept an queue name' do + it 'accepts an queue name' do @queue[:name] = 'dan@pl' expect(@queue[:name]).to eq('dan@pl') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_queue).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should not allow whitespace in the name' do - expect { + it 'does not allow whitespace in the name' do + expect do @queue[:name] = 'b r' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should not allow names without @' do - expect { + it 'does not allow names without @' do + expect do @queue[:name] = 'b_r' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should accept an arguments with numbers value' do - @queue[:arguments] = {'x-message-ttl' => 30} - expect(@queue[:arguments].to_json).to eq("{\"x-message-ttl\":30}") + it 'accepts an arguments with numbers value' do + @queue[:arguments] = { 'x-message-ttl' => 30 } + expect(@queue[:arguments].to_json).to eq('{"x-message-ttl":30}') expect(@queue[:arguments]['x-message-ttl']).to eq(30) end - it 'should accept an arguments with string value' do - @queue[:arguments] = {'x-dead-letter-exchange' => 'catchallexchange'} - expect(@queue[:arguments].to_json).to eq("{\"x-dead-letter-exchange\":\"catchallexchange\"}") + it 'accepts an arguments with string value' do + @queue[:arguments] = { 'x-dead-letter-exchange' => 'catchallexchange' } + expect(@queue[:arguments].to_json).to eq('{"x-dead-letter-exchange":"catchallexchange"}') end - it 'should accept an queue durable' do + it 'accepts an queue durable' do @queue[:durable] = :true expect(@queue[:durable]).to eq(:true) end - it 'should accept a user' do + it 'accepts a user' do @queue[:user] = :root expect(@queue[:user]).to eq(:root) end - it 'should accept a password' do + it 'accepts a password' do @queue[:password] = :PaSsw0rD expect(@queue[:password]).to eq(:PaSsw0rD) end diff --git a/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb b/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb index 90424dc2a..298d529f1 100644 --- a/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb @@ -1,48 +1,48 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_user_permissions) do - before :each do - @perms = Puppet::Type.type(:rabbitmq_user_permissions).new(:name => 'foo@bar') + before do + @perms = Puppet::Type.type(:rabbitmq_user_permissions).new(name: 'foo@bar') end - it 'should accept a valid hostname name' do + it 'accepts a valid hostname name' do @perms[:name] = 'dan@bar' expect(@perms[:name]).to eq('dan@bar') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_user_permissions).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should fail when names dont have a @' do - expect { + it 'fails when names dont have a @' do + expect do @perms[:name] = 'bar' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end [:configure_permission, :read_permission, :write_permission].each do |param| - it 'should not default to anything' do - expect(@perms[param]).to eq(nil) + it 'does not default to anything' do + expect(@perms[param]).to eq(nil) end it "should accept a valid regex for #{param}" do @perms[param] = '.*?' - expect(@perms[param]).to eq('.*?') + expect(@perms[param]).to eq('.*?') end it "should accept an empty string for #{param}" do @perms[param] = '' - expect(@perms[param]).to eq('') + expect(@perms[param]).to eq('') end it "should not accept invalid regex for #{param}" do - expect { + expect do @perms[param] = '*' - }.to raise_error(Puppet::Error, /Invalid regexp/) + end.to raise_error(Puppet::Error, %r{Invalid regexp}) end end - {:rabbitmq_vhost => 'dan@test', :rabbitmq_user => 'test@dan'}.each do |k,v| + { rabbitmq_vhost: 'dan@test', rabbitmq_user: 'test@dan' }.each do |k, v| it "should autorequire #{k}" do - if k == :rabbitmq_vhost - vhost = Puppet::Type.type(k).new(:name => "test") - else - vhost = Puppet::Type.type(k).new(:name => "test", :password => 'pass') - end - perm = Puppet::Type.type(:rabbitmq_user_permissions).new(:name => v) + vhost = if k == :rabbitmq_vhost + Puppet::Type.type(k).new(name: 'test') + else + Puppet::Type.type(k).new(name: 'test', password: 'pass') + end + perm = Puppet::Type.type(:rabbitmq_user_permissions).new(name: v) config = Puppet::Resource::Catalog.new :testing do |conf| [vhost, perm].each { |resource| conf.add_resource resource } end diff --git a/spec/unit/puppet/type/rabbitmq_user_spec.rb b/spec/unit/puppet/type/rabbitmq_user_spec.rb index 3a8f5cec8..d2df4db6e 100644 --- a/spec/unit/puppet/type/rabbitmq_user_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_user_spec.rb @@ -1,31 +1,31 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_user) do - before :each do - @user = Puppet::Type.type(:rabbitmq_user).new(:name => 'foo', :password => 'pass') + before do + @user = Puppet::Type.type(:rabbitmq_user).new(name: 'foo', password: 'pass') end - it 'should accept a user name' do + it 'accepts a user name' do @user[:name] = 'dan' expect(@user[:name]).to eq('dan') expect(@user[:admin]).to eq(:false) end - it 'should accept a password' do + it 'accepts a password' do @user[:password] = 'foo' expect(@user[:password]).to eq('foo') end - it 'should require a password' do - expect { - Puppet::Type.type(:rabbitmq_user).new(:name => 'foo') - }.to raise_error(/must set password/) + it 'requires a password' do + expect do + Puppet::Type.type(:rabbitmq_user).new(name: 'foo') + end.to raise_error(%r{must set password}) end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_user).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should not allow whitespace in the name' do - expect { + it 'does not allow whitespace in the name' do + expect do @user[:name] = 'b r' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end [true, false, 'true', 'false'].each do |val| it "admin property should accept #{val}" do @@ -33,19 +33,19 @@ expect(@user[:admin]).to eq(val.to_s.to_sym) end end - it 'should not accept non-boolean values for admin' do - expect { + it 'does not accept non-boolean values for admin' do + expect do @user[:admin] = 'yes' - }.to raise_error(Puppet::Error, /Invalid value/) + end.to raise_error(Puppet::Error, %r{Invalid value}) end - it 'should not accept tags with spaces' do - expect { + it 'does not accept tags with spaces' do + expect do @user[:tags] = ['policy maker'] - }.to raise_error(Puppet::Error, /Invalid tag/) + end.to raise_error(Puppet::Error, %r{Invalid tag}) end - it 'should not accept the administrator tag' do - expect { + it 'does not accept the administrator tag' do + expect do @user[:tags] = ['administrator'] - }.to raise_error(Puppet::Error, /must use admin property/) + end.to raise_error(Puppet::Error, %r{must use admin property}) end end diff --git a/spec/unit/puppet/type/rabbitmq_vhost_spec.rb b/spec/unit/puppet/type/rabbitmq_vhost_spec.rb index 03d7ebb68..b7051aefb 100644 --- a/spec/unit/puppet/type/rabbitmq_vhost_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_vhost_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' describe Puppet::Type.type(:rabbitmq_vhost) do - before :each do - @vhost = Puppet::Type.type(:rabbitmq_vhost).new(:name => 'foo') + before do + @vhost = Puppet::Type.type(:rabbitmq_vhost).new(name: 'foo') end - it 'should accept a vhost name' do + it 'accepts a vhost name' do @vhost[:name] = 'dan' expect(@vhost[:name]).to eq('dan') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_vhost).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should not allow whitespace in the name' do - expect { + it 'does not allow whitespace in the name' do + expect do @vhost[:name] = 'b r' - }.to raise_error(Puppet::Error, /Valid values match/) + end.to raise_error(Puppet::Error, %r{Valid values match}) end end diff --git a/spec/unit/rabbitmq_nodename_spec.rb b/spec/unit/rabbitmq_nodename_spec.rb index 621d7ebfe..fbafa2ec1 100644 --- a/spec/unit/rabbitmq_nodename_spec.rb +++ b/spec/unit/rabbitmq_nodename_spec.rb @@ -1,13 +1,13 @@ -require "spec_helper" +require 'spec_helper' describe Facter::Util::Fact do - before { + before do Facter.clear - } + end - describe "rabbitmq_nodename" do + describe 'rabbitmq_nodename' do context 'with value' do - before :each do + before do Facter::Core::Execution.stubs(:which).with('rabbitmqctl').returns(true) Facter::Core::Execution.stubs(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit1 ...') end @@ -17,7 +17,7 @@ end context 'with dashes in hostname' do - before :each do + before do Facter::Core::Execution.stubs(:which).with('rabbitmqctl').returns(true) Facter::Core::Execution.stubs(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit-1 ...') end @@ -27,7 +27,7 @@ end context 'with quotes around node name' do - before :each do + before do Facter::Core::Execution.stubs(:which).with('rabbitmqctl').returns(true) Facter::Core::Execution.stubs(:execute).with('rabbitmqctl status 2>&1').returns('Status of node \'monty@rabbit-1\' ...') end @@ -37,7 +37,7 @@ end context 'without trailing points' do - before :each do + before do Facter::Core::Execution.stubs(:which).with('rabbitmqctl').returns(true) Facter::Core::Execution.stubs(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit-1') end @@ -45,6 +45,5 @@ expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1') } end - end end diff --git a/spec/unit/rabbitmq_version_spec.rb b/spec/unit/rabbitmq_version_spec.rb index fedddff4a..a370e326e 100644 --- a/spec/unit/rabbitmq_version_spec.rb +++ b/spec/unit/rabbitmq_version_spec.rb @@ -1,13 +1,13 @@ -require "spec_helper" +require 'spec_helper' describe Facter::Util::Fact do - before { + before do Facter.clear - } + end - describe "rabbitmq_version" do + describe 'rabbitmq_version' do context 'with value' do - before :each do + before do Facter::Core::Execution.stubs(:which).with('rabbitmqadmin').returns(true) Facter::Core::Execution.stubs(:execute).with('rabbitmqadmin --version 2>&1').returns('rabbitmqadmin 3.6.0') end From 542918b056e5c62d3aeaea0478b7e768831a47ac Mon Sep 17 00:00:00 2001 From: William Yardley Date: Wed, 30 Aug 2017 09:16:53 -0700 Subject: [PATCH 4/4] manual fixes to errors introduced by autofixes --- .../rabbitmq_user_permissions/rabbitmqctl.rb | 2 +- spec/classes/rabbitmq_spec.rb | 56 +++++++++++-------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb index dbc7576cc..5baa51bae 100644 --- a/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb @@ -18,7 +18,7 @@ def self.users(name, vhost) run_with_retries do rabbitmqctl('-q', 'list_user_permissions', name) end.split(%r{\n}).each do |line| - line = .strip_backslashes(line) + line = strip_backslashes(line) if line =~ %r{^(\S+)\s+(\S*)\s+(\S*)\s+(\S*)$} @users[name][Regexp.last_match(1)] = { configure: Regexp.last_match(2), read: Regexp.last_match(4), write: Regexp.last_match(3) } diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index a58b04e5d..65673c2ed 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -100,9 +100,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile unlimited - rabbitmq hard nofile unlimited - ' + 'content' => <<-EOS +rabbitmq soft nofile unlimited +rabbitmq hard nofile unlimited +EOS ) } end @@ -116,9 +117,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile infinity - rabbitmq hard nofile infinity - ' + 'content' => <<-EOS +rabbitmq soft nofile infinity +rabbitmq hard nofile infinity +EOS ) } end @@ -132,9 +134,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile -1 - rabbitmq hard nofile -1 - ' + 'content' => <<-EOS +rabbitmq soft nofile -1 +rabbitmq hard nofile -1 +EOS ) } end @@ -148,9 +151,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Class[Rabbitmq::Service]', - 'content' => 'rabbitmq soft nofile 1234 - rabbitmq hard nofile 1234 - ' + 'content' => <<-EOS +rabbitmq soft nofile 1234 +rabbitmq hard nofile 1234 +EOS ) } end @@ -230,9 +234,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] - LimitNOFILE=unlimited - ' + 'content' => <<-EOS +[Service] +LimitNOFILE=unlimited +EOS ) } end @@ -246,9 +251,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] - LimitNOFILE=infinity - ' + 'content' => <<-EOS +[Service] +LimitNOFILE=infinity +EOS ) } end @@ -262,9 +268,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] - LimitNOFILE=-1 - ' + 'content' => <<-EOS +[Service] +LimitNOFILE=-1 +EOS ) } end @@ -278,9 +285,10 @@ 'group' => '0', 'mode' => '0644', 'notify' => 'Exec[rabbitmq-systemd-reload]', - 'content' => '[Service] - LimitNOFILE=1234 - ' + 'content' => <<-EOS +[Service] +LimitNOFILE=1234 +EOS ) } end