Improvements in various descriptions and a better way to check for hash type

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2021-03-31 12:35:11 +05:30
parent c0b213c46a
commit a55b083b0a
4 changed files with 4 additions and 8 deletions

View file

@ -256,7 +256,7 @@ module Inspec
data.inputs.each do |input_name, input_value| data.inputs.each do |input_name, input_value|
evt = Inspec::Input::Event.new( evt = Inspec::Input::Event.new(
value: input_value&.class.eql?(Hash) ? Thor::CoreExt::HashWithIndifferentAccess.new(input_value) : input_value, value: input_value.is_a?(Hash) ? Thor::CoreExt::HashWithIndifferentAccess.new(input_value) : input_value,
provider: :cli_files, provider: :cli_files,
priority: 40, priority: 40,
file: path file: path
@ -307,7 +307,7 @@ module Inspec
def handle_raw_input_from_metadata(input_orig, profile_name) def handle_raw_input_from_metadata(input_orig, profile_name)
input_options = input_orig.dup input_options = input_orig.dup
input_name = input_options.delete(:name) input_name = input_options.delete(:name)
input_options[:value] = Thor::CoreExt::HashWithIndifferentAccess.new(input_options[:value]) if input_options[:value]&.class.eql?(Hash) input_options[:value] = Thor::CoreExt::HashWithIndifferentAccess.new(input_options[:value]) if input_options[:value].is_a?(Hash)
input_options[:provider] = :profile_metadata input_options[:provider] = :profile_metadata
input_options[:file] = File.join(profile_name, "inspec.yml") input_options[:file] = File.join(profile_name, "inspec.yml")
input_options[:priority] ||= 30 input_options[:priority] ||= 30

View file

@ -1,8 +1,6 @@
# copyright: 218, The Authors # copyright: 218, The Authors
title "Verifying loading of hashmap inputs using metadata and external file" title "Verifying loading of hashmap inputs using metadata and external file"
# controls to test metadata file hash traversing
control "hashmap-metadata" do control "hashmap-metadata" do
title "Verifying loading of hashmap inputs using metadata file" title "Verifying loading of hashmap inputs using metadata file"
@ -16,8 +14,6 @@ control "hashmap-metadata" do
end end
end end
# controls to test external attribute file hash traversing
control "hashmap-external-file" do control "hashmap-external-file" do
title "Verifying loading of hashmap inputs using external file" title "Verifying loading of hashmap inputs using external file"

View file

@ -4,7 +4,7 @@ maintainer: The Authors
copyright: The Authors copyright: The Authors
copyright_email: you@example.com copyright_email: you@example.com
license: Apache-2.0 license: Apache-2.0
summary: A profile that checks the hash inputs using metadata file and external file. summary: A profile that checks loading of hashmap inputs using metadata file and external file.
version: 0.1.0 version: 0.1.0
supports: supports:
platform: os platform: os

View file

@ -445,7 +445,7 @@ describe "inputs" do
end end
describe "when a profile is executed with external inputs and inputs defined in metadata file" do describe "when a profile is executed with external inputs and inputs defined in metadata file" do
it "should access the values successfully from in both input ways" do it "should access the values successfully from both input ways" do
result = run_inspec_process("exec #{inputs_profiles_path}/hashmap --input-file #{external_attributes_file_path}", json: true) result = run_inspec_process("exec #{inputs_profiles_path}/hashmap --input-file #{external_attributes_file_path}", json: true)
_(result.stderr).must_be_empty _(result.stderr).must_be_empty
assert_json_controls_passing(result) assert_json_controls_passing(result)