Skip to content

Commit d6ea52d

Browse files
authored
Merge pull request #470 from Joris29/db_tests
Add more database unit tests
2 parents 7d63e35 + 64a9aff commit d6ea52d

File tree

1 file changed

+249
-43
lines changed

1 file changed

+249
-43
lines changed

spec/classes/jira_config_spec.rb

Lines changed: 249 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def self.clear_cache
6262
with_content(%r{<pool-test-while-idle>true}).
6363
with_content(%r{<pool-test-on-borrow>false}).
6464
with_content(%r{<validation-query>select version\(\);}).
65-
with_content(%r{<connection-properties>tcpKeepAlive=true;socketTimeout=240})
65+
with_content(%r{<connection-properties>tcpKeepAlive=true;socketTimeout=240}).
66+
without_content(%r{<validation-query-timeout>})
6667
end
6768

6869
it { is_expected.not_to contain_file(FILENAME_CLUSTER_PROPS) }
@@ -81,24 +82,6 @@ def self.clear_cache
8182
it { is_expected.to contain_package('java-11-openjdk-headless') }
8283
end
8384

84-
context 'with mysql' do
85-
let(:params) do
86-
{
87-
javahome: '/usr/lib/jvm/jre-11-openjdk',
88-
db: 'mysql',
89-
}
90-
end
91-
92-
it { is_expected.to compile.with_all_deps }
93-
94-
it do
95-
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
96-
with_content(%r{<validation-query>select 1</validation-query>}).
97-
with_content(%r{<validation-query-timeout>3</validation-query-timeout>}).
98-
without_content(%r{<connection-properties>})
99-
end
100-
end
101-
10285
context 'with version < 1.3.0' do
10386
let(:params) do
10487
{
@@ -232,7 +215,17 @@ def self.clear_cache
232215
end
233216
end
234217

235-
context 'database settings' do
218+
context 'with unsupported db' do
219+
let(:params) do
220+
super().merge(
221+
db: 'imaginarydb'
222+
)
223+
end
224+
225+
it { is_expected.not_to compile }
226+
end
227+
228+
context 'with default db and custom database settings' do
236229
let(:params) do
237230
super().merge(
238231
connection_settings: 'TEST-SETTING;',
@@ -248,51 +241,223 @@ def self.clear_cache
248241

249242
it do
250243
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
244+
with_content(%r{<database-type>postgres72</database-type>}).
245+
with_content(%r{<url>jdbc:postgresql://localhost:5432/jira</url>}).
246+
with_content(%r{<driver-class>org.postgresql.Driver</driver-class>}).
251247
with_content(%r{<connection-properties>TEST-SETTING;</connection-properties>}).
252248
with_content(%r{<pool-max-size>200</pool-max-size>}).
253249
with_content(%r{<pool-min-size>10</pool-min-size>}).
254250
with_content(%r{<validation-query>SELECT myfunction\(\);</validation-query>})
255251
end
256252
end
257253

258-
context 'mysql params' do
254+
context 'with default db and custom dbport' do
255+
let(:params) do
256+
super().merge(
257+
dbport: '666'
258+
)
259+
end
260+
261+
it do
262+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
263+
with_content(%r{<url>jdbc:postgresql://localhost:666/jira</url>})
264+
end
265+
end
266+
267+
context 'with default db and custom dbriver' do
268+
let(:params) do
269+
super().merge(
270+
dbdriver: 'mydriver'
271+
)
272+
end
273+
274+
it do
275+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
276+
with_content(%r{<url>jdbc:postgresql://localhost:5432/jira</url>}).
277+
with_content(%r{<driver-class>mydriver</driver-class>})
278+
end
279+
end
280+
281+
context 'with default db and custom dbtype' do
282+
let(:params) do
283+
super().merge(
284+
dbtype: 'mydbtype'
285+
)
286+
end
287+
288+
it do
289+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
290+
with_content(%r{<database-type>mydbtype</database-type>}).
291+
with_content(%r{<url>jdbc:postgresql://localhost:5432/jira</url>})
292+
end
293+
end
294+
295+
context 'with mysql db and default database settings' do
259296
let(:params) do
260297
super().merge(
261298
db: 'mysql'
262299
)
263300
end
264301

302+
it { is_expected.to compile.with_all_deps }
303+
304+
it { is_expected.to contain_file(FILENAME_SETENV_SH) }
305+
it { is_expected.to contain_file(FILENAME_USER_SH) }
306+
it { is_expected.to contain_file(FILENAME_SERVER_XML) }
307+
308+
it do
309+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
310+
with_content(%r{<database-type>mysql</database-type>}).
311+
with_content(%r{<url>jdbc:mysql://localhost:3306/jira\?useUnicode=true&amp;characterEncoding=UTF8&amp;sessionVariables=default_storage_engine=InnoDB</url>}).
312+
with_content(%r{<driver-class>com.mysql.jdbc.Driver</driver-class>}).
313+
with_content(%r{<validation-query>select 1</validation-query>}).
314+
with_content(%r{<validation-query-timeout>3</validation-query-timeout>}).
315+
without_content(%r{<connection-properties>})
316+
end
317+
end
318+
319+
context 'with mysql db and custom url' do
320+
let(:params) do
321+
super().merge(
322+
db: 'mysql',
323+
dburl: 'jdbc:mysql://localhost:9999/myjira'
324+
)
325+
end
326+
327+
it do
328+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
329+
with_content(%r{<url>jdbc:mysql://localhost:9999/myjira</url>})
330+
end
331+
end
332+
333+
context 'with mysql db and custom url with dbname and dbserver' do
334+
let(:params) do
335+
super().merge(
336+
db: 'mysql',
337+
dburl: 'jdbc:mysql://localhost:666/jiradb',
338+
dbname: 'mydatabase',
339+
dbserver: 'myhost'
340+
)
341+
end
342+
343+
it do
344+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
345+
with_content(%r{<url>jdbc:mysql://localhost:666/jiradb</url>})
346+
end
347+
end
348+
349+
context 'with sqlserver db and default database settings' do
350+
let(:params) do
351+
super().merge(
352+
db: 'sqlserver'
353+
)
354+
end
355+
356+
it { is_expected.to compile.with_all_deps }
357+
358+
it { is_expected.to contain_file(FILENAME_SETENV_SH) }
359+
it { is_expected.to contain_file(FILENAME_USER_SH) }
360+
it { is_expected.to contain_file(FILENAME_SERVER_XML) }
361+
362+
it do
363+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
364+
with_content(%r{<database-type>mssql</database-type>}).
365+
with_content(%r{<url>jdbc:jtds:sqlserver://localhost:1433/jira</url>}).
366+
with_content(%r{<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>}).
367+
with_content(%r{<validation-query>select 1</validation-query>}).
368+
without_content(%r{<validation-query-timeout>}).
369+
without_content(%r{<connection-properties>})
370+
end
371+
end
372+
373+
context 'with sqlserver db and custom url' do
374+
let(:params) do
375+
super().merge(
376+
db: 'sqlserver',
377+
dburl: 'jdbc:sqlserver://localhost:9999/myjira'
378+
)
379+
end
380+
381+
it do
382+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
383+
with_content(%r{<url>jdbc:sqlserver://localhost:9999/myjira</url>})
384+
end
385+
end
386+
387+
context 'with sqlserver db and custom url with dbname and dbserver' do
388+
let(:params) do
389+
super().merge(
390+
db: 'sqlserver',
391+
dburl: 'jdbc:jtds:sqlserver://localhost:666/jiradb',
392+
dbname: 'mydatabase',
393+
dbserver: 'myhost'
394+
)
395+
end
396+
397+
it do
398+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
399+
with_content(%r{<url>jdbc:jtds:sqlserver://localhost:666/jiradb</url>})
400+
end
401+
end
402+
403+
context 'with oracle db and default database settings' do
404+
let(:params) do
405+
super().merge(
406+
db: 'oracle'
407+
)
408+
end
409+
410+
it { is_expected.to compile.with_all_deps }
411+
265412
it { is_expected.to contain_file(FILENAME_SETENV_SH) }
266413
it { is_expected.to contain_file(FILENAME_USER_SH) }
267414
it { is_expected.to contain_file(FILENAME_SERVER_XML) }
268415

269416
it do
270417
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
271-
with_content(%r{jdbc:mysql://localhost:3306/jira})
418+
with_content(%r{<database-type>oracle10g</database-type>}).
419+
with_content(%r{<url>jdbc:oracle:thin:@localhost:1521:jira</url>}).
420+
with_content(%r{<driver-class>oracle.jdbc.OracleDriver</driver-class>}).
421+
with_content(%r{<validation-query>select 1 from dual</validation-query>}).
422+
without_content(%r{<validation-query-timeout>}).
423+
without_content(%r{<connection-properties>})
272424
end
273425
end
274426

275-
context 'oracle params' do
427+
context 'with oracle db and custom url' do
276428
let(:params) do
277429
super().merge(
278430
db: 'oracle',
279-
dbname: 'mydatabase'
431+
dburl: 'jdbc:oracle:thin:@localhost:9999/mydatabase'
280432
)
281433
end
282434

283435
it do
284436
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
285-
with_content(%r{jdbc:oracle:thin:@localhost:1521:mydatabase}).
286-
with_content(%r{<database-type>oracle10g}).
287-
with_content(%r{<driver-class>oracle.jdbc.OracleDriver})
437+
with_content(%r{<url>jdbc:oracle:thin:@localhost:9999/mydatabase</url>})
288438
end
289439
end
290440

291-
context 'oracle servicename' do
441+
context 'with oracle db and custom url with dbname and dbserver' do
442+
let(:params) do
443+
super().merge(
444+
db: 'oracle',
445+
dburl: 'jdbc:oracle:thin:@localhost:666/mydatabase',
446+
dbname: 'mydatabase',
447+
dbserver: 'myhost'
448+
)
449+
end
450+
451+
it do
452+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
453+
with_content(%r{<url>jdbc:oracle:thin:@localhost:666/mydatabase</url>})
454+
end
455+
end
456+
457+
context 'with oracle db and not use oracle sid' do
292458
let(:params) do
293459
super().merge(
294460
db: 'oracle',
295-
dbport: 1522,
296461
dbserver: 'oracleserver',
297462
oracle_use_sid: false,
298463
dbname: 'mydatabase'
@@ -301,7 +466,61 @@ def self.clear_cache
301466

302467
it do
303468
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
304-
with_content(%r{jdbc:oracle:thin:@oracleserver:1522/mydatabase})
469+
with_content(%r{jdbc:oracle:thin:@oracleserver:1521/mydatabase})
470+
end
471+
end
472+
473+
context 'with h2 db and default database settings' do
474+
let(:params) do
475+
super().merge(
476+
db: 'h2'
477+
)
478+
end
479+
480+
it { is_expected.to compile.with_all_deps }
481+
482+
it { is_expected.to contain_file(FILENAME_SETENV_SH) }
483+
it { is_expected.to contain_file(FILENAME_USER_SH) }
484+
it { is_expected.to contain_file(FILENAME_SERVER_XML) }
485+
486+
it do
487+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
488+
with_content(%r{<database-type>h2</database-type>}).
489+
with_content(%r{<url>jdbc:h2:file://home/jira/database/jira</url>}).
490+
with_content(%r{<driver-class>org.h2.Driver</driver-class>}).
491+
without_content(%r{<validation-query>}).
492+
without_content(%r{<validation-query-timeout>}).
493+
without_content(%r{<connection-properties>})
494+
end
495+
end
496+
497+
context 'with h2 db and custom url' do
498+
let(:params) do
499+
super().merge(
500+
db: 'h2',
501+
dburl: 'jdbc:h2:file://home/jira/database/myjira'
502+
)
503+
end
504+
505+
it do
506+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
507+
with_content(%r{<url>jdbc:h2:file://home/jira/database/myjira</url>})
508+
end
509+
end
510+
511+
context 'with h2 db and custom url with dbname and dbserver' do
512+
let(:params) do
513+
super().merge(
514+
db: 'h2',
515+
dburl: 'jdbc:h2:file://var/opt/jira/database/jiradb',
516+
dbname: 'mydatabase',
517+
dbserver: 'myhost'
518+
)
519+
end
520+
521+
it do
522+
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
523+
with_content(%r{<url>jdbc:h2:file://var/opt/jira/database/jiradb</url>})
305524
end
306525
end
307526

@@ -445,19 +664,6 @@ def self.clear_cache
445664
end
446665
end
447666

448-
context 'custom dburl' do
449-
let(:params) do
450-
super().merge(
451-
dburl: 'my custom dburl'
452-
)
453-
end
454-
455-
it do
456-
is_expected.to contain_file(FILENAME_DBCONFIG_XML).
457-
with_content(%r{<url>my custom dburl</url>})
458-
end
459-
end
460-
461667
context 'customise tomcat connector' do
462668
let(:params) do
463669
super().merge(

0 commit comments

Comments
 (0)