diff --git a/spec/classes/mysql_bindings_java_spec.rb b/spec/classes/mysql_bindings_java_spec.rb deleted file mode 100644 index 2c8b17a..0000000 --- a/spec/classes/mysql_bindings_java_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe 'mysql::bindings::java' do - - describe 'on a debian based os' do - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - it { should contain_package('mysql-connector-java').with( - :name => 'libmysql-java', - :ensure => 'present' - )} - end - - describe 'on a freebsd based os' do - let :facts do - { :osfamily => 'FreeBSD', :root_home => '/root'} - end - it { should contain_package('mysql-connector-java').with( - :name => 'databases/mysql-connector-java', - :ensure => 'present' - )} - end - - describe 'on a redhat based os' do - let :facts do - {:osfamily => 'RedHat', :root_home => '/root'} - end - it { should contain_package('mysql-connector-java').with( - :name => 'mysql-connector-java', - :ensure => 'present' - )} - describe 'when parameters are supplied' do - let :params do - {:package_ensure => 'latest', :package_name => 'java-mysql'} - end - it { should contain_package('mysql-connector-java').with( - :name => 'java-mysql', - :ensure => 'latest' - )} - end - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported osfamily: foo/) - end - end - -end diff --git a/spec/classes/mysql_bindings_perl_spec.rb b/spec/classes/mysql_bindings_perl_spec.rb deleted file mode 100644 index b94c7ae..0000000 --- a/spec/classes/mysql_bindings_perl_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'spec_helper' - -describe 'mysql::bindings::perl' do - - describe 'on a debian based os' do - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - it { should contain_package('perl_mysql').with( - :name => 'libdbd-mysql-perl', - :ensure => 'present', - :provider => '' - )} - end - - describe 'on a freebsd based os' do - let :facts do - { :osfamily => 'FreeBSD', :root_home => '/root'} - end - it { should contain_package('perl_mysql').with( - :name => 'p5-DBD-mysql', - :ensure => 'present', - :provider => '' - )} - end - - describe 'on a redhat based os' do - let :facts do - {:osfamily => 'Redhat', :root_home => '/root'} - end - it { should contain_package('perl_mysql').with( - :name => 'perl-DBD-MySQL', - :ensure => 'present', - :provider => '' - )} - describe 'when parameters are supplied' do - let :params do - {:package_ensure => 'latest', - :package_provider => 'zypper', - :package_name => 'mysql_perl'} - end - it { should contain_package('perl_mysql').with( - :name => 'mysql_perl', - :ensure => 'latest', - :provider => 'zypper' - )} - end - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported osfamily: foo/) - end - end - -end diff --git a/spec/classes/mysql_bindings_python_spec.rb b/spec/classes/mysql_bindings_python_spec.rb deleted file mode 100644 index 6d5cfc3..0000000 --- a/spec/classes/mysql_bindings_python_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe 'mysql::bindings::python' do - - describe 'on a debian based os' do - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - it { should contain_package('python-mysqldb').with( - :name => 'python-mysqldb', - :ensure => 'present' - )} - end - - describe 'on a freebsd based os' do - let :facts do - { :osfamily => 'FreeBSD', :root_home => '/root'} - end - it { should contain_package('python-mysqldb').with( - :name => 'databases/py-MySQLdb', - :ensure => 'present' - )} - end - - describe 'on a redhat based os' do - let :facts do - {:osfamily => 'RedHat', :root_home => '/root'} - end - it { should contain_package('python-mysqldb').with( - :name => 'MySQL-python', - :ensure => 'present' - )} - describe 'when parameters are supplied' do - let :params do - {:package_ensure => 'latest', :package_name => 'python-mysql'} - end - it { should contain_package('python-mysqldb').with( - :name => 'python-mysql', - :ensure => 'latest' - )} - end - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported osfamily: foo/) - end - end - -end diff --git a/spec/classes/mysql_bindings_ruby_spec.rb b/spec/classes/mysql_bindings_ruby_spec.rb deleted file mode 100644 index c16947f..0000000 --- a/spec/classes/mysql_bindings_ruby_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'spec_helper' - -describe 'mysql::bindings::ruby' do - - describe 'on a debian based os' do - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - it { should contain_package('ruby_mysql').with( - :name => 'libmysql-ruby', - :ensure => 'present', - :provider => '' - )} - end - - describe 'on a freebsd based os' do - let :facts do - { :osfamily => 'FreeBSD', :root_home => '/root'} - end - it { should contain_package('ruby_mysql').with( - :name => 'ruby-mysql', - :ensure => 'present', - :provider => 'gem' - )} - end - - describe 'on a redhat based os' do - let :facts do - {:osfamily => 'RedHat', :root_home => '/root'} - end - it { should contain_package('ruby_mysql').with( - :name => 'ruby-mysql', - :ensure => 'present', - :provider => 'gem' - )} - describe 'when parameters are supplied' do - let :params do - {:package_ensure => 'latest', - :package_provider => 'zypper', - :package_name => 'mysql_ruby'} - end - it { should contain_package('ruby_mysql').with( - :name => 'mysql_ruby', - :ensure => 'latest', - :provider => 'zypper' - )} - end - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported osfamily: foo/) - end - end - -end diff --git a/spec/classes/mysql_bindings_spec.rb b/spec/classes/mysql_bindings_spec.rb new file mode 100644 index 0000000..19b093d --- /dev/null +++ b/spec/classes/mysql_bindings_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'mysql::bindings' do + let(:params) {{ + 'java_enable' => true, + 'perl_enable' => true, + 'php_enable' => true, + 'python_enable' => true, + 'ruby_enable' => true, + }} + + shared_examples 'bindings' do |osfamily, operatingsystem, java_name, perl_name, php_name, python_name, ruby_name| + let :facts do + { :osfamily => osfamily, :operatingsystem => operatingsystem, :root_home => '/root'} + end + it { should contain_package('mysql-connector-java').with( + :name => java_name, + :ensure => 'present' + )} + it { should contain_package('perl_mysql').with( + :name => perl_name, + :ensure => 'present', + )} + it { should contain_package('python-mysqldb').with( + :name => python_name, + :ensure => 'present' + )} + it { should contain_package('ruby_mysql').with( + :name => ruby_name, + :ensure => 'present', + )} + end + + context 'Debian' do + it_behaves_like 'bindings', 'Debian', 'Debian', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby' + it_behaves_like 'bindings', 'Debian', 'Ubuntu', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby' + end + + context 'freebsd' do + it_behaves_like 'bindings', 'FreeBSD', 'FreeBSD', 'databases/mysql-connector-java', 'p5-DBD-mysql', 'databases/php5-mysql', 'databases/py-MySQLdb', 'databases/ruby-mysql' + end + + context 'redhat' do + it_behaves_like 'bindings', 'RedHat', 'RedHat', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql' + it_behaves_like 'bindings', 'RedHat', 'OpenSuSE', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql' + end + + describe 'on any other os' do + let :facts do + {:osfamily => 'foo', :root_home => '/root'} + end + + it 'should fail' do + expect { subject }.to raise_error(/Unsupported osfamily: foo/) + end + end + +end diff --git a/spec/classes/mysql_client_spec.rb b/spec/classes/mysql_client_spec.rb new file mode 100644 index 0000000..d7386d1 --- /dev/null +++ b/spec/classes/mysql_client_spec.rb @@ -0,0 +1,16 @@ +describe 'mysql::client' do + let(:facts) {{ :osfamily => 'RedHat' }} + + context 'with defaults' do + it { should_not contain_class('mysql::bindings') } + it { should contain_package('mysql_client') } + end + + context 'with bindings enabled' do + let(:params) {{ :bindings_enable => true }} + + it { should contain_class('mysql::bindings') } + it { should contain_package('mysql_client') } + end + +end diff --git a/spec/classes/mysql_config_spec.rb b/spec/classes/mysql_config_spec.rb deleted file mode 100644 index 7ca556b..0000000 --- a/spec/classes/mysql_config_spec.rb +++ /dev/null @@ -1,348 +0,0 @@ -require 'spec_helper' -describe 'mysql::config' do - - let :constant_parameter_defaults do - { - :root_password => 'UNSET', - :old_root_password => '', - :max_connections => '151', - :bind_address => '127.0.0.1', - :port => '3306', - :etc_root_password => false, - :datadir => '/var/lib/mysql', - :default_engine => 'UNSET', - :ssl => false, - :key_buffer => '16M', - :max_allowed_packet => '16M', - :thread_stack => '256K', - :thread_cache_size => 8, - :myisam_recover => 'BACKUP', - :query_cache_limit => '1M', - :query_cache_size => '16M', - :max_binlog_size => '100M', - :expire_logs_days => 10, - :character_set => 'UNSET', - :tmp_table_size => 'UNSET', - :max_heap_table_size => 'UNSET', - :table_open_cache => 'UNSET', - :long_query_time => 'UNSET', - :server_id => 'UNSET', - :sql_log_bin => 'UNSET', - :log_bin => 'UNSET', - :binlog_do_db => 'UNSET', - :log_bin_trust_function_creators => 'UNSET', - :replicate_ignore_table => 'UNSET', - :replicate_wild_do_table => 'UNSET', - :replicate_wild_ignore_table => 'UNSET', - :ft_min_word_len => 'UNSET', - :ft_max_word_len => 'UNSET' - } - end - - describe 'with osfamily specific defaults' do - { - 'Debian' => { - :datadir => '/var/lib/mysql', - :service_name => 'mysql', - :config_file => '/etc/mysql/my.cnf', - :socket => '/var/run/mysqld/mysqld.sock', - :pidfile => '/var/run/mysqld/mysqld.pid', - :root_group => 'root', - :ssl_ca => '/etc/mysql/cacert.pem', - :ssl_cert => '/etc/mysql/server-cert.pem', - :ssl_key => '/etc/mysql/server-key.pem' - }, - 'FreeBSD' => { - :datadir => '/var/db/mysql', - :service_name => 'mysql-server', - :config_file => '/var/db/mysql/my.cnf', - :socket => '/tmp/mysql.sock', - :pidfile => '/var/db/mysql/mysql.pid', - :root_group => 'wheel' - }, - 'RedHat' => { - :datadir => '/var/lib/mysql', - :service_name => 'mysqld', - :config_file => '/etc/my.cnf', - :socket => '/var/lib/mysql/mysql.sock', - :pidfile => '/var/run/mysqld/mysqld.pid', - :root_group => 'root', - :ssl_ca => '/etc/mysql/cacert.pem', - :ssl_cert => '/etc/mysql/server-cert.pem', - :ssl_key => '/etc/mysql/server-key.pem' - } - }.each do |osfamily, osparams| - - - describe "when osfamily is #{osfamily}" do - - let :facts do - {:osfamily => osfamily, :root_home => '/root'} - end - - describe 'when config file should be managed' do - let :params do - {:manage_config_file => true} - end - - it { should contain_file(osparams[:config_file]) } - end - - describe 'when config file should not be managed' do - let :params do - {:manage_config_file => false} - end - - it { should_not contain_file(osparams[:config_file]) } - 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 -p\'foo\' status > /dev/null", - 'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin' - )} - - it { should contain_file('/root/.my.cnf').with( - 'content' => "[client]\nuser=root\nhost=localhost\npassword='foo'\nsocket=#{osparams[:socket]}", - '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 -p\'bar\' password \'foo\'', - 'logoutput' => true, - 'unless' => "mysqladmin -u root -p\'foo\' status > /dev/null", - 'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin' - )} - - end - - [ - {}, - { - :service_name => 'dans_service', - :config_file => '/home/dan/mysql.conf', - :pidfile => '/home/dan/mysql.pid', - :socket => '/home/dan/mysql.sock', - :bind_address => '0.0.0.0', - :port => '3306', - :datadir => '/path/to/datadir', - :default_engine => 'InnoDB', - :ssl => true, - :ssl_ca => '/path/to/cacert.pem', - :ssl_cert => '/path/to/server-cert.pem', - :ssl_key => '/path/to/server-key.pem', - :key_buffer => '16M', - :max_allowed_packet => '32M', - :thread_stack => '256K', - :query_cache_size => '16M', - :character_set => 'utf8', - :max_connections => 1000, - :tmp_table_size => '4096M', - :max_heap_table_size => '4096M', - :table_open_cache => 2048, - :long_query_time => 0.5, - :ft_min_word_len => 3, - :ft_max_word_len => 10 - } - ].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/:/usr/bin/:/bin/', - :command => "service #{param_values[:service_name]} restart" - )} - - it { should_not contain_exec('set_mysql_rootpw') } - - it { should contain_file('/root/.my.cnf')} - - it { should contain_file('/etc/mysql').with( - 'owner' => 'root', - 'group' => param_values[:root_group], - 'notify' => 'Exec[mysqld-restart]', - 'ensure' => 'directory', - 'mode' => '0755' - )} - it { should contain_file('/etc/mysql/conf.d').with( - 'owner' => 'root', - 'group' => param_values[:root_group], - 'notify' => 'Exec[mysqld-restart]', - 'ensure' => 'directory', - 'mode' => '0755' - )} - it { should contain_file(param_values[:config_file]).with( - 'owner' => 'root', - 'group' => param_values[:root_group], - '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]}", - "pid-file = #{param_values[:pidfile]}", - "datadir = #{param_values[:datadir]}", - "max_connections = #{param_values[:max_connections]}", - "bind-address = #{param_values[:bind_address]}", - "key_buffer = #{param_values[:key_buffer]}", - "max_allowed_packet = #{param_values[:max_allowed_packet]}", - "thread_stack = #{param_values[:thread_stack]}", - "thread_cache_size = #{param_values[:thread_cache_size]}", - "myisam-recover = #{param_values[:myisam_recover]}", - "query_cache_limit = #{param_values[:query_cache_limit]}", - "query_cache_size = #{param_values[:query_cache_size]}", - "expire_logs_days = #{param_values[:expire_logs_days]}", - "max_binlog_size = #{param_values[:max_binlog_size]}" - ] - if param_values[:tmp_table_size] != 'UNSET' - expected_lines = expected_lines | [ "tmp_table_size = #{param_values[:tmp_table_size]}" ] - end - if param_values[:max_heap_table_size] != 'UNSET' - expected_lines = expected_lines | [ "max_heap_table_size = #{param_values[:max_heap_table_size]}" ] - end - if param_values[:table_open_cache] != 'UNSET' - expected_lines = expected_lines | [ "table_open_cache = #{param_values[:table_open_cache]}" ] - end - if param_values[:long_query_time] != 'UNSET' - expected_lines = expected_lines | [ "long_query_time = #{param_values[:long_query_time]}" ] - end - if param_values[:ft_min_word_len] != 'UNSET' - expected_lines = expected_lines | [ "ft_min_word_len = #{param_values[:ft_min_word_len]}" ] - end - if param_values[:ft_max_word_len] != 'UNSET' - expected_lines = expected_lines | [ "ft_max_word_len = #{param_values[:ft_max_word_len]}" ] - end - if param_values[:default_engine] != 'UNSET' - expected_lines = expected_lines | [ "default-storage-engine = #{param_values[:default_engine]}" ] - else - content.should_not match(/^default-storage-engine = /) - end - if param_values[:character_set] != 'UNSET' - expected_lines = expected_lines | [ "character-set-server = #{param_values[:character_set]}" ] - end - if param_values[:sql_log_bin] != 'UNSET' - expected_lines = expected_lines | [ "sql_log_bin = #{param_values[:sql_log_bin]}" ] - end - if param_values[:log_bin] != 'UNSET' - expected_lines = expected_lines | [ "log-bin = #{param_values[:log_bin]}" ] - end - if param_values[:binlog_do_db] != 'UNSET' - expected_lines = expected_lines | [ "binlog-do-db = #{param_values[:binlog_do_db]}" ] - end - if param_values[:log_bin_trust_function_creators] != 'UNSET' - expected_lines = expected_lines | [ "log_bin_trust_function_creators = #{param_values[:log_bin_trust_function_creators]}" ] - end - if param_values[:replicate_ignore_table] != 'UNSET' - expected_lines = expected_lines | [ "replicate-ignore-table = #{param_values[:replicate_ignore_table]}" ] - end - if param_values[:replicate_wild_do_table] != 'UNSET' - expected_lines = expected_lines | [ "replicate-wild-do-table = #{param_values[:replicate_wild_do_table]}" ] - end - if param_values[:replicate_wild_ignore_table] != 'UNSET' - expected_lines = expected_lines | [ "replicate-wild-ignore-table = #{param_values[:replicate_wild_ignore_table]}" ] - end - if param_values[:ssl] - expected_lines = expected_lines | - [ - "ssl-ca = #{param_values[:ssl_ca]}", - "ssl-cert = #{param_values[:ssl_cert]}", - "ssl-key = #{param_values[:ssl_key]}" - ] - end - (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', :root_home => '/root'} - end - - let :params do - { - :root_password => 'foo', - :old_root_password => 'bar', - :etc_root_password => true, - :socket => '/tmp/mysql.sock', - } - end - - it { should contain_exec('set_mysql_rootpw').with( - 'command' => 'mysqladmin -u root -p\'bar\' password \'foo\'', - 'logoutput' => true, - 'unless' => "mysqladmin -u root -p\'foo\' status > /dev/null", - 'path' => '/usr/local/sbin:/usr/bin:/usr/local/bin' - )} - - it { should contain_file('/root/.my.cnf').with( - 'content' => "[client]\nuser=root\nhost=localhost\npassword='foo'\nsocket=#{params[:socket]}", - 'require' => 'Exec[set_mysql_rootpw]' - )} - - end - - describe 'setting etc_root_password should fail on redhat' do - let :facts do - {:osfamily => 'RedHat', :root_home => '/root'} - end - - let :params do - {:root_password => 'foo', :old_root_password => 'bar', :etc_root_password => true} - end - - it 'should fail' do - expect { subject }.to raise_error(Puppet::Error, /Duplicate (declaration|definition)/) - end - - end - - describe 'unset ssl params should fail when ssl is true on freebsd' do - let :facts do - {:osfamily => 'FreeBSD', :root_home => '/root'} - end - - let :params do - { :ssl => true } - end - - it 'should fail' do - expect { subject }.to raise_error(Puppet::Error, /required when ssl is true/) - end - - end - -end diff --git a/spec/classes/mysql_init_spec.rb b/spec/classes/mysql_init_spec.rb deleted file mode 100644 index 3e94b32..0000000 --- a/spec/classes/mysql_init_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe 'mysql' do - - describe 'on a debian based os' do - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - it { should contain_package('mysql_client').with( - :name => 'mysql-client', - :ensure => 'present' - )} - end - - describe 'on a freebsd based os' do - let :facts do - { :osfamily => 'FreeBSD', :root_home => '/root'} - end - it { should contain_package('mysql_client').with( - :name => 'databases/mysql55-client', - :ensure => 'present' - )} - end - - describe 'on a redhat based os' do - let :facts do - {:osfamily => 'RedHat', :root_home => '/root'} - end - it { should contain_package('mysql_client').with( - :name => 'mysql', - :ensure => 'present' - )} - describe 'when parameters are supplied' do - let :params do - {:client_package_ensure => 'latest', :client_package_name => 'mysql_client'} - end - it { should contain_package('mysql_client').with( - :name => 'mysql_client', - :ensure => 'latest' - )} - end - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported osfamily: foo/) - end - end - -end diff --git a/spec/classes/mysql_php_spec.rb b/spec/classes/mysql_php_spec.rb deleted file mode 100644 index 2279968..0000000 --- a/spec/classes/mysql_php_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe 'mysql::php' do - - describe 'on a debian based os' do - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - it { should contain_package('php-mysql').with( - :name => 'php5-mysql', - :ensure => 'present' - )} - end - - describe 'on a freebsd based os' do - let :facts do - { :osfamily => 'FreeBSD', :root_home => '/root'} - end - it { should contain_package('php-mysql').with( - :name => 'php5-mysql', - :ensure => 'present' - )} - end - - describe 'on a redhat based os' do - let :facts do - {:osfamily => 'Redhat', :root_home => '/root'} - end - it { should contain_package('php-mysql').with( - :name => 'php-mysql', - :ensure => 'present' - )} - describe 'when parameters are supplied' do - let :params do - {:package_ensure => 'latest', :package_name => 'php53-mysql'} - end - it { should contain_package('php-mysql').with( - :name => 'php53-mysql', - :ensure => 'latest' - )} - end - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported osfamily: foo/) - end - end - -end diff --git a/spec/classes/mysql_backup_spec.rb b/spec/classes/mysql_server_backup_spec.rb similarity index 98% rename from spec/classes/mysql_backup_spec.rb rename to spec/classes/mysql_server_backup_spec.rb index 80b7493..e0fa360 100644 --- a/spec/classes/mysql_backup_spec.rb +++ b/spec/classes/mysql_server_backup_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'mysql::backup' do +describe 'mysql::server::backup' do let(:default_params) { { 'backupuser' => 'testuser', diff --git a/spec/classes/mysql_server_mysqltuner_spec.rb b/spec/classes/mysql_server_mysqltuner_spec.rb new file mode 100644 index 0000000..7e9499a --- /dev/null +++ b/spec/classes/mysql_server_mysqltuner_spec.rb @@ -0,0 +1,5 @@ +describe 'mysql::server::mysqltuner' do + + it { should contain_file('/usr/local/bin/mysqltuner') } + +end diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index cb3055b..eae72e7 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -1,99 +1,78 @@ require 'spec_helper' describe 'mysql::server' do + let(:facts) {{:osfamily => 'RedHat', :root_home => '/root'}} - let :constant_parameter_defaults do - {:config_hash => {}, - :package_ensure => 'present', - :enabled => true, - :manage_service => true - } + context 'with defaults' do + it { should contain_class('mysql::server::install') } + it { should contain_class('mysql::server::config') } + it { should contain_class('mysql::server::service') } + it { should contain_class('mysql::server::root_password') } end - describe 'when ubuntu use upstart' do - let :facts do - { :osfamily => 'Debian', - :operatingsystem => 'Ubuntu', - :root_home => '/root' - } + context 'with remove_default_accounts set' do + let (:params) {{ :remove_default_accounts => true }} + it { should contain_class('mysql::server::account_security') } + end + + context 'mysql::server::install' do + let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }} + it do + should contain_package('mysql-server').with({ + :ensure => :present, + :name => 'mysql-server', + }) + end + end + + context 'mysql::server::config' do + it do + should contain_file('/etc/mysql').with({ + :ensure => :directory, + :mode => '0755', + }) end - it { should contain_service('mysqld').with( - :name => 'mysql', - :ensure => 'running', - :enable => 'true', - :provider => 'upstart', - :require => 'Package[mysql-server]' - )} + it do + should contain_file('/etc/mysql/conf.d').with({ + :ensure => :directory, + :mode => '0755', + }) + end + + it do + should contain_file('/etc/my.cnf').with({ + :mode => '0644', + }) + end end - describe 'with osfamily specific defaults' do - { - 'Debian' => { - :service_name => 'mysql', - :package_name => 'mysql-server' - }, - 'FreeBSD' => { - :service_name => 'mysql-server', - :package_name => 'databases/mysql55-server' - }, - 'RedHat' => { - :service_name => 'mysqld', - :package_name => 'mysql-server' - } - }.each do |osfamily, osparams| + context 'mysql::server::service' do + context 'with defaults' do + it { should contain_service('mysqld') } + end - describe "when osfamily is #{osfamily}" do + context 'service_enabled set to false' do + let(:params) {{ :service_enabled => false }} - let :facts do - { :osfamily => osfamily, :root_home => '/root' } - end - - [ - {}, - { - :package_name => 'dans_package', - :package_ensure => 'latest', - :service_name => 'dans_service', - :config_hash => {'root_password' => 'foo'}, - :enabled => false, - :manage_service => false - } - ].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_package('mysql-server').with( - :name => param_values[:package_name], - :ensure => param_values[:package_ensure] - )} - - it { - if param_values[:manage_service] - should contain_service('mysqld').with( - :name => param_values[:service_name], - :ensure => param_values[:enabled] ? 'running' : 'stopped', - :enable => param_values[:enabled], - :require => 'Package[mysql-server]' - ).without_provider - else - should_not contain_service('mysqld') - end - } - end - end + it do + should contain_service('mysqld').with({ + :ensure => :stopped + }) end end end + + context 'mysql::server::root_password' do + describe 'when defaults' do + it { should_not contain_mysql_user('root@localhost') } + it { should_not contain_file('/root/.my.cnf') } + end + describe 'when set' do + let(:params) {{:root_password => 'SET' }} + it { should contain_mysql_user('root@localhost') } + it { should contain_file('/root/.my.cnf') } + end + + end + end diff --git a/spec/defines/mysql_db_spec.rb b/spec/defines/mysql_db_spec.rb index 328ae21..a7ee31f 100644 --- a/spec/defines/mysql_db_spec.rb +++ b/spec/defines/mysql_db_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'mysql::db', :type => :define do + let(:facts) {{ :osfamily => 'RedHat' }} let(:title) { 'test_db' } let(:params) { @@ -11,7 +12,7 @@ describe 'mysql::db', :type => :define do it 'should report an error when ensure is not present or absent' do params.merge!({'ensure' => 'invalid_val'}) - expect { subject }.to raise_error(Puppet::Error, + expect { subject }.to raise_error(Puppet::Error, /invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./) end diff --git a/spec/defines/mysql_server_config_spec.rb b/spec/defines/mysql_server_config_spec.rb deleted file mode 100644 index 0fd9ea4..0000000 --- a/spec/defines/mysql_server_config_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'spec_helper' - -describe 'mysql::server::config', :type => :define do - filename = '/etc/mysql/conf.d/test_config.cnf' - - let :facts do - { :osfamily => 'Debian', :root_home => '/root'} - end - - let(:title) { File.basename(filename, '.cnf') } - - let(:params) { - { 'settings' => { - 'mysqld' => { - 'bind-address' => '0.0.0.0' - } - } - } - } - - it 'should notify the mysql daemon' do - should contain_file(filename).with_notify('Exec[mysqld-restart]') - end - - it 'should contain config parameter in content' do - should contain_file(filename).with_content("### MANAGED BY PUPPET ###\n[mysqld]\nbind-address = 0.0.0.0\n\n") - end - - it 'should not notify the mysql daemon' do - params.merge!({ 'notify_service' => false }) - should contain_file(filename).without_notify - end - - it 'should require on the mysql-server package' do - should contain_file(filename).with_require('Package[mysql-server]') - end -end diff --git a/spec/system/mysql_account_delete_spec.rb b/spec/system/mysql_account_delete_spec.rb new file mode 100644 index 0000000..11f776a --- /dev/null +++ b/spec/system/mysql_account_delete_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_system' + +describe 'mysql::server::account_security class' do + + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': remove_default_accounts => true } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + + describe 'accounts' do + it 'should delete accounts' do + shell("mysql -e 'show grants for root@127.0.01;'") do |s| + s.exit_code.should == 1 + end + end + + it 'should delete databases' do + shell("mysql -e 'show databases;' |grep test") do |s| + s.exit_code.should == 1 + end + end + end + end + +end diff --git a/spec/system/mysql_backup_spec.rb b/spec/system/mysql_backup_spec.rb index 831b6bd..bab3fa1 100644 --- a/spec/system/mysql_backup_spec.rb +++ b/spec/system/mysql_backup_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_system' -describe 'mysql::backup class' do +describe 'mysql::server::backup class' do context 'should work with no errors' do pp = <<-EOS class { 'mysql::globals': override_options => { 'root_password' => 'password' } } @@ -10,7 +10,7 @@ describe 'mysql::backup class' do password => 'secret', } - class { 'mysql::backup': + class { 'mysql::server::backup': backupuser => 'myuser', backuppassword => 'mypassword', backupdir => '/tmp/backups', @@ -50,7 +50,7 @@ describe 'mysql::backup class' do password => 'secret', } - class { 'mysql::backup': + class { 'mysql::server::backup': backupuser => 'myuser', backuppassword => 'mypassword', backupdir => '/tmp/backups', diff --git a/spec/system/mysql_db_spec.rb b/spec/system/mysql_db_spec.rb index 0349f4d..2e7ffa1 100644 --- a/spec/system/mysql_db_spec.rb +++ b/spec/system/mysql_db_spec.rb @@ -8,7 +8,7 @@ describe 'mysql::db define' do class { 'mysql::globals': override_options => { 'root_password' => 'password' } } class { 'mysql::server': } mysql::db { 'spec1': - user => 'root', + user => 'root1', password => 'password', } EOS @@ -40,7 +40,7 @@ describe 'mysql::db define' do before => Mysql::Db['spec2'], } mysql::db { 'spec2': - user => 'root', + user => 'root1', password => 'password', sql => '/tmp/spec.sql', } diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index 360c924..f9ba34a 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -83,13 +83,6 @@ usvn_user@localhost end end - describe 'flush' do - it 'removes cached privileges' do - provider.expects(:mysql).with([defaults_file, '-NBe', 'FLUSH PRIVILEGES']) - provider.flush - end - end - describe 'self.defaults_file' do it 'sets --defaults-file' do File.stubs(:file?).with('/root/.my.cnf').returns(true)