From 0ec70ff60f620a1af29ae64a646ee7e5ad98ebb9 Mon Sep 17 00:00:00 2001 From: Gael Chamoulaud Date: Fri, 3 Apr 2015 15:15:02 +0200 Subject: [PATCH] spec: Add Unit Tests for Ceilometer_config type/provider Change-Id: I0527683055829d3a3b6ff465c48a0caf44c41595 Partial-bug: #1440401 Signed-off-by: Gael Chamoulaud --- .../ceilometer_config/ini_setting_spec.rb | 42 +++++++++++++++ spec/unit/type/ceilometer_config_spec.rb | 53 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 spec/unit/provider/ceilometer_config/ini_setting_spec.rb create mode 100644 spec/unit/type/ceilometer_config_spec.rb diff --git a/spec/unit/provider/ceilometer_config/ini_setting_spec.rb b/spec/unit/provider/ceilometer_config/ini_setting_spec.rb new file mode 100644 index 000000000..172766dc2 --- /dev/null +++ b/spec/unit/provider/ceilometer_config/ini_setting_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 diff --git a/spec/unit/type/ceilometer_config_spec.rb b/spec/unit/type/ceilometer_config_spec.rb new file mode 100644 index 000000000..226507eb9 --- /dev/null +++ b/spec/unit/type/ceilometer_config_spec.rb @@ -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