From 88d2b26387363f173b842f2ba9d41d3195d243ef Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Mon, 25 Jan 2016 15:44:17 +0100 Subject: [PATCH] bugfix: write given ID to metadata json Whenever the user provides an ID under which the profile is scoped, write it out to JSON during generation. --- lib/inspec/profile.rb | 1 + test/unit/profile_test.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/inspec/profile.rb b/lib/inspec/profile.rb index cd8405e84..75276aae7 100644 --- a/lib/inspec/profile.rb +++ b/lib/inspec/profile.rb @@ -33,6 +33,7 @@ module Inspec @params = @metadata.params # use the id from parameter, name or fallback to nil @profile_id = options[:id] || params[:name] || nil + @params[:name] = @profile_id @params[:rules] = rules = {} @runner = Runner.new( diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index a26395b27..d2ac3c86f 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -41,7 +41,8 @@ describe Inspec::Profile do end describe 'with simple metadata in profile' do - let(:profile) { load_profile('simple-metadata') } + let(:profile_id) { 'simple-metadata' } + let(:profile) { load_profile(profile_id) } it 'has metadata' do profile.params[:name].must_equal 'yumyum profile' @@ -50,6 +51,12 @@ describe Inspec::Profile do it 'has no rules' do profile.params[:rules].must_equal({}) end + + it 'can overwrite the profile ID' do + testID = rand.to_s + res = load_profile(profile_id, id: testID) + res.params[:name].must_equal testID + end end describe 'with simple metadata in profile (legacy mode)' do