Add spec tests for api-paste-ini

Define api-paste-ini configuration using provider and type,
but have not spec tests, so add them.

Change-Id: I9b6024633980bf251de966df947fe510d39bf4dc
This commit is contained in:
ZhongShengping 2016-05-11 13:28:56 +08:00
parent cca9f888bf
commit 0b5551d464
2 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,53 @@
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:manila_api_paste_ini).provider(:ini_setting)
describe provider_class do
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Manila_api_paste_ini.new(
{:name => 'boo/zoo', :value => 'plop'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('boo')
expect(provider.setting).to eq('zoo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Manila_api_paste_ini.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Manila_api_paste_ini.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,70 @@
require 'puppet'
require 'puppet/type/manila_api_paste_ini'
describe 'Puppet::Type.type(:manila_api_paste_ini)' do
before :each do
Puppet::Type.rmtype(:manila_api_paste_ini)
Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
@manila_api_paste_ini = Puppet::Type.type(:manila_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end
shared_examples_for 'manila_api_paste_ini' do
it 'should require a name' do
expect {
Puppet::Type.type(:manila_api_paste_ini).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:manila_api_paste_ini).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:manila_api_paste_ini).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:manila_api_paste_ini).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@manila_api_paste_ini[:value] = 'bar'
expect(@manila_api_paste_ini[:value]).to eq('bar')
end
it 'should not accept a value with whitespace' do
@manila_api_paste_ini[:value] = 'b ar'
expect(@manila_api_paste_ini[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@manila_api_paste_ini[:ensure] = :present
expect(@manila_api_paste_ini[:ensure]).to eq(:present)
@manila_api_paste_ini[:ensure] = :absent
expect(@manila_api_paste_ini[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@manila_api_paste_ini[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'manila')
catalog.add_resource package, @manila_api_paste_ini
dependency = @manila_api_paste_ini.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@manila_api_paste_ini)
expect(dependency[0].source).to eq(package)
end
end
end