Merge pull request #49 from bodepd/test_coverage

Add more spec test coverage
This commit is contained in:
Nan Liu 2012-03-16 15:16:32 -07:00
commit 9627d0126b
4 changed files with 201 additions and 19 deletions

View file

@ -1,9 +1,46 @@
require 'spec_helper'
describe 'mysql' do
let :facts do
{ :osfamily => 'Debian'}
describe 'on a debian based os' do
let :facts do
{ :osfamily => 'Debian'}
end
it { should contain_package('mysql_client').with(
:name => 'mysql-client',
:ensure => 'present'
)}
end
describe 'on a redhat based os' do
let :facts do
{:osfamily => 'Redhat'}
end
it { should contain_package('mysql_client').with(
:name => 'mysql',
:ensure => 'present'
)}
describe 'when parameters are supplied' do
let :params do
{:package_ensure => 'latest', :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'}
end
it 'should fail' do
expect do
subject
end.should raise_error(/Unsupported osfamily: foo/)
end
end
it { should contain_class 'mysql' }
end

View file

@ -0,0 +1,46 @@
require 'spec_helper'
describe 'mysql::python' do
describe 'on a debian based os' do
let :facts do
{ :osfamily => 'Debian'}
end
it { should contain_package('python-mysqldb').with(
:name => 'python-mysqldb',
:ensure => 'present'
)}
end
describe 'on a redhat based os' do
let :facts do
{:osfamily => 'Redhat'}
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'}
end
it 'should fail' do
expect do
subject
end.should raise_error(/Unsupported osfamily: foo/)
end
end
end

View file

@ -0,0 +1,53 @@
require 'spec_helper'
describe 'mysql::ruby' do
describe 'on a debian based os' do
let :facts do
{ :osfamily => 'Debian'}
end
it { should contain_package('ruby_mysql').with(
:name => 'libmysql-ruby',
:ensure => 'present',
# TODO is this what we want? does this actually work
# if the provider is blank
:provider => ''
)}
end
describe 'on a redhat based os' do
let :facts do
{:osfamily => 'Redhat'}
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'}
end
it 'should fail' do
expect do
subject
end.should raise_error(/Unsupported osfamily: foo/)
end
end
end

View file

@ -1,22 +1,68 @@
require 'spec_helper'
describe 'mysql::server' do
let (:facts) do
{ :osfamily => 'Debian' }
let :constant_parameter_defaults do
{:config_hash => {},
:package_ensure => 'present',
:package_name => 'mysql-server'
}
end
it { should contain_package('mysql-server').with_ensure('present') }
it do should contain_service('mysqld').with(
'name' => 'mysql',
'ensure' => 'running',
'enable' => 'true'
) end
describe 'with osfamily specific defaults' do
{
'Debian' => {
:service_name => 'mysql'
},
'Redhat' => {
:service_name => 'mysqld'
}
}.each do |osfamily, osparams|
it { should contain_class 'mysql::config' }
it do should contain_exec('mysqld-restart').with(
'command' => 'service mysql restart',
'logoutput' => 'on_failure',
'path' => '/sbin/:/usr/sbin/:/usr/bin/:/bin/',
'refreshonly' => 'true'
) end
describe "when osfamily is #{osfamily}" do
let :facts do
{:osfamily => osfamily}
end
[
{},
{
:package_name => 'dans_package',
:package_ensure => 'latest',
:service_name => 'dans_service',
:config_hash => {'root_password' => 'foo'}
}
].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 { should contain_service('mysqld').with(
:name => param_values[:service_name],
:ensure => 'running',
:enable => 'true',
:require => 'Package[mysql-server]'
)}
end
end
end
end
end
end