spec: Add Unit Tests for Ceilometer_config type/provider

Change-Id: I0527683055829d3a3b6ff465c48a0caf44c41595
Partial-bug: #1440401
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
changes/88/170488/4
Gael Chamoulaud 8 years ago
parent 2b3a328ea6
commit 0ec70ff60f
  1. 42
      spec/unit/provider/ceilometer_config/ini_setting_spec.rb
  2. 53
      spec/unit/type/ceilometer_config_spec.rb

@ -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

@ -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
Loading…
Cancel
Save