Add fixtures.yml and mysql db spec test

This commit is contained in:
Xingchao Yu 2013-10-18 16:19:51 +08:00
parent 77f6823b31
commit 9b9d9a205e
3 changed files with 123 additions and 0 deletions

8
.fixtures.yml Normal file
View File

@ -0,0 +1,8 @@
fixtures:
repositories:
'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile'
'keystone': 'git://github.com/stackforge/puppet-keystone.git'
'mysql': 'git://github.com/puppetlabs/puppetlabs-mysql.git'
'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
symlinks:
'designate': "#{source_dir}"

View File

@ -0,0 +1,110 @@
require 'spec_helper'
describe 'designate::db::mysql' do
let :pre_condition do
'include mysql::server'
end
let :params do
{ :password => 's3cr3t',
:dbname => 'designate',
:user => 'designate',
:host => 'localhost',
:charset => 'latin1'
}
end
shared_examples_for 'designate mysql database' do
context 'when omiting the required parameter password' do
before { params.delete(:password) }
it { expect { should raise_error(Puppet::Error) } }
end
it 'creates a mysql database' do
should contain_mysql__db( params[:dbname] ).with(
:user => params[:user],
:password => params[:password],
:host => params[:host],
:charset => params[:charset],
:require => 'Class[Mysql::Config]'
)
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
it_configures 'designate mysql database'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'designate mysql database'
end
describe "overriding allowed_hosts param to array" do
let :facts do
{ :osfamily => "Debian" }
end
let :params do
{
:password => 'designatepass',
:allowed_hosts => ['localhost','%']
}
end
it {should_not contain_designate__db__mysql__host_access("localhost").with(
:user => 'designate',
:password => 'designatepass',
:database => 'designate'
)}
it {should contain_designate__db__mysql__host_access("%").with(
:user => 'designate',
:password => 'designatepass',
:database => 'designate'
)}
end
describe "overriding allowed_hosts param to string" do
let :facts do
{ :osfamily => 'RedHat' }
end
let :params do
{
:password => 'designatepass2',
:allowed_hosts => '192.168.1.1'
}
end
it {should contain_designate__db__mysql__host_access("192.168.1.1").with(
:user => 'designate',
:password => 'designatepass2',
:database => 'designate'
)}
end
describe "overriding allowed_hosts param equals to host param " do
let :facts do
{ :osfamily => 'RedHat' }
end
let :params do
{
:password => 'designatepass2',
:allowed_hosts => 'localhost'
}
end
it {should_not contain_designate__db__mysql__host_access("localhost").with(
:user => 'designate',
:password => 'designatepass2',
:database => 'designate'
)}
end
end

5
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,5 @@
require 'puppetlabs_spec_helper/module_spec_helper'
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
end