Skip to content

Commit a5185d9

Browse files
Add spec test for instance test1
update spec tests
1 parent 5b829f4 commit a5185d9

File tree

1 file changed

+223
-0
lines changed

1 file changed

+223
-0
lines changed

Diff for: spec/defines/server_instance_spec.rb

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'postgresql::server_instance' do
6+
include_examples 'RedHat 8'
7+
8+
let :pre_condition do
9+
"class { 'postgresql::globals':
10+
encoding => 'UTF-8',
11+
locale => 'en_US.UTF-8',
12+
manage_package_repo => false,
13+
manage_dnf_module => true,
14+
needs_initdb => true,
15+
version => '13',
16+
}
17+
# stop default main instance
18+
class { 'postgresql::server':
19+
service_ensure => 'stopped',
20+
service_enable => false,
21+
}"
22+
end
23+
let(:title) { 'test1' }
24+
let(:params) do
25+
{
26+
'instance_user': 'ins_test1',
27+
'instance_group': 'ins_test1',
28+
'instance_directories': { '/opt/pgsql': { 'ensure' => 'directory' },
29+
'/opt/pgsql/backup': { 'ensure' => 'directory' },
30+
'/opt/pgsql/data': { 'ensure' => 'directory' },
31+
'/opt/pgsql/data/13': { 'ensure' => 'directory' },
32+
'/opt/pgsql/data/home': { 'ensure' => 'directory' },
33+
'/opt/pgsql/wal': { 'ensure' => 'directory' },
34+
'/opt/pgsql/log': { 'ensure' => 'directory' },
35+
'/opt/pgsql/log/13': { 'ensure' => 'directory' },
36+
'/opt/pgsql/log/13/test1': { 'ensure' => 'directory' }, },
37+
'config_settings': { 'pg_hba_conf_path' => '/opt/pgsql/data/13/test1/pg_hba.conf',
38+
'postgresql_conf_path' => '/opt/pgsql/data/13/test1/postgresql.conf',
39+
'pg_ident_conf_path' => '/opt/pgsql/data/13/test1/pg_ident.conf',
40+
'datadir' => '/opt/pgsql/data/13/test1',
41+
'service_name' => 'postgresql@13-test1',
42+
'port' => 5433,
43+
'pg_hba_conf_defaults' => false },
44+
'service_settings': { 'service_name' => 'postgresql@13-test1',
45+
'service_status' => 'systemctl status [email protected]',
46+
'service_ensure' => 'running',
47+
'service_enable' => true },
48+
'initdb_settings': { 'auth_local' => 'peer',
49+
'auth_host' => 'md5',
50+
'needs_initdb' => true,
51+
'datadir' => '/opt/pgsql/data/13/test1',
52+
'encoding' => 'UTF-8',
53+
'lc_messages' => 'en_US.UTF8',
54+
'locale' => 'en_US.UTF8',
55+
'data_checksums' => false,
56+
'group' => 'postgres',
57+
'user' => 'postgres',
58+
'username' => 'ins_test1' },
59+
'config_entries': { 'authentication_timeout': { 'value' => '1min',
60+
'comment' => 'a test' },
61+
'log_statement_stats': { 'value' => 'off' },
62+
'autovacuum_vacuum_scale_factor': { 'value' => 0.3 }, },
63+
'databases': { 'testdb1': { 'encoding' => 'UTF8',
64+
'locale' => 'en_US.UTF8',
65+
'owner' => 'dba_test1' },
66+
'testdb2': { 'encoding' => 'UTF8',
67+
'locale' => 'en_US.UTF8',
68+
'owner' => 'dba_test1' }, },
69+
'roles': { 'ins_test1': { 'superuser' => true,
70+
'login' => true, },
71+
'dba_test1': { 'createdb' => true,
72+
'login' => true, },
73+
'app_test1': { 'login' => true },
74+
'rep_test1': { 'replication' => true,
75+
'login' => true },
76+
'rou_test1': { 'login' => true }, },
77+
'pg_hba_rules': { 'local all INSTANCE user': { 'type' => 'local',
78+
'database' => 'all',
79+
'user' => 'ins_test1',
80+
'auth_method' => 'peer',
81+
'order' => 1 },
82+
'local all DB user': { 'type' => 'local',
83+
'database' => 'all',
84+
'user' => 'dba_test1',
85+
'auth_method' => 'peer',
86+
'order' => 2 },
87+
'local all APP user': { 'type' => 'local',
88+
'database' => 'all',
89+
'user' => 'app_test1',
90+
'auth_method' => 'peer',
91+
'order' => 3 },
92+
'local all READONLY user': { 'type' => 'local',
93+
'database' => 'all',
94+
'user' => 'rou_test1',
95+
'auth_method' => 'peer',
96+
'order' => 4 },
97+
'remote all INSTANCE user PGADMIN server': { 'type' => 'host',
98+
'database' => 'all',
99+
'user' => 'ins_test1',
100+
'address' => '192.168.22.131/32',
101+
'auth_method' => 'md5',
102+
'order' => 5 },
103+
'local replication INSTANCE user': { 'type' => 'local',
104+
'database' => 'replication',
105+
'user' => 'ins_test1',
106+
'auth_method' => 'peer',
107+
'order' => 6 },
108+
'local replication REPLICATION user': { 'type' => 'local',
109+
'database' => 'replication',
110+
'user' => 'rep_test1',
111+
'auth_method' => 'peer',
112+
'order' => 7 }, },
113+
}
114+
end
115+
116+
context 'with postgresql instance test1' do
117+
it { is_expected.to compile.with_all_deps }
118+
it { is_expected.to contain_postgresql__server_instance('test1') }
119+
it { is_expected.to contain_user('ins_test1') }
120+
it { is_expected.to contain_group('ins_test1') }
121+
it { is_expected.to contain_service('postgresqld_instance_test1').with_name('postgresql@13-test1').with_status('systemctl status [email protected]') }
122+
it { is_expected.to contain_systemd__dropin_file('[email protected]') }
123+
it { is_expected.to contain_postgresql_conn_validator('validate_service_is_running_instance_test1') }
124+
it { is_expected.to contain_postgresql_conf('port_for_instance_test1') }
125+
it { is_expected.to contain_postgresql_conf('log_statement_stats_test1') }
126+
it { is_expected.to contain_postgresql_conf('data_directory_for_instance_test1') }
127+
it { is_expected.to contain_postgresql_conf('autovacuum_vacuum_scale_factor_test1') }
128+
it { is_expected.to contain_postgresql_conf('authentication_timeout_test1') }
129+
it { is_expected.to contain_postgresql__server__role('app_test1') }
130+
it { is_expected.to contain_postgresql__server__role('dba_test1') }
131+
it { is_expected.to contain_postgresql__server__role('ins_test1') }
132+
it { is_expected.to contain_postgresql__server__role('rep_test1') }
133+
it { is_expected.to contain_postgresql__server__role('rou_test1') }
134+
it { is_expected.to contain_anchor('postgresql::server::service::begin::test1') }
135+
it { is_expected.to contain_anchor('postgresql::server::service::end::test1') }
136+
it { is_expected.to contain_class('Postgresql::Dnfmodule') }
137+
it { is_expected.to contain_class('Postgresql::Server::Install') }
138+
it { is_expected.to contain_class('Postgresql::Server::Reload') }
139+
it { is_expected.to contain_concat__fragment('pg_hba_rule_local all APP user for instance test1') }
140+
it { is_expected.to contain_concat__fragment('pg_hba_rule_local all DB user for instance test1') }
141+
it { is_expected.to contain_concat__fragment('pg_hba_rule_local all INSTANCE user for instance test1') }
142+
it { is_expected.to contain_concat__fragment('pg_hba_rule_local all READONLY user for instance test1') }
143+
it { is_expected.to contain_concat__fragment('pg_hba_rule_local replication INSTANCE user for instance test1') }
144+
it { is_expected.to contain_concat__fragment('pg_hba_rule_local replication REPLICATION user for instance test1') }
145+
it { is_expected.to contain_concat__fragment('pg_hba_rule_remote all INSTANCE user PGADMIN server for instance test1') }
146+
it { is_expected.to contain_concat('/opt/pgsql/data/13/test1/pg_hba.conf') }
147+
it { is_expected.to contain_concat('/opt/pgsql/data/13/test1/pg_ident.conf') }
148+
it { is_expected.to contain_exec('postgresql_initdb_instance_test1') }
149+
it { is_expected.to contain_file('/opt/pgsql/backup') }
150+
it { is_expected.to contain_file('/opt/pgsql/data/13/test1/postgresql.conf') }
151+
it { is_expected.to contain_file('/opt/pgsql/data/13/test1') }
152+
it { is_expected.to contain_file('/opt/pgsql/data/13') }
153+
it { is_expected.to contain_file('/opt/pgsql/data/home') }
154+
it { is_expected.to contain_file('/opt/pgsql/data') }
155+
it { is_expected.to contain_file('/opt/pgsql/log/13/test1') }
156+
it { is_expected.to contain_file('/opt/pgsql/log/13') }
157+
it { is_expected.to contain_file('/opt/pgsql/log') }
158+
it { is_expected.to contain_file('/opt/pgsql/wal') }
159+
it { is_expected.to contain_file('/opt/pgsql') }
160+
it { is_expected.to contain_postgresql__server__config_entry('authentication_timeout_test1') }
161+
it { is_expected.to contain_postgresql__server__config_entry('autovacuum_vacuum_scale_factor_test1') }
162+
it { is_expected.to contain_postgresql__server__config_entry('data_directory_for_instance_test1') }
163+
it { is_expected.to contain_postgresql__server__config_entry('log_statement_stats_test1') }
164+
it { is_expected.to contain_postgresql__server__config_entry('password_encryption_for_instance_test1') }
165+
it { is_expected.to contain_postgresql__server__config_entry('port_for_instance_test1') }
166+
it { is_expected.to contain_postgresql__server__database('testdb1') }
167+
it { is_expected.to contain_postgresql__server__database('testdb2') }
168+
it { is_expected.to contain_postgresql__server__instance__config('test1') }
169+
it { is_expected.to contain_postgresql__server__instance__initdb('test1') }
170+
it { is_expected.to contain_postgresql__server__instance__passwd('test1') }
171+
it { is_expected.to contain_postgresql__server__instance__service('test1') }
172+
it { is_expected.to contain_postgresql__server__instance__systemd('test1') }
173+
it { is_expected.to contain_postgresql__server__pg_hba_rule('local all APP user for instance test1') }
174+
it { is_expected.to contain_postgresql__server__pg_hba_rule('local all DB user for instance test1') }
175+
it { is_expected.to contain_postgresql__server__pg_hba_rule('local all INSTANCE user for instance test1') }
176+
it { is_expected.to contain_postgresql__server__pg_hba_rule('local all READONLY user for instance test1') }
177+
it { is_expected.to contain_postgresql__server__pg_hba_rule('local replication INSTANCE user for instance test1') }
178+
it { is_expected.to contain_postgresql__server__pg_hba_rule('local replication REPLICATION user for instance test1') }
179+
it { is_expected.to contain_postgresql__server__pg_hba_rule('remote all INSTANCE user PGADMIN server for instance test1') }
180+
it { is_expected.to contain_postgresql_psql('ALTER DATABASE "testdb1" OWNER TO "dba_test1"') }
181+
it { is_expected.to contain_postgresql_psql('ALTER DATABASE "testdb2" OWNER TO "dba_test1"') }
182+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" CONNECTION LIMIT -1') }
183+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" INHERIT') }
184+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" LOGIN') }
185+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" NOCREATEDB') }
186+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" NOCREATEROLE') }
187+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" NOREPLICATION') }
188+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "app_test1" NOSUPERUSER') }
189+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" CONNECTION LIMIT -1') }
190+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" CREATEDB') }
191+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" INHERIT') }
192+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" LOGIN') }
193+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" NOCREATEROLE') }
194+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" NOREPLICATION') }
195+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "dba_test1" NOSUPERUSER') }
196+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" CONNECTION LIMIT -1') }
197+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" INHERIT') }
198+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" LOGIN') }
199+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" NOCREATEDB') }
200+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" NOCREATEROLE') }
201+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" NOREPLICATION') }
202+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "ins_test1" SUPERUSER') }
203+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" CONNECTION LIMIT -1') }
204+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" INHERIT') }
205+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" LOGIN') }
206+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" NOCREATEDB') }
207+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" NOCREATEROLE') }
208+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" NOSUPERUSER') }
209+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rep_test1" REPLICATION') }
210+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" CONNECTION LIMIT -1') }
211+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" INHERIT') }
212+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" LOGIN') }
213+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOCREATEDB') }
214+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOCREATEROLE') }
215+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOREPLICATION') }
216+
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOSUPERUSER') }
217+
it { is_expected.to contain_postgresql_psql('CREATE ROLE app_test1 ENCRYPTED PASSWORD ****') }
218+
it { is_expected.to contain_postgresql_psql('CREATE ROLE dba_test1 ENCRYPTED PASSWORD ****') }
219+
it { is_expected.to contain_postgresql_psql('CREATE ROLE ins_test1 ENCRYPTED PASSWORD ****') }
220+
it { is_expected.to contain_postgresql_psql('CREATE ROLE rep_test1 ENCRYPTED PASSWORD ****') }
221+
it { is_expected.to contain_postgresql_psql('CREATE ROLE rou_test1 ENCRYPTED PASSWORD ****') }
222+
end
223+
end

0 commit comments

Comments
 (0)