Add actual postgresl module from puppetlabs
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / defines / pg_hba_rule_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::pg_hba_rule', :type => :define do
4   let :facts do
5     {
6       :postgres_default_version => '8.4',
7       :osfamily => 'Debian',
8       :concat_basedir => tmpfilename('pg_hba'),
9     }
10   end
11   let :title do
12     'test'
13   end
14   let :target do
15     tmpfilename('pg_hba_rule')
16   end
17
18   context 'test template 1' do
19     let :params do
20       {
21         :type => 'host',
22         :database => 'all',
23         :user => 'all',
24         :address => '1.1.1.1/24',
25         :auth_method => 'md5',
26         :target => target,
27       }
28     end
29     it do
30       content = param('concat::fragment', 'pg_hba_rule_test', 'content')
31       content.should =~ /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/
32     end
33   end
34
35   context 'test template 2' do
36     let :params do
37       {
38         :type => 'local',
39         :database => 'all',
40         :user => 'all',
41         :auth_method => 'ident',
42         :target => target,
43       }
44     end
45     it do
46       content = param('concat::fragment', 'pg_hba_rule_test', 'content')
47       content.should =~ /local\s+all\s+all\s+ident/
48     end
49   end
50
51   context 'test template 3' do
52     let :params do
53       {
54         :type => 'host',
55         :database => 'all',
56         :user => 'all',
57         :address => '0.0.0.0/0',
58         :auth_method => 'ldap',
59         :auth_option => 'foo=bar',
60         :target => target,
61       }
62     end
63     it do
64       content = param('concat::fragment', 'pg_hba_rule_test', 'content')
65       content.should =~ /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/
66     end
67   end
68
69   context 'validation' do
70     context 'validate type test 1' do
71       let :params do
72         {
73           :type => 'invalid',
74           :database => 'all',
75           :user => 'all',
76           :address => '0.0.0.0/0',
77           :auth_method => 'ldap',
78           :target => target,
79         }
80       end
81       it 'should fail parsing when type is not valid' do
82         expect {subject}.to raise_error(Puppet::Error,
83           /The type you specified \[invalid\] must be one of/)
84       end
85     end
86
87     context 'validate auth_method' do
88       let :params do
89         {
90           :type => 'local',
91           :database => 'all',
92           :user => 'all',
93           :address => '0.0.0.0/0',
94           :auth_method => 'invalid',
95           :target => target,
96         }
97       end
98       it 'should fail parsing when auth_method is not valid' do
99         expect {subject}.to raise_error(Puppet::Error,
100           /The auth_method you specified \[invalid\] must be one of/)
101       end
102     end
103   end
104 end