Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
# Unit tests for Inspec::PluginLoader and Registry
require 'minitest/autorun'
require_relative '../../../../lib/inspec/plugin/v2'
2018-09-27 22:46:35 +00:00
require 'train' # Needed for Train plugin testing
2019-04-24 00:21:31 +00:00
class PluginLoaderTests < Minitest :: Test
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
@@orig_home = Dir . home
def reset_globals
ENV [ 'HOME' ] = @@orig_home
ENV [ 'INSPEC_CONFIG_DIR' ] = nil
2019-05-16 21:50:01 +00:00
Inspec :: Plugin :: V2 :: Registry . instance . __reset
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
end
def setup
reset_globals
2019-05-17 00:47:54 +00:00
@config_dir_path = File . expand_path " test/unit/mock/config_dirs "
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
@bundled_plugins = [
2018-09-25 14:29:18 +00:00
:'inspec-supermarket' ,
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
]
2018-09-18 04:00:54 +00:00
@core_plugins = [
2018-09-19 00:19:56 +00:00
:'inspec-artifact' ,
2018-10-04 18:31:39 +00:00
:'inspec-compliance' ,
2018-09-18 17:10:07 +00:00
:'inspec-habitat' ,
2018-09-18 19:54:33 +00:00
:'inspec-init' ,
2018-09-18 04:00:54 +00:00
]
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
end
def teardown
reset_globals
2019-05-16 21:50:01 +00:00
# Clean up any activated gems
Gem . loaded_specs . delete ( 'inspec-test-fixture' )
Gem . loaded_specs . delete ( 'ordinal_array' )
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
end
#====================================================================#
# basic constructor usage and bundle detection #
#====================================================================#
def test_constructor_should_not_load_anything_automatically
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new
assert_equal 0 , reg . loaded_count , " \n Registry load count "
end
def test_constructor_should_detect_bundled_plugins
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new
@bundled_plugins . each do | bundled_plugin_name |
assert reg . known_plugin? ( bundled_plugin_name ) , " \n #{ bundled_plugin_name } should be detected as a bundled plugin "
end
end
2018-09-18 04:00:54 +00:00
def test_constructor_should_detect_core_plugins
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new
@core_plugins . each do | core_plugin_name |
assert reg . known_plugin? ( core_plugin_name ) , " \n #{ core_plugin_name } should be detected as a core plugin "
end
end
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
def test_constructor_should_skip_bundles_when_option_is_set
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
@bundled_plugins . each do | bundled_plugin_name |
refute reg . known_plugin? ( bundled_plugin_name ) , " \n #{ bundled_plugin_name } should not be detected when omit_bundles is set "
end
end
2018-09-18 04:00:54 +00:00
def test_constructor_should_skip_core_when_option_is_set
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_core_plugins : true )
@core_plugins . each do | core_plugin_name |
refute reg . known_plugin? ( core_plugin_name ) , " \n #{ core_plugin_name } should not be detected when omit_core_plugins is set "
end
end
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
def test_constructor_when_using_home_dir_detects_declared_plugins
ENV [ 'HOME' ] = File . join ( @config_dir_path , 'fakehome' )
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new
assert reg . known_plugin? ( :'inspec-test-home-marker' ) , " \n inspec-test-home-marker should be detected as a plugin "
end
#====================================================================#
# unusual plugin.json situations #
#====================================================================#
def test_constructor_when_the_plugin_config_is_absent_it_detects_bundled_plugins
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'empty' )
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new
@bundled_plugins . each do | bundled_plugin_name |
assert reg . known_plugin? ( bundled_plugin_name ) , " \n #{ bundled_plugin_name } should be detected as a bundled plugin "
end
end
#====================================================================#
# basic loading #
#====================================================================#
def test_load_no_plugins_should_load_no_plugins
reg = Inspec :: Plugin :: V2 :: Registry . instance
2019-05-10 00:26:56 +00:00
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true , omit_core_plugins : true , omit_user_plugins : true )
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
loader . load_all
assert_equal 0 , reg . loaded_count , " \n Registry load count "
end
def test_load_only_bundled_plugins_should_load_bundled_plugins
skip 'This keeps failing, only affects legacy bundles, will fix later'
# Skip rationale: I beleive this test is failing due to a test artifact - we
# keep loading v1 CLI plugins and then purging the registry, which results (depending
# on test order) in the Ruby `require` refusing to re-load the v1 plugin (since it was
# previously loaded). But since we purge the Registry, the Registry doesn't know
# about it either. Neither of those things are intended to happen as
# the plugin system is finished (the v1 plugins will be ported to v2, and registry
# purging should never happen in real-world use)
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new
loader . load_all
@bundled_plugins . each do | bundled_plugin_name |
assert reg . loaded_plugin? ( bundled_plugin_name ) , " \n #{ bundled_plugin_name } should be loaded "
assert_equal [ :cli_command ] , reg [ bundled_plugin_name ] . plugin_types , " annotate plugin type of bundled plugins "
assert_equal 0 , reg [ bundled_plugin_name ] . api_generation , " annotate API generation of bundled plugins "
assert_kind_of ( Class , reg [ bundled_plugin_name ] . plugin_class )
end
assert_equal @bundled_plugins . count , reg . loaded_count , " \n Registry load count "
end
def test_load_cli_plugin_by_path
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'meaning_by_path' )
reg = Inspec :: Plugin :: V2 :: Registry . instance
plugin_name = :'inspec-meaning-of-life'
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
assert reg . known_plugin? ( plugin_name ) , " \n #{ plugin_name } should be a known plugin "
refute reg . loaded_plugin? ( plugin_name ) , " \n #{ plugin_name } should not be loaded yet "
loader . load_all
assert reg . loaded_plugin? ( plugin_name ) , " \n #{ plugin_name } should be loaded "
end
2018-09-19 21:38:13 +00:00
def test_list_managed_gems
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'test-fixture-2-float' )
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
gemspecs = loader . list_managed_gems
gem = gemspecs . detect { | spec | spec . name == 'ordinal_array' }
refute_nil gem , 'loader.list_managed_gems should find ordinal_array'
assert_equal Gem :: Version . new ( '0.2.0' ) , gem . version
end
def test_list_installed_plugin_gems
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'test-fixture-1-float' )
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
gemspecs = loader . list_installed_plugin_gems
gem = gemspecs . detect { | spec | spec . name == 'inspec-test-fixture' }
refute_nil gem , 'loader.list_installed_plugin_gems should find inspec-test-fixture'
assert_equal Gem :: Version . new ( '0.1.0' ) , gem . version
end
def test_load_mock_plugin_by_gem
2019-05-18 22:39:53 +00:00
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'test-fixture-2-float' )
2019-05-16 21:50:01 +00:00
2018-09-19 21:38:13 +00:00
reg = Inspec :: Plugin :: V2 :: Registry . instance
plugin_name = :'inspec-test-fixture'
2019-05-16 21:50:01 +00:00
2018-09-19 21:38:13 +00:00
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
2019-05-16 21:50:01 +00:00
assert_operator reg , :known_plugin? , plugin_name
refute_operator reg , :loaded_plugin? , plugin_name
2018-09-19 21:38:13 +00:00
loader . load_all
2019-05-16 21:50:01 +00:00
assert_operator reg , :loaded_plugin? , plugin_name
2018-09-19 21:38:13 +00:00
end
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
#====================================================================#
# activation #
#====================================================================#
def test_activation
# Setup
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'meaning_by_path' )
registry = Inspec :: Plugin :: V2 :: Registry . instance
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
loader . load_all
status = registry [ :'inspec-meaning-of-life' ]
# Management methods for activation
assert_respond_to status , :activators , 'A plugin status should respond to `activators`'
assert_respond_to registry , :find_activators , 'Registry should respond to `find_activators`'
# Finding an Activator
assert_kind_of Array , status . activators , 'status should have an array for activators'
assert_kind_of Array , registry . find_activators ( ) , 'find_activators should return an array'
assert_equal 'Inspec::Plugin::V2::Activator' , registry . find_activators ( ) [ 0 ] . class . name , 'find_activators should return an array of Activators'
activator = registry . find_activators ( plugin_type : :mock_plugin_type , name : :'meaning-of-life-the-universe-and-everything' ) [ 0 ]
refute_nil activator , 'find_activators should find the test activator'
2018-09-19 21:38:13 +00:00
[ :plugin_name , :plugin_type , :activator_name , :'activated?' , :exception , :activation_proc , :implementation_class ] . each do | method_name |
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
assert_respond_to activator , method_name
end
# Activation preconditions
2018-09-19 21:38:13 +00:00
refute activator . activated? , 'Test activator should start out unactivated'
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
assert_nil activator . exception , 'Test activator should have no exception prior to activation'
assert_nil activator . implementation_class , 'Test activator should not know implementation class prior to activation'
refute InspecPlugins :: MeaningOfLife . const_defined? ( :MockPlugin ) , 'impl_class should not be defined prior to activation'
2019-01-12 04:10:48 +00:00
activator . activate
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
# Activation postconditions
2018-09-19 21:38:13 +00:00
assert activator . activated? , 'Test activator should be activated after activate'
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
assert_nil activator . exception , 'Test activator should have no exception after activation'
# facts about the implementation class
impl_class = activator . implementation_class
refute_nil impl_class , 'Activation should set the implementation class'
assert_kind_of Class , impl_class , 'Should have a Class in the implementation class slot'
assert_includes impl_class . ancestors , Inspec :: Plugin :: V2 :: PluginBase , 'impl_class should derive from PluginBase'
assert_includes impl_class . ancestors , Inspec :: Plugin :: V2 :: PluginType :: Mock , 'impl_class should derive from PluginType::Mock'
assert InspecPlugins :: MeaningOfLife . const_defined? ( :MockPlugin ) , 'impl_class should now be defined'
2019-05-15 22:57:44 +00:00
assert_equal :'inspec-meaning-of-life' , Inspec :: Plugin :: V2 :: PluginBase . find_name_by_implementation_class ( impl_class ) , 'find_name_by_implementation_class should work'
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
end
2018-09-27 22:46:35 +00:00
#====================================================================#
# Train Plugin Special Handling #
#====================================================================#
def test_when_a_train_plugin_is_installed_via_gem_and_required
ENV [ 'INSPEC_CONFIG_DIR' ] = File . join ( @config_dir_path , 'train-test-fixture' )
reg = Inspec :: Plugin :: V2 :: Registry . instance
loader = nil
assert_silent { loader = Inspec :: Plugin :: V2 :: Loader . new }
plugin_name = :'train-test-fixture'
assert ( reg . known_plugin? ( plugin_name ) , 'The train plugin should be known after loader init' )
status = reg [ plugin_name ]
assert_equal ( :'train-1' , status . api_generation , " It should have a special value for api gen (:'train-1') " )
refute ( reg . loaded_plugin? ( plugin_name ) , 'It should not be loaded until needed' )
# 'Requiring' the gem name should succeed
require 'train-test-fixture'
assert_includes ( Train :: Plugins . registry . keys , 'test-fixture' , 'After requiring the gem, the Train Registry should know the plugin is loaded' )
assert ( reg . loaded_plugin? ( plugin_name ) , 'After requiring, InSpec Registry should know the the plugin is loaded' )
end
2019-04-24 00:21:31 +00:00
end