Skip to content

Commit 62e322e

Browse files
sheenaajayDavidS
authored andcommitted
update unit tests
1 parent 18d89f1 commit 62e322e

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

spec/unit/puppet/provider/postgresql_conn_validator/ruby_spec.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,33 @@
3030

3131
describe '#build_psql_cmd' do
3232
it 'contains expected commandline options' do
33-
expect(provider.validator.build_psql_cmd).to match %r{/usr/bin/psql.*--host.*--port.*--username.*}
33+
expect(provider.validator.build_psql_cmd).to eq(['/usr/bin/psql', '--tuples-only', '--quiet', '--no-psqlrc', '--host', 'db.test.com', '--port', 4444, '--username', 'testuser', '--command',
34+
'SELECT 1'])
3435
end
3536
end
3637

37-
describe '#parse_connect_settings' do
38+
describe 'connect_settings' do
3839
it 'returns array if password is present' do
39-
expect(provider.validator.parse_connect_settings).to eq(['PGPASSWORD=testpass'])
40+
expect(provider.validator.connect_settings).to eq({ 'PGPASSWORD' => 'testpass' })
4041
end
4142

4243
it 'returns an empty array if password is nil' do
4344
attributes.delete(:db_password)
44-
expect(provider.validator.parse_connect_settings).to eq([])
45+
expect(provider.validator.connect_settings).to eq({})
4546
end
4647

4748
it 'returns an array of settings' do
4849
attributes.delete(:db_password)
4950
attributes.merge! connect_settings
50-
expect(provider.validator.parse_connect_settings).to eq(['PGPASSWORD=testpass', 'PGHOST=db.test.com', 'PGPORT=1234'])
51+
expect(provider.validator.connect_settings).to eq({ PGHOST: 'db.test.com', PGPASSWORD: 'testpass', PGPORT: '1234' })
5152
end
5253
end
5354

5455
describe '#attempt_connection' do
5556
let(:sleep_length) { 1 }
5657
let(:tries) { 3 }
57-
let(:exec) do
58-
provider.validator.stub(:execute_command).and_return(true)
59-
end
6058

6159
it 'tries the correct number of times' do
62-
expect(provider.validator).to receive(:execute_command).exactly(3).times
63-
6460
provider.validator.attempt_connection(sleep_length, tries)
6561
end
6662
end

spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
it 'executes with the given psql_path on the given DB' do
1717
expect(provider).to receive(:run_command).with(['psql', '-d',
18-
attributes[:db], '-t', '-X', '-c', '"SELECT \'something\' as \"Custom column\""'], 'postgres',
18+
attributes[:db], '-t', '-X', '-c', 'SELECT \'something\' as "Custom column"'], 'postgres',
1919
'postgres', {})
2020

2121
provider.run_sql_command('SELECT \'something\' as "Custom column"')
@@ -35,7 +35,7 @@
3535
it 'executes with the given psql_path on the given DB' do
3636
expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield
3737
expect(provider).to receive(:run_command).with([attributes[:psql_path],
38-
'-d', attributes[:db], '-t', '-X', '-c', '"SELECT \'something\' as \"Custom column\""'],
38+
'-d', attributes[:db], '-t', '-X', '-c', 'SELECT \'something\' as "Custom column"'],
3939
attributes[:psql_user], attributes[:psql_group], {})
4040

4141
provider.run_sql_command('SELECT \'something\' as "Custom column"')
@@ -50,7 +50,7 @@
5050

5151
it 'executes with the given search_path' do
5252
expect(provider).to receive(:run_command).with(['psql', '-t', '-X', '-c',
53-
'"set search_path to schema1; SELECT \'something\' as \"Custom column\""'],
53+
'set search_path to schema1; SELECT \'something\' as "Custom column"'],
5454
'postgres', 'postgres', {})
5555

5656
provider.run_sql_command('SELECT \'something\' as "Custom column"')
@@ -65,7 +65,7 @@
6565

6666
it 'executes with the given search_path' do
6767
expect(provider).to receive(:run_command).with(['psql', '-t', '-X', '-c',
68-
'"set search_path to schema1,schema2; SELECT \'something\' as \"Custom column\""'],
68+
'set search_path to schema1,schema2; SELECT \'something\' as "Custom column"'],
6969
'postgres', 'postgres',
7070
{})
7171

@@ -79,7 +79,7 @@
7979
it 'executes with the given port' do
8080
expect(provider).to receive(:run_command).with(['psql',
8181
'-p', '5555',
82-
'-t', '-X', '-c', '"SELECT something"'],
82+
'-t', '-X', '-c', 'SELECT something'],
8383
'postgres', 'postgres', {})
8484

8585
provider.run_sql_command('SELECT something')
@@ -91,7 +91,7 @@
9191
it 'executes with the given host' do
9292
expect(provider).to receive(:run_command).with(['psql',
9393
'-t', '-X', '-c',
94-
'"SELECT something"'],
94+
'SELECT something'],
9595
'postgres', 'postgres', 'PGHOST' => '127.0.0.1')
9696

9797
provider.run_sql_command('SELECT something')

0 commit comments

Comments
 (0)