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
2019-09-24 23:45:03 +00:00
require " helper "
require " inspec/plugin/v2 "
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
2019-06-11 22:24:35 +00:00
require " train " # Needed for Train plugin testing
2018-09-27 22:46:35 +00:00
2019-09-24 23:45:03 +00:00
class Inspec :: Plugin :: V2 :: Loader
public :detect_system_plugins
end
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
2019-06-11 22:24:35 +00:00
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
]
2019-07-09 00:20:30 +00:00
@core_plugins = % i {
inspec - artifact
inspec - compliance
inspec - habitat
inspec - init
}
2019-08-13 21:51:01 +00:00
@system_plugins = [
" train-habitat " ,
]
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
2019-06-11 22:24:35 +00:00
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_detect_bundled_plugins
reg = Inspec :: Plugin :: V2 :: Registry . instance
2019-05-31 21:59:06 +00:00
Inspec :: Plugin :: V2 :: Loader . new
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 . 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
2019-05-31 21:59:06 +00:00
Inspec :: Plugin :: V2 :: Loader . new
2018-09-18 04:00:54 +00:00
@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
2019-05-31 21:59:06 +00:00
Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : 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
@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
2019-05-31 21:59:06 +00:00
Inspec :: Plugin :: V2 :: Loader . new ( omit_core_plugins : true )
2018-09-18 04:00:54 +00:00
@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
2019-06-11 22:24:35 +00:00
ENV [ " HOME " ] = File . join ( @config_dir_path , " fakehome " )
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
reg = Inspec :: Plugin :: V2 :: Registry . instance
2019-05-31 21:59:06 +00:00
Inspec :: Plugin :: V2 :: Loader . new
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 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
2019-06-11 22:24:35 +00:00
ENV [ " INSPEC_CONFIG_DIR " ] = File . join ( @config_dir_path , " empty " )
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
reg = Inspec :: Plugin :: V2 :: Registry . instance
2019-05-31 21:59:06 +00:00
Inspec :: Plugin :: V2 :: Loader . new
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 . 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-08-13 21:51:01 +00:00
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true , omit_core_plugins : true , omit_user_plugins : true , omit_sys_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
2019-06-11 22:24:35 +00:00
skip " This keeps failing, only affects legacy bundles, will fix later "
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
# 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
2019-06-11 22:24:35 +00:00
ENV [ " INSPEC_CONFIG_DIR " ] = File . join ( @config_dir_path , " meaning_by_path " )
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
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
2019-06-11 22:24:35 +00:00
ENV [ " INSPEC_CONFIG_DIR " ] = File . join ( @config_dir_path , " test-fixture-2-float " )
2018-09-19 21:38:13 +00:00
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
gemspecs = loader . list_managed_gems
2019-06-11 22:24:35 +00:00
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
2018-09-19 21:38:13 +00:00
end
def test_list_installed_plugin_gems
2019-06-11 22:24:35 +00:00
ENV [ " INSPEC_CONFIG_DIR " ] = File . join ( @config_dir_path , " test-fixture-1-float " )
2018-09-19 21:38:13 +00:00
loader = Inspec :: Plugin :: V2 :: Loader . new ( omit_bundles : true )
gemspecs = loader . list_installed_plugin_gems
2019-06-11 22:24:35 +00:00
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
2018-09-19 21:38:13 +00:00
end
def test_load_mock_plugin_by_gem
2019-06-11 22:24:35 +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
2019-06-11 22:24:35 +00:00
ENV [ " INSPEC_CONFIG_DIR " ] = File . join ( @config_dir_path , " meaning_by_path " )
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
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
2019-06-11 22:24:35 +00:00
assert_respond_to status , :activators , " A plugin status should respond to `activators` "
assert_respond_to registry , :find_activators , " Registry should respond to `find_activators` "
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
# Finding an Activator
2019-06-11 22:24:35 +00:00
assert_kind_of Array , status . activators , " status should have an array for activators "
2019-07-09 00:20:30 +00:00
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 "
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
activator = registry . find_activators ( plugin_type : :mock_plugin_type , name : :'meaning-of-life-the-universe-and-everything' ) [ 0 ]
2019-06-11 22:24:35 +00:00
refute_nil activator , " find_activators should find the test activator "
2019-07-09 00:20:30 +00:00
% i { 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
2019-06-11 22:24:35 +00:00
refute activator . activated? , " Test activator should start out unactivated "
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 "
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
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
2019-06-11 22:24:35 +00:00
assert activator . activated? , " Test activator should be activated after activate "
assert_nil activator . exception , " Test activator should have no exception after activation "
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
# facts about the implementation class
impl_class = activator . implementation_class
2019-06-11 22:24:35 +00:00
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
2019-06-11 22:24:35 +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
2019-06-11 22:24:35 +00:00
ENV [ " INSPEC_CONFIG_DIR " ] = File . join ( @config_dir_path , " train-test-fixture " )
2018-09-27 22:46:35 +00:00
reg = Inspec :: Plugin :: V2 :: Registry . instance
2019-05-31 21:59:06 +00:00
assert_silent { Inspec :: Plugin :: V2 :: Loader . new }
2018-09-27 22:46:35 +00:00
plugin_name = :'train-test-fixture'
2019-06-11 22:24:35 +00:00
assert ( reg . known_plugin? ( plugin_name ) , " The train plugin should be known after loader init " )
2018-09-27 22:46:35 +00:00
status = reg [ plugin_name ]
assert_equal ( :'train-1' , status . api_generation , " It should have a special value for api gen (:'train-1') " )
2019-06-11 22:24:35 +00:00
refute ( reg . loaded_plugin? ( plugin_name ) , " It should not be loaded until needed " )
2018-09-27 22:46:35 +00:00
# 'Requiring' the gem name should succeed
2019-06-11 22:24:35 +00:00
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 " )
2018-09-27 22:46:35 +00:00
end
2019-09-24 23:45:03 +00:00
REG_INST = Inspec :: Plugin :: V2 :: Registry . instance
def with_empty_registry
old_reg = REG_INST . registry . dup
REG_INST . registry . clear
yield
ensure
REG_INST . registry . replace old_reg
end
def with_logger
old_logger = Inspec :: Log . logger
io = StringIO . new
Inspec :: Log . logger = Logger . new ( io )
yield
io . string
ensure
Inspec :: Log . logger = old_logger
end
def using_bundler?
Gem :: Specification . find_by_name ( " inspec " )
rescue Gem :: MissingSpecError
nil
end
def assert_detect_system_plugins ( exp_keys , exp_err )
# rubocop:disable Style/HashSyntax
loader = Inspec :: Plugin :: V2 :: Loader . new ( :omit_user_plugins = > true ,
:omit_bundles = > true ,
:omit_core_plugins = > true ,
:omit_sys_plugins = > true )
assert_empty REG_INST . registry
yield loader
log_out = with_logger do
assert_silent do
loader . detect_system_plugins
end
end
assert_equal exp_keys , REG_INST . registry . keys . sort
assert_match exp_err , log_out
end
def test_detect_system_plugins
with_empty_registry do
exp = [ ]
exp_err = " inspec gem not found, skipping detecting of system plugins \n "
assert_detect_system_plugins exp , exp_err do | loader |
def loader . find_inspec_gemspec ( * )
nil
end
end
end
end
def test_detect_system_plugins_inspec
skip " not valid in this env " unless using_bundler?
with_empty_registry do
exp = % i { train - aws train - habitat train - winrm }
exp_err = " "
assert_detect_system_plugins exp , exp_err do | loader |
def loader . find_inspec_gemspec ( name , version )
super if name == " inspec "
end
end
end
end
2019-04-24 00:21:31 +00:00
end