Skip to content

Commit 9dca82e

Browse files
committed
Correct passing of object arguments
1 parent a307611 commit 9dca82e

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

modules/tester/manifests/config.pp

+37-17
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
11
# Tester extension for Chassis
22
class tester::config (
3-
$test_database = undef,
4-
$test_database_user = undef,
5-
$test_database_password = undef,
6-
$test_database_host = undef,
7-
$test_database_prefix = 'test_',
3+
$test_config = {},
4+
$ensure = present,
85
) {
9-
if ( ! empty( $::config[disabled_extensions] ) and 'chassis/tester' in $::config[disabled_extensions] ) {
10-
$file = absent
11-
} else {
12-
$file = present
6+
# If test DB configuration was provided, pull those values out.
7+
$test_database = $test_config[name] ? {
8+
/.*/ => $test_config[name],
9+
default => undef,
10+
}
11+
$test_database_user = $test_config[user] ? {
12+
/.*/ => $test_config[user],
13+
default => undef,
14+
}
15+
$test_database_password = $test_config[password] ? {
16+
/.*/ => $test_config[password],
17+
default => 'password',
18+
}
19+
$test_database_host = $test_config[host] ? {
20+
/.*/ => $test_config[host],
21+
default => 'localhost',
22+
}
23+
$test_database_prefix = $test_config[prefix] ? {
24+
/.*/ => $test_config[prefix],
25+
default => 'test_',
1326
}
1427

1528
file { '/vagrant/extensions/tester/wpdevel/wp-tests-config.php':
16-
ensure => $file,
29+
ensure => $ensure,
1730
content => template('tester/wp-tests-config.php.erb')
1831
}
1932

2033
file { '/etc/profile.d/tester-env.sh':
21-
ensure => $file,
34+
ensure => $ensure,
2235
content => template('tester/tester-env.sh.erb')
2336
}
2437

25-
if ( $file == absent or $test_database ) {
26-
file { '/vagrant/local-config-tester.php':
27-
ensure => $file,
28-
content => template('tester/local-config-tester.php.erb')
29-
}
38+
# Determine whether a DB configuration file should exist.
39+
if ( absent == $ensure ) {
40+
$db_config_file = absent
41+
} elsif ( empty( $test_database ) and empty( $test_database_user ) ) {
42+
$db_config_file = absent
43+
} else {
44+
$db_config_file = present
45+
}
46+
47+
file { '/vagrant/local-config-tester.php':
48+
ensure => $db_config_file,
49+
content => template('tester/local-config-tester.php.erb')
3050
}
3151

32-
if ( present == $file ) {
52+
if ( present == $ensure ) {
3353
exec { 'load_tester_envs':
3454
path => '/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin',
3555
command => "bash -c 'source /etc/profile.d/tester-env.sh'",

modules/tester/manifests/init.pp

+3-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
}
2929
}
3030

31-
# Invoke even if tester is disabled in order to clean up templated files.
31+
# Invoke even if tester is disabled, in order to clean up templated files.
3232
class { 'tester::config':
33-
test_database => $config[tester_db][name],
34-
test_database_user => $config[tester_db][user],
35-
test_database_password => $config[tester_db][password],
36-
test_database_host => $config[tester_db][host],
33+
test_config => $config[tester_db],
34+
ensure => $tester,
3735
}
3836
}

0 commit comments

Comments
 (0)