Skip to content

Commit

Permalink
Split out the template tests and rework both sets of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Penney committed Aug 14, 2014
1 parent d564793 commit 9cb685d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 108 deletions.
78 changes: 78 additions & 0 deletions spec/classes/mycnf_template_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require 'spec_helper'

describe 'mysql::server' do
context 'my.cnf template' do
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }

context 'normal entry' do
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
it do
is_expected.to contain_file('mysql-config-file').with({
:mode => '0644',
}).with_content(/socket = \/var\/lib\/mysql\/mysql.sock/)
end
end

describe 'array entry' do
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } }}}
it do
is_expected.to contain_file('mysql-config-file').with_content(
/.*replicate-do-db = base1\nreplicate-do-db = base2.*/
)
end
end

describe 'ssl set to true' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl/) }
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
end

describe 'ssl set to false' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => false }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl = false/) }
end

# ssl-disable (and ssl) are special cased within mysql.
describe 'possibility of disabling ssl completely' do
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true }}}}
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
end

describe 'a non ssl option set to true' do
let(:params) {{ :override_options => { 'mysqld' => { 'test' => true }}}}
it { is_expected.to contain_file('mysql-config-file').with_content(/^test$/) }
it { is_expected.to contain_file('mysql-config-file').without_content(/test = true/) }
end

context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it 'makes the directory' do
is_expected.to contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end

it { is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) }
end

context 'without includedir' do
let(:params) {{ :includedir => '' }}
it 'shouldnt contain the directory' do
is_expected.not_to contain_file('mysql-config-file').with({
:ensure => :directory,
:mode => '0755',
})
end

it { is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) }
end
end
end
end
end
end
113 changes: 5 additions & 108 deletions spec/classes/mysql_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,122 +14,20 @@
it { is_expected.to contain_class('mysql::server::providers') }
end

# make sure that overriding the mysqld settings keeps the defaults for everything else
context 'with overrides' do
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
it do
is_expected.to contain_file('mysql-config-file').with({
:mode => '0644',
}).with_content(/basedir/)
end
end

describe 'with multiple instance of an option' do
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}}
it do
is_expected.to contain_file('mysql-config-file').with_content(
/^replicate-do-db = base1$/
).with_content(
/^replicate-do-db = base2$/
).with_content(
/^replicate-do-db = base3$/
)
end
end

describe 'an option set to true' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true } }}
}
it do
is_expected.to contain_file('mysql-config-file').with_content(/^\s*ssl\s*(?:$|= true)/m)
end
end

describe 'an option set to false' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => false } }}
}
it do
is_expected.to contain_file('mysql-config-file').with_content(/^\s*ssl = false/m)
end
end

context 'with remove_default_accounts set' do
let (:params) {{ :remove_default_accounts => true }}
let(:params) {{ :remove_default_accounts => true }}
it { is_expected.to contain_class('mysql::server::account_security') }
end

describe 'possibility of disabling ssl completely' do
let(:params) {
{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true } }}
}
it do
is_expected.to contain_file('mysql-config-file').without_content(/^\s*ssl\s*(?:$|= true)/m)
end
end

context 'mysql::server::install' do
let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }}
it do
it 'contains the package' do
is_expected.to contain_package('mysql-server').with({
:ensure => :present,
:name => 'mysql-server',
})
end
end

if pe_platform =~ /redhat-7/
context 'mysql::server::install on RHEL 7' do
let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }}
it do
is_expected.to contain_package('mysql-server').with({
:ensure => :present,
:name => 'mariadb-server',
})
end
end
end

context 'mysql::server::config' do
context 'with includedir' do
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
it do
is_expected.to contain_file('/etc/my.cnf.d').with({
:ensure => :directory,
:mode => '0755',
})
end

it do
is_expected.to contain_file('mysql-config-file').with({
:mode => '0644',
})
end

it do
is_expected.to contain_file('mysql-config-file').with_content(/!includedir/)
end
end

context 'without includedir' do
let(:params) {{ :includedir => '' }}
it do
is_expected.not_to contain_file('mysql-config-file').with({
:ensure => :directory,
:mode => '0755',
})
end

it do
is_expected.to contain_file('mysql-config-file').with({
:mode => '0644',
})
end

it do
is_expected.to contain_file('mysql-config-file').without_content(/!includedir/)
end
context 'with datadir overridden' do
let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }}
it { is_expected.to contain_exec('mysql_install_db') }
end
end

Expand Down Expand Up @@ -159,7 +57,6 @@
it { is_expected.to contain_mysql_user('root@localhost') }
it { is_expected.to contain_file('/root/.my.cnf') }
end

end

context 'mysql::server::providers' do
Expand Down

0 comments on commit 9cb685d

Please sign in to comment.