1 require 'spec_helper_acceptance'
3 describe 'postgresql_psql', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
5 it 'should always run SQL' do
7 class { 'postgresql::server': } ->
8 postgresql_psql { 'foobar':
10 psql_user => 'postgres',
11 command => 'select 1',
15 apply_manifest(pp, :catch_failures => true)
16 apply_manifest(pp, :expect_changes => true)
19 it 'should run some SQL when the unless query returns no rows' do
21 class { 'postgresql::server': } ->
22 postgresql_psql { 'foobar':
24 psql_user => 'postgres',
25 command => 'select 1',
26 unless => 'select 1 where 1=2',
30 apply_manifest(pp, :catch_failures => true)
31 apply_manifest(pp, :expect_changes => true)
34 it 'should not run SQL when the unless query returns rows' do
36 class { 'postgresql::server': } ->
37 postgresql_psql { 'foobar':
39 psql_user => 'postgres',
40 command => 'select * from pg_database limit 1',
41 unless => 'select 1 where 1=1',
45 apply_manifest(pp, :catch_failures => true)
46 apply_manifest(pp, :catch_changes => true)
49 it 'should not run SQL when refreshed and the unless query returns rows' do
51 class { 'postgresql::server': } ->
52 notify { 'trigger': } ~>
53 postgresql_psql { 'foobar':
55 psql_user => 'postgres',
56 command => 'invalid sql statement',
57 unless => 'select 1 where 1=1',
61 apply_manifest(pp, :catch_failures => true)
62 apply_manifest(pp, :expect_changes => true)
65 context 'with refreshonly' do
66 it 'should not run SQL when the unless query returns no rows' do
68 class { 'postgresql::server': } ->
69 postgresql_psql { 'foobar':
71 psql_user => 'postgres',
72 command => 'select 1',
73 unless => 'select 1 where 1=2',
78 apply_manifest(pp, :catch_failures => true)
79 apply_manifest(pp, :catch_changes => true)
82 it 'should run SQL when refreshed and the unless query returns no rows' do
84 class { 'postgresql::server': } ->
85 notify { 'trigger': } ~>
86 postgresql_psql { 'foobar':
88 psql_user => 'postgres',
89 command => 'select 1',
90 unless => 'select 1 where 1=2',
95 apply_manifest(pp, :catch_failures => true)
96 apply_manifest(pp, :expect_changes => true)
99 it 'should not run SQL when refreshed and the unless query returns rows' do
101 class { 'postgresql::server': } ->
102 notify { 'trigger': } ~>
103 postgresql_psql { 'foobar':
105 psql_user => 'postgres',
106 command => 'invalid sql query',
107 unless => 'select 1 where 1=1',
112 apply_manifest(pp, :catch_failures => true)
113 apply_manifest(pp, :expect_changes => true)
117 it 'should not run some SQL when the onlyif query returns no rows' do
119 class { 'postgresql::server': } ->
120 postgresql_psql { 'foobar':
122 psql_user => 'postgres',
123 command => 'select 1',
124 onlyif => 'select 1 where 1=2',
128 apply_manifest(pp, :catch_failures => true)
129 apply_manifest(pp, :catch_changes => true)
132 it 'should run SQL when the onlyif query returns rows' do
134 class { 'postgresql::server': } ->
135 postgresql_psql { 'foobar':
137 psql_user => 'postgres',
138 command => 'select * from pg_database limit 1',
139 onlyif => 'select 1 where 1=1',
143 apply_manifest(pp, :catch_failures => true)
144 apply_manifest(pp, :expect_changes => true)
147 context 'with secure password passing by environment' do
148 it 'should run SQL that contanins password passed by environment' do
149 select = "select \\'$PASS_TO_EMBED\\'"
151 class { 'postgresql::server': } ->
152 postgresql_psql { 'password embedded by environment: #{select}':
154 psql_user => 'postgres',
155 command => '#{select}',
157 'PASS_TO_EMBED=pa$swD',
161 apply_manifest(pp, :catch_failures => true)
162 apply_manifest(pp, :expect_changes => false)
164 it 'should run SQL that contanins password passed by environment in check' do
165 select = "select 1 where \\'$PASS_TO_EMBED\\'=\\'passwD\\'"
167 class { 'postgresql::server': } ->
168 postgresql_psql { 'password embedded by environment in check: #{select}':
170 psql_user => 'postgres',
171 command => 'invalid sql query',
172 unless => '#{select}',
174 'PASS_TO_EMBED=passwD',
179 apply_manifest(pp, :catch_failures => true)
180 apply_manifest(pp, :expect_changes => false)