mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
CHEF-9848 - Exclude Warning "Unrecognized feature name" for Custom InSpec plugins. (#6988)
* Adds the check for custom plugins to avoid showing "Unrecognised Feature " warnings for them. Signed-off-by: Vasu1105 <vjagdale@progress.com> * Test to verify feature validation should not show warning for custom plugins Signed-off-by: Vasu1105 <vjagdale@progress.com> * Fix the test failures Signed-off-by: Vasu1105 <vjagdale@progress.com> --------- Signed-off-by: Vasu1105 <vjagdale@progress.com>
This commit is contained in:
parent
0fdfaad9d0
commit
91210f8afe
2 changed files with 32 additions and 1 deletions
|
@ -11,7 +11,10 @@ module Inspec
|
|||
# Validate that the feature is recognized
|
||||
feature = config[feature_name]
|
||||
unless feature
|
||||
logger.warn "Unrecognized feature name '#{feature_name}'"
|
||||
# Avoid warning for custom plugins
|
||||
user_plugins = Inspec::Plugin::V2::Registry.instance.plugin_statuses.select { |status| status.installation_type == :user_gem }
|
||||
user_plugin_names = user_plugins.collect { |a| a.name.to_s }
|
||||
logger.warn "Unrecognized feature name '#{feature_name}'" unless user_plugin_names.include?(feature_name)
|
||||
end
|
||||
|
||||
# If the feature is not recognized
|
||||
|
|
|
@ -9,7 +9,24 @@ require "stringio"
|
|||
|
||||
require "inspec/feature"
|
||||
|
||||
require "inspec/plugin/v2"
|
||||
|
||||
class Inspec::Plugin::V2::Loader
|
||||
public :detect_system_plugins
|
||||
end
|
||||
|
||||
describe "Inspec::Feature" do
|
||||
after do
|
||||
ENV["HOME"] = Dir.home
|
||||
ENV["INSPEC_CONFIG_DIR"] = nil
|
||||
Inspec::Plugin::V2::Registry.instance.__reset
|
||||
if defined?(::InspecPlugins::TestFixture)
|
||||
InspecPlugins.send :remove_const, :TestFixture
|
||||
end
|
||||
# forget all test fixture files
|
||||
$".reject! { |path| path =~ %r{test/fixtures} }
|
||||
end
|
||||
|
||||
let(:fixtures_path) { "test/fixtures" }
|
||||
it "should be a class" do
|
||||
_(Inspec::Feature).must_be_kind_of Class
|
||||
|
@ -62,6 +79,17 @@ describe "Inspec::Feature" do
|
|||
_(logger_io.string).must_match(/WARN/)
|
||||
_(logger_io.string).must_match(/test-feature-nonesuch/)
|
||||
end
|
||||
|
||||
it "should not give warnings for inspec custom plugins" do
|
||||
@config_dir_path = File.expand_path "test/fixtures/config_dirs"
|
||||
ENV["INSPEC_CONFIG_DIR"] = File.join(@config_dir_path, "train-test-fixture")
|
||||
loader = Inspec::Plugin::V2::Loader.new(omit_bundles: true)
|
||||
loader.send(:read_conf_file_into_registry)
|
||||
Inspec::Plugin::V2::Registry.instance
|
||||
Inspec.with_feature("train-test-fixture", config: cfg, logger: logger) do
|
||||
end
|
||||
_(logger_io.string).wont_match(/WARN/)
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Integration with Entitlement
|
||||
|
|
Loading…
Reference in a new issue