List all invoked features by feature sub system (#6979)

* Added class function to list all invoked features by feature sub system

Signed-off-by: Nik08 <nikita.mathur@progress.com>

* Test cases to verify invoked features list function

Signed-off-by: Nik08 <nikita.mathur@progress.com>

---------

Signed-off-by: Nik08 <nikita.mathur@progress.com>
This commit is contained in:
Nikita Mathur 2024-04-16 14:55:33 +05:30 committed by GitHub
parent 7cdd45c690
commit 61a4ee3fc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View file

@ -8,11 +8,15 @@ module Inspec
class Feature
attr_reader :name, :description, :env_preview
@@features_invoked = []
def initialize(feature_name, feature_yaml_opts)
@name = feature_name
feature_yaml_opts ||= {}
@description = feature_yaml_opts["description"]
@env_preview = feature_yaml_opts["env_preview"]
@@features_invoked << feature_name
end
def previewable?
@ -30,5 +34,9 @@ module Inspec
env_preview_feature_name = name.to_s.split("inspec-")[-1]
ENV["CHEF_PREVIEW_#{env_preview_feature_name.gsub("-", "_").upcase}"]
end
def self.list_all_invoked_features
@@features_invoked.uniq
end
end
end

View file

@ -219,5 +219,18 @@ describe "Inspec::Feature" do
_(test_feature_04.no_preview?).must_equal true
end
end
describe "Collecting invoked features" do
let(:feature_config_file) { File.join(fixtures_path, "features-02.yaml") }
let(:cfg) { Inspec::Feature::Config.new(feature_config_file) }
it "returns list of invoked feature names" do
# Invoked features 1 & 2
Inspec.with_feature("inspec-test-feature-01", config: cfg) {}
Inspec.with_feature("inspec-test-feature-02", config: cfg) {}
invoked_features = Inspec::Feature.list_all_invoked_features
_(invoked_features).must_include :"inspec-test-feature-01"
_(invoked_features).must_include :"inspec-test-feature-02"
end
end
end
end