(MODULES-2683) fix version compare to properly suppress show_diff for root password

This commit is contained in:
David Schmitt 2015-10-13 11:29:53 +01:00
parent 6527a3aa22
commit 5f49c45b2e
3 changed files with 28 additions and 4 deletions

View file

@ -35,7 +35,7 @@ class mysql::server::root_password {
}
# show_diff was added with puppet 3.0
if versioncmp($::puppetversion, '3.0') <= 0 {
if versioncmp($::puppetversion, '3.0') >= 0 {
File["${::root_home}/.my.cnf"] { show_diff => false }
}
if $mysql::server::create_root_user == true {

View file

@ -64,5 +64,21 @@ describe 'mysql class' do
apply_manifest(pp, :catch_changes => true)
end
end
end
describe 'when changing the password' do
let(:password) { 'THE NEW SECRET' }
let(:manifest) { "class { 'mysql::server': root_password => '#{password}' }" }
it 'should not display the password' do
result = apply_manifest(manifest, :expect_changes => true)
# this does not actually prove anything, as show_diff in the puppet config defaults to false.
expect(result.stdout).not_to match /#{password}/
end
it 'should be idempotent' do
result = apply_manifest(manifest, :catch_changes => true)
end
end
end

View file

@ -90,12 +90,20 @@ describe 'mysql::server' do
describe 'when root_password set' do
let(:params) {{:root_password => 'SET' }}
it { is_expected.to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
if Puppet.version.to_f >= 3.0
it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false).that_requires('Mysql_user[root@localhost]') }
else
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
end
end
describe 'when root_password set, create_root_user set to false' do
let(:params) {{ :root_password => 'SET', :create_root_user => false }}
it { is_expected.not_to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf') }
if Puppet.version.to_f >= 3.0
it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false) }
else
it { is_expected.to contain_file('/root/.my.cnf') }
end
end
describe 'when root_password set, create_root_my_cnf set to false' do
let(:params) {{ :root_password => 'SET', :create_root_my_cnf => false }}