forked from redhat-openstack/openstack-puppet-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec: Add Unit Tests for Ceilometer_config type/provider
Change-Id: I0527683055829d3a3b6ff465c48a0caf44c41595 Partial-bug: #1440401 Signed-off-by: Gael Chamoulaud <[email protected]>
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
$LOAD_PATH.push( | ||
File.join( | ||
File.dirname(__FILE__), | ||
'..', | ||
'..', | ||
'..', | ||
'fixtures', | ||
'modules', | ||
'inifile', | ||
'lib') | ||
) | ||
|
||
require 'spec_helper' | ||
|
||
provider_class = Puppet::Type.type(:ceilometer_config).provider(:ini_setting) | ||
|
||
describe provider_class do | ||
|
||
it 'should default to the default setting when no other one is specified' do | ||
resource = Puppet::Type::Ceilometer_config.new( | ||
{ | ||
:name => 'DEFAULT/foo', | ||
:value => 'bar' | ||
} | ||
) | ||
provider = provider_class.new(resource) | ||
expect(provider.section).to eq('DEFAULT') | ||
expect(provider.setting).to eq('foo') | ||
end | ||
|
||
it 'should allow setting to be set explicitly' do | ||
resource = Puppet::Type::Ceilometer_config.new( | ||
{ | ||
:name => 'dude/foo', | ||
:value => 'bar' | ||
} | ||
) | ||
provider = provider_class.new(resource) | ||
expect(provider.section).to eq('dude') | ||
expect(provider.setting).to eq('foo') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'puppet' | ||
require 'puppet/type/ceilometer_config' | ||
|
||
describe 'Puppet::Type.type(:ceilometer_config)' do | ||
before :each do | ||
@ceilometer_config = Puppet::Type.type(:ceilometer_config).new(:name => 'DEFAULT/foo', :value => 'bar') | ||
end | ||
|
||
it 'should require a name' do | ||
expect { | ||
Puppet::Type.type(:ceilometer_config).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(:ceilometer_config).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(:ceilometer_config).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(:ceilometer_config).new(:name => 'DEFAULT/foo', :ensure => :absent) | ||
end | ||
|
||
it 'should accept a valid value' do | ||
@ceilometer_config[:value] = 'bar' | ||
expect(@ceilometer_config[:value]).to eq('bar') | ||
end | ||
|
||
it 'should not accept a value with whitespace' do | ||
@ceilometer_config[:value] = 'b ar' | ||
expect(@ceilometer_config[:value]).to eq('b ar') | ||
end | ||
|
||
it 'should accept valid ensure values' do | ||
@ceilometer_config[:ensure] = :present | ||
expect(@ceilometer_config[:ensure]).to eq(:present) | ||
@ceilometer_config[:ensure] = :absent | ||
expect(@ceilometer_config[:ensure]).to eq(:absent) | ||
end | ||
|
||
it 'should not accept invalid ensure values' do | ||
expect { | ||
@ceilometer_config[:ensure] = :latest | ||
}.to raise_error(Puppet::Error, /Invalid value/) | ||
end | ||
end |