From 972f3a648642f72924ad68feb2bcacc470306cac Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Wed, 3 Jan 2018 11:10:35 -0600 Subject: [PATCH] Modify `inspec json` to use `check_mode` (#2435) This modifies `inspec json` to make it not evaluate code inside of `only_if` blocks. Signed-off-by: Jerry Aldrich --- lib/inspec/cli.rb | 1 + test/functional/inspec_json_profile_test.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb index cf021cef8..b68b7f696 100644 --- a/lib/inspec/cli.rb +++ b/lib/inspec/cli.rb @@ -36,6 +36,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI o = opts.dup o[:ignore_supports] = true o[:backend] = Inspec::Backend.create(target: 'mock://') + o[:check_mode] = true profile = Inspec::Profile.for_target(target, o) dst = o[:output].to_s diff --git a/test/functional/inspec_json_profile_test.rb b/test/functional/inspec_json_profile_test.rb index 05b817fdb..7ce688d84 100644 --- a/test/functional/inspec_json_profile_test.rb +++ b/test/functional/inspec_json_profile_test.rb @@ -121,4 +121,11 @@ describe 'inspec json' do out.exit_status.must_equal 0 end end + + describe 'inspec json with a profile containing only_if' do + it 'ignores the `only_if`' do + out = inspec('json ' + File.join(profile_path, 'only-if-os-nope')) + out.exit_status.must_equal 0 + end + end end