3 describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do
4 let(:name) { 'rspec psql test' }
6 Puppet::Type.type(:postgresql_psql).new({ :name => name, :provider => :ruby }.merge attributes)
9 let(:provider) { resource.provider }
11 context("#run_sql_command") do
12 describe "with default attributes" do
13 let(:attributes) do { :db => 'spec_db' } end
15 it "executes with the given psql_path on the given DB" do
16 expect(provider).to receive(:run_command).with(['psql', '-d',
17 attributes[:db], '-t', '-c', '"SELECT \'something\' as \"Custom column\""'], 'postgres',
20 provider.run_sql_command('SELECT \'something\' as "Custom column"')
23 describe "with psql_path and db" do
25 :psql_path => '/opt/postgres/psql',
26 :psql_user => 'spec_user',
27 :psql_group => 'spec_group',
32 it "executes with the given psql_path on the given DB" do
33 expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield
34 expect(provider).to receive(:run_command).with([attributes[:psql_path],
35 '-d', attributes[:db], '-t', '-c', '"SELECT \'something\' as \"Custom column\""'],
36 attributes[:psql_user], attributes[:psql_group], {})
38 provider.run_sql_command('SELECT \'something\' as "Custom column"')
41 describe "with search_path string" do
43 :search_path => "schema1"
46 it "executes with the given search_path" do
47 expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
48 '"set search_path to schema1; SELECT \'something\' as \"Custom column\""'],
49 'postgres', 'postgres', {})
51 provider.run_sql_command('SELECT \'something\' as "Custom column"')
54 describe "with search_path array" do
56 :search_path => ['schema1','schema2'],
59 it "executes with the given search_path" do
60 expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
61 '"set search_path to schema1,schema2; SELECT \'something\' as \"Custom column\""'],
67 provider.run_sql_command('SELECT \'something\' as "Custom column"')
71 describe "with port string" do
72 let(:attributes) do { :port => '5555' } end
74 it "executes with the given port" do
75 expect(provider).to receive(:run_command).with(["psql",
77 "-t", "-c", "\"SELECT something\""],
78 "postgres", "postgres", {} )
80 provider.run_sql_command("SELECT something")
83 describe "with connect_settings" do
84 let(:attributes) do { :connect_settings => { 'PGHOST' => '127.0.0.1' } } end
86 it "executes with the given host" do
87 expect(provider).to receive(:run_command).with(["psql",
89 "\"SELECT something\""],
90 "postgres", "postgres", { 'PGHOST' => '127.0.0.1' } )
92 provider.run_sql_command("SELECT something")
96 context("#run_unless_sql_command") do
97 let(:attributes) do { } end
99 it "calls #run_sql_command with SQL" do
100 expect(provider).to receive(:run_sql_command).with('SELECT COUNT(*) FROM (SELECT 1) count')
101 provider.run_unless_sql_command('SELECT 1')