From 5c819fbe342c7c7f762fe14b4bd849f1d5d69105 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 27 Dec 2021 10:23:53 +0900 Subject: [PATCH] Load libraries in a single place This change refactors how the dependent libraries are loaded during unit tests, and load the libraries in the base spec_helper to avoid duplicate and redundant implementations. Change-Id: I7ee1f07d71cfe6bd08d5255a489f2e6c1045e5c9 --- spec/spec_helper.rb | 4 ++- .../libvirtd_config/ini_setting_spec.rb | 16 ----------- .../ini_setting_spec.rb | 16 ----------- .../nova_api_paste_ini/ini_setting_spec.rb | 16 ----------- .../nova_api_uwsgi_config/ini_setting_spec.rb | 16 ----------- .../nova_config/openstackconfig_spec.rb | 27 ------------------- .../novajoin_config/ini_setting_spec.rb | 27 ------------------- 7 files changed, 3 insertions(+), 119 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 036c7e4f0..54c100646 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,7 @@ -# Load libraries from openstacklib here to simulate how they live together in a real puppet run (for provider unit tests) +# Load libraries here to simulate how they live together in a real puppet run (for provider unit tests) +$LOAD_PATH.push(File.join(File.dirname(__FILE__), 'fixtures', 'modules', 'inifile', 'lib')) $LOAD_PATH.push(File.join(File.dirname(__FILE__), 'fixtures', 'modules', 'openstacklib', 'lib')) + require 'puppetlabs_spec_helper/module_spec_helper' require 'shared_examples' require 'puppet-openstack_spec_helper/facts' diff --git a/spec/unit/provider/libvirtd_config/ini_setting_spec.rb b/spec/unit/provider/libvirtd_config/ini_setting_spec.rb index 24e98a773..137468314 100644 --- a/spec/unit/provider/libvirtd_config/ini_setting_spec.rb +++ b/spec/unit/provider/libvirtd_config/ini_setting_spec.rb @@ -1,19 +1,3 @@ -# -# 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(:libvirtd_config).provider(:ini_setting) describe provider_class do diff --git a/spec/unit/provider/nova_api_metadata_uwsgi_config/ini_setting_spec.rb b/spec/unit/provider/nova_api_metadata_uwsgi_config/ini_setting_spec.rb index 3077a3c8b..61da6c913 100644 --- a/spec/unit/provider/nova_api_metadata_uwsgi_config/ini_setting_spec.rb +++ b/spec/unit/provider/nova_api_metadata_uwsgi_config/ini_setting_spec.rb @@ -1,19 +1,3 @@ -# -# 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_metadata_uwsgi_config).provider(:ini_setting) describe provider_class do 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 index b674841e0..d68fe5042 100644 --- a/spec/unit/provider/nova_api_paste_ini/ini_setting_spec.rb +++ b/spec/unit/provider/nova_api_paste_ini/ini_setting_spec.rb @@ -1,19 +1,3 @@ -# -# 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 diff --git a/spec/unit/provider/nova_api_uwsgi_config/ini_setting_spec.rb b/spec/unit/provider/nova_api_uwsgi_config/ini_setting_spec.rb index b8bdea52a..b6d6e2f75 100644 --- a/spec/unit/provider/nova_api_uwsgi_config/ini_setting_spec.rb +++ b/spec/unit/provider/nova_api_uwsgi_config/ini_setting_spec.rb @@ -1,19 +1,3 @@ -# -# 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_uwsgi_config).provider(:ini_setting) describe provider_class do diff --git a/spec/unit/provider/nova_config/openstackconfig_spec.rb b/spec/unit/provider/nova_config/openstackconfig_spec.rb index d602cecdd..1ad00d89a 100644 --- a/spec/unit/provider/nova_config/openstackconfig_spec.rb +++ b/spec/unit/provider/nova_config/openstackconfig_spec.rb @@ -1,30 +1,3 @@ -# -# 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 programmatically set the modulepath -$LOAD_PATH.push( - File.join( - File.dirname(__FILE__), - '..', - '..', - '..', - 'fixtures', - 'modules', - 'inifile', - 'lib') -) -$LOAD_PATH.push( - File.join( - File.dirname(__FILE__), - '..', - '..', - '..', - 'fixtures', - 'modules', - 'openstacklib', - 'lib') -) require 'spec_helper' provider_class = Puppet::Type.type(:nova_config).provider(:openstackconfig) describe provider_class do diff --git a/spec/unit/provider/novajoin_config/ini_setting_spec.rb b/spec/unit/provider/novajoin_config/ini_setting_spec.rb index 1a95963f2..9acb07b53 100644 --- a/spec/unit/provider/novajoin_config/ini_setting_spec.rb +++ b/spec/unit/provider/novajoin_config/ini_setting_spec.rb @@ -1,30 +1,3 @@ -# -# 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') -) -$LOAD_PATH.push( - File.join( - File.dirname(__FILE__), - '..', - '..', - '..', - 'fixtures', - 'modules', - 'openstacklib', - 'lib') -) require 'spec_helper' provider_class = Puppet::Type.type(:novajoin_config).provider(:ini_setting) describe provider_class do