4 RSpec.configure do |config|
5 config.mock_with :mocha
8 describe Puppet::Type.type(:rabbitmq_policy).provider(:rabbitmqctl) do
11 Puppet::Type.type(:rabbitmq_policy).new(
17 :provider => described_class.name
21 let(:provider) { resource.provider }
24 described_class.instance_variable_set(:@policies, nil)
27 it 'should accept @ in policy name' do
28 resource = Puppet::Type.type(:rabbitmq_policy).new(
34 :provider => described_class.name
36 provider = described_class.new(resource)
37 provider.should_policy.should == 'ha@home'
38 provider.should_vhost.should == '/'
41 it 'should fail with invalid output from list' do
42 provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns 'foobar'
43 expect { provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_policies/)
46 it 'should match policies from list (>=3.2.0)' do
47 provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT
48 / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0
49 / test exchanges .* {"ha-mode":"all"} 0
51 provider.exists?.should == {
57 'ha-sync-mode' => 'automatic'}
61 it 'should match policies from list (<3.2.0)' do
62 provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT
63 / ha-all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0
64 / test .* {"ha-mode":"all"} 0
66 provider.exists?.should == {
72 'ha-sync-mode' => 'automatic'}
76 it 'should not match an empty list' do
77 provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns ''
78 provider.exists?.should == nil
81 it 'should destroy policy' do
82 provider.expects(:rabbitmqctl).with('clear_policy', '-p', '/', 'ha-all')
86 it 'should only call set_policy once (<3.2.0)' do
87 provider.class.expects(:rabbitmq_version).returns '3.1.0'
88 provider.resource[:priority] = '10'
89 provider.resource[:applyto] = 'exchanges'
90 provider.expects(:rabbitmqctl).with('set_policy',
96 provider.priority = '10'
97 provider.applyto = 'exchanges'
100 it 'should only call set_policy once (>=3.2.0)' do
101 provider.class.expects(:rabbitmq_version).returns '3.2.0'
102 provider.resource[:priority] = '10'
103 provider.resource[:applyto] = 'exchanges'
104 provider.expects(:rabbitmqctl).with('set_policy',
107 '--apply-to', 'exchanges',
110 '{"ha-mode":"all"}').once
111 provider.priority = '10'
112 provider.applyto = 'exchanges'