From 86ce4e6cdf5ea1436625e830cd489f27f7e24430 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 27 Dec 2021 10:52:39 +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: I02a8e453e3901ef2b2c1c4b9e8dce5997128f5c2 --- spec/spec_helper.rb | 3 +++ .../openstackconfig_spec.rb | 27 ------------------- .../octavia_config/openstackconfig_spec.rb | 27 ------------------- .../ini_setting_spec.rb | 27 ------------------- 4 files changed, 3 insertions(+), 81 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a5c46c3..33f27e2d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ +# 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/octavia_api_uwsgi_config/openstackconfig_spec.rb b/spec/unit/provider/octavia_api_uwsgi_config/openstackconfig_spec.rb index 5001eaee..ba7813ea 100644 --- a/spec/unit/provider/octavia_api_uwsgi_config/openstackconfig_spec.rb +++ b/spec/unit/provider/octavia_api_uwsgi_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 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(:octavia_api_uwsgi_config).provider(:ini_setting) describe provider_class do diff --git a/spec/unit/provider/octavia_config/openstackconfig_spec.rb b/spec/unit/provider/octavia_config/openstackconfig_spec.rb index 312acb4c..5e80d6cb 100644 --- a/spec/unit/provider/octavia_config/openstackconfig_spec.rb +++ b/spec/unit/provider/octavia_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(:octavia_config).provider(:openstackconfig) describe provider_class do diff --git a/spec/unit/provider/octavia_ovn_provider_config/ini_setting_spec.rb b/spec/unit/provider/octavia_ovn_provider_config/ini_setting_spec.rb index 0c2574f3..82f8a22a 100644 --- a/spec/unit/provider/octavia_ovn_provider_config/ini_setting_spec.rb +++ b/spec/unit/provider/octavia_ovn_provider_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(:octavia_ovn_provider_config).provider(:ini_setting) describe provider_class do