3 type = Puppet::Type.type(:postgresql_replication_slot)
4 describe type.provider(:ruby) do
5 let(:name) { 'standby' }
7 type.new({ :name => name, :provider => :ruby }.merge attributes)
10 let(:sql_instances) do
11 "abc | | physical | | | t | | | 0/3000420
12 def | | physical | | | t | | | 0/3000420\n"
20 let(:success_status) { SuccessStatus.new }
27 let(:fail_status) { FailStatus.new }
29 let(:provider) { resource.provider }
31 context 'when listing instances' do
32 let(:attributes) do { } end
34 it 'should list instances' do
35 provider.class.expects(:run_command).with(
36 ['psql', '-t', '-c', 'SELECT * FROM pg_replication_slots;'],
37 'postgres', 'postgres').returns([sql_instances, nil])
38 instances = provider.class.instances
39 expect(instances.size).to eq 2
40 expect(instances[0].name).to eq 'abc'
41 expect(instances[1].name).to eq 'def'
45 context 'when creating slot' do
46 let(:attributes) do { :ensure => 'present' } end
48 context 'when creation works' do
49 it 'should call psql and succeed' do
50 provider.class.expects(:run_command).with(
51 ['psql', '-t', '-c', "SELECT * FROM pg_create_physical_replication_slot('standby');"],
52 'postgres', 'postgres').returns([nil, success_status])
54 expect { provider.create }.not_to raise_error
58 context 'when creation fails' do
59 it 'should call psql and fail' do
60 provider.class.expects(:run_command).with(
61 ['psql', '-t', '-c', "SELECT * FROM pg_create_physical_replication_slot('standby');"],
62 'postgres', 'postgres').returns([nil, fail_status])
64 expect { provider.create }.to raise_error(Puppet::Error, /Failed to create replication slot standby:/)
69 context 'when destroying slot' do
70 let(:attributes) do { :ensure => 'absent' } end
72 context 'when destruction works' do
73 it 'should call psql and succeed' do
74 provider.class.expects(:run_command).with(
75 ['psql', '-t', '-c', "SELECT pg_drop_replication_slot('standby');"],
76 'postgres', 'postgres').returns([nil, success_status])
78 expect { provider.destroy }.not_to raise_error
82 context 'when destruction fails' do
83 it 'should call psql and fail' do
84 provider.class.expects(:run_command).with(
85 ['psql', '-t', '-c', "SELECT pg_drop_replication_slot('standby');"],
86 'postgres', 'postgres').returns([nil, fail_status])
88 expect { provider.destroy }.to raise_error(Puppet::Error, /Failed to destroy replication slot standby:/)