From 5f453cd9bddca063b87b58c83f63d850b29b015d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 4 May 2020 03:09:13 +0900 Subject: [PATCH] Add unit tests for nova_api_paste_ini resource ... and deprecated nova_paste_api_ini resource. Change-Id: Ia0cba87b1a609839201d06469be1885ebaf250f4 --- .../nova_api_paste_ini/ini_setting_spec.rb | 29 +++++++++++++++++++ .../nova_paste_api_ini/ini_setting_spec.rb | 29 +++++++++++++++++++ spec/unit/type/nova_api_paste_spec.rb | 24 +++++++++++++++ spec/unit/type/nova_paste_api_spec.rb | 24 +++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 spec/unit/provider/nova_api_paste_ini/ini_setting_spec.rb create mode 100644 spec/unit/provider/nova_paste_api_ini/ini_setting_spec.rb create mode 100644 spec/unit/type/nova_api_paste_spec.rb create mode 100644 spec/unit/type/nova_paste_api_spec.rb diff --git a/spec/unit/provider/nova_api_paste_ini/ini_setting_spec.rb b/spec/unit/provider/nova_api_paste_ini/ini_setting_spec.rb new file mode 100644 index 000000000..b674841e0 --- /dev/null +++ b/spec/unit/provider/nova_api_paste_ini/ini_setting_spec.rb @@ -0,0 +1,29 @@ +# +# these tests are a little concerning b/c they are hacking around the +# modulepath, so these tests will not catch issues that may eventually arise +# related to loading these plugins. +# I could not, for the life of me, figure out how to programatcally set the modulepath +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'inifile', + 'lib') +) +require 'spec_helper' +provider_class = Puppet::Type.type(:nova_api_paste_ini).provider(:ini_setting) +describe provider_class do + + it 'should allow setting to be set explicitly' do + resource = Puppet::Type::Nova_api_paste_ini.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/provider/nova_paste_api_ini/ini_setting_spec.rb b/spec/unit/provider/nova_paste_api_ini/ini_setting_spec.rb new file mode 100644 index 000000000..da340f74f --- /dev/null +++ b/spec/unit/provider/nova_paste_api_ini/ini_setting_spec.rb @@ -0,0 +1,29 @@ +# +# these tests are a little concerning b/c they are hacking around the +# modulepath, so these tests will not catch issues that may eventually arise +# related to loading these plugins. +# I could not, for the life of me, figure out how to programatcally set the modulepath +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'inifile', + 'lib') +) +require 'spec_helper' +provider_class = Puppet::Type.type(:nova_paste_api_ini).provider(:ini_setting) +describe provider_class do + + it 'should allow setting to be set explicitly' do + resource = Puppet::Type::Nova_paste_api_ini.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/nova_api_paste_spec.rb b/spec/unit/type/nova_api_paste_spec.rb new file mode 100644 index 000000000..fd842d32c --- /dev/null +++ b/spec/unit/type/nova_api_paste_spec.rb @@ -0,0 +1,24 @@ +require 'puppet' +require 'puppet/type/nova_api_paste_ini' + +describe 'Puppet::Type.type(:nova_api_paste_ini)' do + before :each do + @nova_api_paste_ini = Puppet::Type.type(:nova_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should accept a valid value' do + @nova_api_paste_ini[:value] = 'bar' + expect(@nova_api_paste_ini[:value]).to eq('bar') + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + package = Puppet::Type.type(:package).new(:name => 'nova-common') + catalog.add_resource package, @nova_api_paste_ini + dependency = @nova_api_paste_ini.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@nova_api_paste_ini) + expect(dependency[0].source).to eq(package) + end + +end diff --git a/spec/unit/type/nova_paste_api_spec.rb b/spec/unit/type/nova_paste_api_spec.rb new file mode 100644 index 000000000..7a54abd44 --- /dev/null +++ b/spec/unit/type/nova_paste_api_spec.rb @@ -0,0 +1,24 @@ +require 'puppet' +require 'puppet/type/nova_paste_api_ini' + +describe 'Puppet::Type.type(:nova_paste_api_ini)' do + before :each do + @nova_paste_api_ini = Puppet::Type.type(:nova_paste_api_ini).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should accept a valid value' do + @nova_paste_api_ini[:value] = 'bar' + expect(@nova_paste_api_ini[:value]).to eq('bar') + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + package = Puppet::Type.type(:package).new(:name => 'nova-common') + catalog.add_resource package, @nova_paste_api_ini + dependency = @nova_paste_api_ini.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@nova_paste_api_ini) + expect(dependency[0].source).to eq(package) + end + +end