newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / functions / postgresql_acls_to_resources_hash_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
4   context 'individual transform tests' do
5     it do
6       input = 'local   all             postgres                                ident'
7       result = {
8         "postgresql class generated rule test 0"=>{
9           "type"=>"local",
10           "database"=>"all",
11           "user"=>"postgres",
12           "auth_method"=>"ident",
13           "order"=>"100",
14         },
15       }
16
17       is_expected.to run.with_params([input], 'test', 100).and_return(result)
18     end
19
20     it do
21       input = 'local   all             root                                ident'
22       result = {
23         "postgresql class generated rule test 0"=>{
24           "type"=>"local",
25           "database"=>"all",
26           "user"=>"root",
27           "auth_method"=>"ident",
28           "order"=>"100",
29         },
30       }
31
32       is_expected.to run.with_params([input], 'test', 100).and_return(result)
33     end
34
35     it do
36       input_array = [
37         'local   all             all                                     ident',
38       ]
39       result = {
40         "postgresql class generated rule test 0"=>{
41           "type"=>"local",
42           "database"=>"all",
43           "user"=>"all",
44           "auth_method"=>"ident",
45           "order"=>"100",
46         },
47       }
48
49       is_expected.to run.with_params(input_array, 'test', 100).and_return(result)
50     end
51
52     it do
53       input = 'host    all             all             127.0.0.1/32            md5'
54       result = {
55         "postgresql class generated rule test 0"=>{
56           "type"=>"host",
57           "database"=>"all",
58           "user"=>"all",
59           "address"=>"127.0.0.1/32",
60           "auth_method"=>"md5",
61           "order"=>"100",
62         },
63       }
64
65       is_expected.to run.with_params([input], 'test', 100).and_return(result)
66     end
67
68     it do
69       input = 'host    all             all             0.0.0.0/0            md5'
70       result = {
71         "postgresql class generated rule test 0"=>{
72           "type"=>"host",
73           "database"=>"all",
74           "user"=>"all",
75           "address"=>"0.0.0.0/0",
76           "auth_method"=>"md5",
77           "order"=>"100",
78         },
79       }
80
81       is_expected.to run.with_params([input], 'test', 100).and_return(result)
82     end
83
84     it do
85       input = 'host    all             all             ::1/128                 md5'
86       result = {
87         "postgresql class generated rule test 0"=>{
88           "type"=>"host",
89           "database"=>"all",
90           "user"=>"all",
91           "address"=>"::1/128",
92           "auth_method"=>"md5",
93           "order"=>"100",
94         },
95       }
96
97       is_expected.to run.with_params([input], 'test', 100).and_return(result)
98     end
99
100     it do
101       input = 'host    all             all             1.1.1.1 255.255.255.0    md5'
102       result = {
103         "postgresql class generated rule test 0"=>{
104           "type"=>"host",
105           "database"=>"all",
106           "user"=>"all",
107           "address"=>"1.1.1.1 255.255.255.0",
108           "auth_method"=>"md5",
109           "order"=>"100",
110         },
111       }
112
113       is_expected.to run.with_params([input], 'test', 100).and_return(result)
114     end
115
116     it do
117       input = 'host    all             all             1.1.1.1 255.255.255.0   ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"'
118       result = {
119         "postgresql class generated rule test 0"=>{
120           "type"=>"host",
121           "database"=>"all",
122           "user"=>"all",
123           "address"=>"1.1.1.1 255.255.255.0",
124           "auth_method"=>"ldap",
125           "auth_option"=>"ldapserver=ldap.example.net ldapprefix=\"cn=\" ldapsuffix=\", dc=example, dc=net\"",
126           "order"=>"100",
127         },
128       }
129
130       is_expected.to run.with_params([input], 'test', 100).and_return(result)
131     end
132   end
133
134   it 'should return an empty hash when input is empty array' do
135     is_expected.to run.with_params([], 'test', 100).and_return({})
136   end
137 end