mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
Divide tests into undeclared and required groups
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
e88dab4365
commit
58e8bc5167
6 changed files with 58 additions and 29 deletions
14
test/fixtures/profiles/inputs/required/controls/required.rb
vendored
Normal file
14
test/fixtures/profiles/inputs/required/controls/required.rb
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
control 'start_marker' do
|
||||
describe('dummy_test_01') do
|
||||
it { should cmp 'dummy_test_01'}
|
||||
end
|
||||
end
|
||||
|
||||
discard_me = input('required_01')
|
||||
|
||||
control 'end_marker' do
|
||||
describe('dummy_test_04') do
|
||||
it { should cmp 'dummy_test_04'}
|
||||
end
|
||||
end
|
1
test/fixtures/profiles/inputs/required/files/inputs.yaml
vendored
Normal file
1
test/fixtures/profiles/inputs/required/files/inputs.yaml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
required_01: "required_01"
|
13
test/fixtures/profiles/inputs/required/inspec.yml
vendored
Normal file
13
test/fixtures/profiles/inputs/required/inspec.yml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
name: required_inputs
|
||||
title: InSpec Profile
|
||||
maintainer: The Authors
|
||||
copyright: The Authors
|
||||
copyright_email: you@example.com
|
||||
license: Apache-2.0
|
||||
summary: A profile mentioning an input in a control file that is required
|
||||
version: 0.1.0
|
||||
|
||||
inputs:
|
||||
- name: required_01
|
||||
required: true
|
||||
type: string
|
|
@ -1,5 +0,0 @@
|
|||
undeclared_00: "undeclared_00"
|
||||
undeclared_01: "undeclared_01"
|
||||
undeclared_02: "undeclared_02"
|
||||
undeclared_03: "undeclared_03"
|
||||
undeclared_04: "undeclared_04"
|
|
@ -6,20 +6,3 @@ copyright_email: you@example.com
|
|||
license: Apache-2.0
|
||||
summary: A profile mentioning an attribute in a control file that has not otherwise been mentioned
|
||||
version: 0.1.0
|
||||
|
||||
inputs:
|
||||
- name: undeclared_00
|
||||
required: true
|
||||
type: string
|
||||
- name: undeclared_01
|
||||
required: true
|
||||
type: string
|
||||
- name: undeclared_02
|
||||
required: true
|
||||
type: string
|
||||
- name: undeclared_03
|
||||
required: true
|
||||
type: string
|
||||
- name: undeclared_04
|
||||
required: true
|
||||
type: string
|
||||
|
|
|
@ -293,16 +293,39 @@ describe "inputs" do
|
|||
assert_json_controls_passing(result)
|
||||
end
|
||||
end
|
||||
|
||||
# Addresses https://github.com/inspec/inspec/issues/4769
|
||||
describe "when using a profile with undeclared (valueless) inputs and an input file" do
|
||||
it "should not warn and run normally" do
|
||||
cmd = "exec #{inputs_profiles_path}/undeclared --input-file #{inputs_profiles_path}/undeclared/files/inputs.yaml"
|
||||
describe "when using a profile with required inputs" do
|
||||
describe "when the values are not provided" do
|
||||
it "should emit an error and exit code 1" do
|
||||
cmd = "exec #{inputs_profiles_path}/required"
|
||||
|
||||
result = run_inspec_process(cmd, json: true)
|
||||
result = run_inspec_process(cmd, json: true)
|
||||
|
||||
_(result.stderr).must_be_empty
|
||||
assert_json_controls_passing(result)
|
||||
_(result.stderr).must_include "Input 'required_01'"
|
||||
_(result.stderr).must_include "does not have a value"
|
||||
assert_exit_code 1, result
|
||||
end
|
||||
end
|
||||
describe "when the values are provided by an input file" do
|
||||
it "should not warn and run normally" do
|
||||
cmd = "exec #{inputs_profiles_path}/required --input-file #{inputs_profiles_path}/required/files/inputs.yaml"
|
||||
|
||||
result = run_inspec_process(cmd, json: true)
|
||||
|
||||
_(result.stderr).must_be_empty
|
||||
assert_json_controls_passing(result)
|
||||
end
|
||||
end
|
||||
describe "when the values are provided by a CLI flag" do
|
||||
it "should not warn and run normally" do
|
||||
cmd = "exec #{inputs_profiles_path}/required --input required_01=anything"
|
||||
|
||||
result = run_inspec_process(cmd, json: true)
|
||||
|
||||
_(result.stderr).must_be_empty
|
||||
assert_json_controls_passing(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue