Merge pull request #46 from bodepd/add_rspec_tests_for_config_class
Add rspec tests for config class
This commit is contained in:
commit
812ba01509
3 changed files with 181 additions and 2 deletions
|
@ -35,8 +35,6 @@ class mysql::config(
|
|||
$socket = $mysql::params::socket
|
||||
) inherits mysql::params {
|
||||
|
||||
Class['mysql::server'] -> Class['mysql::config']
|
||||
|
||||
File {
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
|
|
|
@ -21,6 +21,8 @@ class mysql::server (
|
|||
$config_hash = {}
|
||||
) inherits mysql::params {
|
||||
|
||||
Class['mysql::server'] -> Class['mysql::config']
|
||||
|
||||
create_resources( 'class', {'mysql::config' => $config_hash} )
|
||||
|
||||
package { 'mysql-server':
|
||||
|
|
179
spec/classes/mysql_config_spec.rb
Normal file
179
spec/classes/mysql_config_spec.rb
Normal file
|
@ -0,0 +1,179 @@
|
|||
require 'spec_helper'
|
||||
describe 'mysql::config' do
|
||||
|
||||
let :constant_parameter_defaults do
|
||||
{:root_password => 'UNSET',
|
||||
:old_root_password => '',
|
||||
:bind_address => '127.0.0.1',
|
||||
:port => '3306',
|
||||
:etc_root_password => false}
|
||||
end
|
||||
|
||||
describe 'with osfamily specific defaults' do
|
||||
{
|
||||
'Debian' => {
|
||||
:service_name => 'mysql',
|
||||
:config_file => '/etc/mysql/my.cnf',
|
||||
:socket => '/var/run/mysqld/mysqld.sock'
|
||||
},
|
||||
'Redhat' => {
|
||||
:service_name => 'mysqld',
|
||||
:config_file => '/etc/my.cnf',
|
||||
:socket => '/var/lib/mysql/mysql.sock'
|
||||
}
|
||||
}.each do |osfamily, osparams|
|
||||
|
||||
|
||||
describe "when osfamily is #{osfamily}" do
|
||||
|
||||
let :facts do
|
||||
{:osfamily => osfamily}
|
||||
end
|
||||
|
||||
describe 'when root password is set' do
|
||||
|
||||
let :params do
|
||||
{:root_password => 'foo'}
|
||||
end
|
||||
|
||||
it { should contain_exec('set_mysql_rootpw').with(
|
||||
'command' => 'mysqladmin -u root password foo',
|
||||
'logoutput' => true,
|
||||
'unless' => "mysqladmin -u root -pfoo status > /dev/null",
|
||||
'path' => '/usr/local/sbin:/usr/bin'
|
||||
)}
|
||||
|
||||
it { should contain_file('/root/.my.cnf').with(
|
||||
'content' => "[client]\nuser=root\nhost=localhost\npassword=foo\n",
|
||||
'require' => 'Exec[set_mysql_rootpw]'
|
||||
)}
|
||||
|
||||
end
|
||||
|
||||
describe 'when root password and old password are set' do
|
||||
let :params do
|
||||
{:root_password => 'foo', :old_root_password => 'bar'}
|
||||
end
|
||||
|
||||
it { should contain_exec('set_mysql_rootpw').with(
|
||||
'command' => 'mysqladmin -u root -pbar password foo',
|
||||
'logoutput' => true,
|
||||
'unless' => "mysqladmin -u root -pfoo status > /dev/null",
|
||||
'path' => '/usr/local/sbin:/usr/bin'
|
||||
)}
|
||||
|
||||
end
|
||||
|
||||
[
|
||||
{},
|
||||
{
|
||||
:service_name => 'dans_service',
|
||||
:config_file => '/home/dan/mysql.conf',
|
||||
:service_name => 'dans_mysql',
|
||||
:socket => '/home/dan/mysql.sock',
|
||||
:bind_address => '0.0.0.0',
|
||||
:port => '3306'
|
||||
}
|
||||
].each do |passed_params|
|
||||
|
||||
describe "with #{passed_params == {} ? 'default' : 'specified'} parameters" do
|
||||
|
||||
let :parameter_defaults do
|
||||
constant_parameter_defaults.merge(osparams)
|
||||
end
|
||||
|
||||
let :params do
|
||||
passed_params
|
||||
end
|
||||
|
||||
let :param_values do
|
||||
parameter_defaults.merge(params)
|
||||
end
|
||||
|
||||
it { should contain_exec('mysqld-restart').with(
|
||||
:refreshonly => true,
|
||||
:path => '/sbin/:/usr/sbin/',
|
||||
:command => "service #{param_values[:service_name]} restart"
|
||||
)}
|
||||
|
||||
it { should_not contain_exec('set_mysql_rootpw') }
|
||||
|
||||
it { should_not contain_file('/root/.my.cnf')}
|
||||
|
||||
it { should contain_file('/etc/mysql').with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'notify' => 'Exec[mysqld-restart]',
|
||||
'ensure' => 'directory',
|
||||
'mode' => '0755'
|
||||
)}
|
||||
it { should contain_file('/etc/mysql/conf.d').with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'notify' => 'Exec[mysqld-restart]',
|
||||
'ensure' => 'directory',
|
||||
'mode' => '0755'
|
||||
)}
|
||||
it { should contain_file(param_values[:config_file]).with(
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'notify' => 'Exec[mysqld-restart]',
|
||||
'mode' => '0644'
|
||||
)}
|
||||
it 'should have a template with the correct contents' do
|
||||
content = param_value(subject, 'file', param_values[:config_file], 'content')
|
||||
expected_lines = [
|
||||
"port = #{param_values[:port]}",
|
||||
"socket = #{param_values[:socket]}",
|
||||
"bind-address = #{param_values[:bind_address]}"
|
||||
]
|
||||
(content.split("\n") & expected_lines).should == expected_lines
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when etc_root_password is set with password' do
|
||||
|
||||
let :facts do
|
||||
{:osfamily => 'Debian'}
|
||||
end
|
||||
|
||||
let :params do
|
||||
{:root_password => 'foo', :old_root_password => 'bar', :etc_root_password => true}
|
||||
end
|
||||
|
||||
it { should contain_exec('set_mysql_rootpw').with(
|
||||
'command' => 'mysqladmin -u root -pbar password foo',
|
||||
'logoutput' => true,
|
||||
'unless' => "mysqladmin -u root -pfoo status > /dev/null",
|
||||
'path' => '/usr/local/sbin:/usr/bin'
|
||||
)}
|
||||
|
||||
it { should contain_file('/root/.my.cnf').with(
|
||||
'content' => "[client]\nuser=root\nhost=localhost\npassword=foo\n",
|
||||
'require' => 'Exec[set_mysql_rootpw]'
|
||||
)}
|
||||
|
||||
end
|
||||
|
||||
describe 'setting etc_root_password should fail on redhat' do
|
||||
let :facts do
|
||||
{:osfamily => 'Redhat'}
|
||||
end
|
||||
|
||||
let :params do
|
||||
{:root_password => 'foo', :old_root_password => 'bar', :etc_root_password => true}
|
||||
end
|
||||
|
||||
it 'should fail' do
|
||||
expect do
|
||||
subject
|
||||
end.should raise_error(Puppet::Error, /Duplicate declaration/)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue