Skip to content

Commit

Permalink
spec: Add Unit Tests for Ceilometer_config type/provider
Browse files Browse the repository at this point in the history
Change-Id: I0527683055829d3a3b6ff465c48a0caf44c41595
Partial-bug: #1440401
Signed-off-by: Gael Chamoulaud <[email protected]>
  • Loading branch information
strider committed Apr 16, 2015
1 parent 2b3a328 commit 0ec70ff
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/unit/provider/ceilometer_config/ini_setting_spec.rb
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
53 changes: 53 additions & 0 deletions spec/unit/type/ceilometer_config_spec.rb
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

0 comments on commit 0ec70ff

Please sign in to comment.