Replace most mentions of attribute with input in test/

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-02-12 18:02:54 -05:00
parent e5f764c9fc
commit f7d58ad92c
23 changed files with 101 additions and 100 deletions

View file

@ -6,7 +6,7 @@ require 'functional/helper'
describe 'example inheritance profile' do
include FunctionalHelper
let(:path) { File.join(examples_path, 'inheritance') }
let(:attrs) { File.join(examples_path, 'profile-attribute.yml') }
let(:input_file) { File.join(examples_path, 'profile-attribute.yml') } # TODO rename attributes in examples
it 'check succeeds with --profiles-path' do
out = inspec('check ' + path + ' --profiles-path ' + examples_path)
@ -68,7 +68,7 @@ describe 'example inheritance profile' do
end
it 'can execute a profile inheritance' do
out = inspec('exec ' + path + ' --reporter json --no-create-lockfile --attrs ' + attrs)
out = inspec('exec ' + path + ' --reporter json --no-create-lockfile --input-file ' + input_file)
out.stderr.must_equal ''
out.exit_status.must_equal 101
JSON.load(out.stdout).must_be_kind_of Hash

View file

@ -2,14 +2,14 @@
require 'functional/helper'
describe 'attributes' do
describe 'inputs' do
include FunctionalHelper
let(:inputs_profiles_path) { File.join(profile_path, 'inputs') }
[
'flat',
'nested',
].each do |input_file|
it "runs OK on #{input_file} attributes" do
it "runs OK on #{input_file} inputs" do
cmd = 'exec '
cmd += File.join(inputs_profiles_path, 'basic')
cmd += ' --no-create-lockfile'
@ -21,8 +21,8 @@ describe 'attributes' do
end
end
describe 'run profile with yaml attributes' do
it "runs using yml attributes" do
describe 'run profile with yaml inputs' do
it "runs using yml inputs" do
cmd = 'exec '
cmd += File.join(inputs_profiles_path, 'global')
cmd += ' --no-create-lockfile'
@ -33,7 +33,7 @@ describe 'attributes' do
out.exit_status.must_equal 0
end
it "does not error when attributes are empty" do
it "does not error when inputs are empty" do
cmd = 'exec '
cmd += File.join(inputs_profiles_path, 'metadata-empty')
cmd += ' --no-create-lockfile'
@ -42,17 +42,17 @@ describe 'attributes' do
out.exit_status.must_equal 0
end
it "errors with invalid attribute types" do
it "errors with invalid input types" do
cmd = 'exec '
cmd += File.join(inputs_profiles_path, 'metadata-invalid')
cmd += ' --no-create-lockfile'
out = inspec(cmd)
out.stderr.must_equal "Type 'Color' is not a valid attribute type.\n"
out.stderr.must_equal "Type 'Color' is not a valid input type.\n"
out.stdout.must_equal ''
out.exit_status.must_equal 1
end
it "errors with required attribute not defined" do
it "errors with required input not defined" do
cmd = 'exec '
cmd += File.join(inputs_profiles_path, 'required')
cmd += ' --no-create-lockfile'
@ -61,5 +61,7 @@ describe 'attributes' do
out.stdout.must_equal ''
out.exit_status.must_equal 1
end
# TODO - add test for backwards compatibility using 'attribute' in DSL
end
end

View file

@ -95,7 +95,7 @@ describe 'inspec archive' do
end
end
it 'can archive a profile with required attributes' do
it 'can archive a profile with required inputs' do
archive_depends_path = File.join(profile_path, 'profile-with-required-inputs')
Dir.mktmpdir do |tmpdir|

View file

@ -97,7 +97,7 @@ Test Summary: 0 successful, 0 failures, 0 skipped
"
end
it "executes a profile and reads attributes" do
it "executes a profile and reads inputs" do
out = inspec("exec #{File.join(examples_path, 'profile-attribute')} --no-create-lockfile --attrs #{File.join(examples_path, "profile-attribute.yml")}")
out.stderr.must_equal ''
out.exit_status.must_equal 0

View file

@ -220,7 +220,7 @@ describe 'example inheritance profile' do
end
end
it 'can vendor profile with required attributes' do
it 'can vendor profile with required inputs' do
archive_depends_path = File.join(profile_path, 'profile-with-required-inputs')
Dir.mktmpdir do |tmpdir|

View file

@ -25,7 +25,7 @@ control 'Test audit cookbook json output' do
end
# test kitchen verify attr passthrough
attr = attribute('verifier_attribute', default: 'none')
attr = attribute('verifier_attribute', default: 'none') # TODO: update test-kitchen to replace attribute -> input
control 'validate verifier attribute override' do
describe attr do
it { should eq 'Attribute Override!' }

View file

@ -17,7 +17,7 @@ describe Inspec::CachedFetcher do
'sha256'=>'132j1kjdasfasdoaefaewo12312',
'groups'=>[],
'controls'=>[],
'attributes'=>[],
'inputs'=>[],
'latest_version'=>'' }]
end
before do

View file

@ -10,15 +10,15 @@ tests = expecteds.keys.map do |test_name|
{
name: test_name,
expected: expecteds[test_name],
attr_via_string: attribute(test_name.to_s, value: "#{test_name}_default"),
attr_via_symbol: attribute(test_name, value: "#{test_name}_default"),
input_via_string: attribute(test_name.to_s, value: "#{test_name}_default"),
input_via_symbol: attribute(test_name, value: "#{test_name}_default"),
}
end
control 'flat' do
tests.each do |info|
describe "#{info[:name]} using string key" do
subject { info[:attr_via_string] }
subject { info[:input_via_string] }
it { should eq info[:expected] }
end
end

View file

@ -1,4 +1,4 @@
attr_names = [
input_names = [
:one_level_array,
:two_level_array,
:one_level_hash,
@ -6,12 +6,12 @@ attr_names = [
:hash_of_arrays,
:array_of_hashes,
]
attrs = {}
attr_names.each do |attr_name|
# Store as a symbol-fetched attribute
attrs[attr_name] = attribute(attr_name, value: "#{attr_name}_sym_default")
# .. and store under a string name, as a string-fetched attribute!
attrs[attr_name.to_s] = attribute(attr_name.to_s, value: "#{attr_name}_str_default")
inputs = {}
input_names.each do |input_name|
# Store as a symbol-fetched input
inputs[input_name] = attribute(input_name, value: "#{input_name}_sym_default")
# .. and store under a string name, as a string-fetched input!
inputs[input_name.to_s] = attribute(input_name.to_s, value: "#{input_name}_str_default")
end
# For now, these all use string keys, as that is normal InSpec behavior
@ -19,7 +19,7 @@ end
control 'nested' do
describe 'one_level_array' do
subject { attrs['one_level_array'] }
subject { inputs['one_level_array'] }
it { should be_a_kind_of(Array) }
it { should respond_to(:[])}
its([0]) { should eq 'thing1' }
@ -30,7 +30,7 @@ control 'nested' do
describe 'two_level_array' do
# Access first row
subject { attrs['two_level_array'][0] }
subject { inputs['two_level_array'][0] }
it { should be_a_kind_of(Array) }
it { should respond_to(:[])}
its([0]) { should eq 'row1col1' }
@ -38,7 +38,7 @@ control 'nested' do
end
describe 'one_level_hash' do
subject { attrs['one_level_hash'] }
subject { inputs['one_level_hash'] }
it { should be_a_kind_of(Hash) }
it { should respond_to(:[])}
its(['key1']) { should eq 'value1' }
@ -47,7 +47,7 @@ control 'nested' do
end
describe 'two_level_hash' do
subject { attrs['two_level_hash'] }
subject { inputs['two_level_hash'] }
it { should be_a_kind_of(Hash) }
it { should respond_to(:[])}
its(['key1', 'key11']) { should eq 'value11' }
@ -56,7 +56,7 @@ control 'nested' do
end
describe 'hash_of_arrays' do
subject { attrs['hash_of_arrays'] }
subject { inputs['hash_of_arrays'] }
it { should be_a_kind_of(Hash) }
it { should respond_to(:[])}
its(['key1', 0]) { should eq 'thing11' }
@ -65,7 +65,7 @@ control 'nested' do
end
describe 'array_of_hashes' do
subject { attrs['array_of_hashes'] }
subject { inputs['array_of_hashes'] }
it { should be_a_kind_of(Array) }
it { should respond_to(:[])}

View file

@ -1,7 +1,7 @@
name: attributes
name: inputs
version: 1.0.0
maintainer: inspec@chef.io
title: Attributes
title: Inputs
license: Apache-2.0
supports:
- linux

View file

@ -1,47 +1,47 @@
describe 'test the val_string attribute set in the global inspec.yml' do
describe 'test the val_string input set in the global inspec.yml' do
subject { attribute('val_string') }
it { should cmp 'test-attr' }
end
describe 'test the val_numeric attribute set in the global inspec.yml' do
describe 'test the val_numeric input set in the global inspec.yml' do
subject { attribute('val_numeric') }
it { should cmp 443 }
end
describe 'test the val_boolean attribute set in the global inspec.yml' do
describe 'test the val_boolean input set in the global inspec.yml' do
subject { attribute('val_boolean') }
it { should cmp true }
end
describe 'test the val_regex attribute set in the global inspec.yml' do
describe 'test the val_regex input set in the global inspec.yml' do
subject { attribute('val_regex') }
it { should cmp '/^\d*/'}
end
describe 'test the val_array attribute set in the global inspec.yml' do
describe 'test the val_array input set in the global inspec.yml' do
subject { attribute('val_array') }
check_array = [ 'a', 'b', 'c' ]
it { should cmp check_array }
end
describe 'test the val_hash attribute set in the global inspec.yml' do
describe 'test the val_hash input set in the global inspec.yml' do
subject { attribute('val_hash') }
check_hash = { a: true, b: false, c: '123' }
it { should cmp check_hash }
end
describe 'test attribute when no default or value is set' do
describe 'test input when no default or value is set' do
subject { attribute('val_no_default').respond_to?(:fake_method) }
it { should cmp true }
end
describe 'test attribute with no defualt but has type' do
describe 'test input with no defualt but has type' do
subject { attribute('val_no_default_with_type').respond_to?(:fake_method) }
it { should cmp true }
end
empty_hash_attribute = attribute('val_with_empty_hash_default', {})
describe 'test attribute with default as empty hash' do
subject { empty_hash_attribute }
empty_hash_input = attribute('val_with_empty_hash_default', {})
describe 'test input with default as empty hash' do
subject { empty_hash_input }
it { should cmp 'success' }
end

View file

@ -1,14 +1,14 @@
include_controls 'child_profile_NEW_NAME'
include_controls 'child_profile2' do
control 'test override control on parent using child attribute' do
describe attribute('val_numeric') do
control 'test override control on parent using child input' do
describe input('val_numeric') do
it { should cmp 654321 }
end
end
control 'test override control on parent using parent attribute' do
describe Inspec::AttributeRegistry.find_attribute('val_numeric', 'attributes').value do
control 'test override control on parent using parent input' do
describe Inspec::InputRegistry.find_input('val_numeric', 'inputs').value do
it { should cmp 443 }
end
end

View file

@ -1,29 +1,29 @@
val_user = attribute('val_user', default: 'alice', description: 'An identification for the user')
val_user_override = attribute('val_user_override', default: 'alice', description: 'An identification for the user')
describe 'reading an attribute in a file-level definition with a default value' do
describe 'reading an input in a file-level definition with a default value' do
subject { val_user }
it { should cmp 'alice' }
end
describe 'reading an attribute in a file-level definition with a default value and a value in secrets file' do
describe 'reading an input in a file-level definition with a default value and a value in secrets file' do
subject { val_user_override }
it { should cmp 'bob' }
end
control 'test using an attribute inside a control block as the describe subject' do
control 'test using an input inside a control block as the describe subject' do
desc 'test the val_numeric attr'
describe attribute('val_user') do
it { should cmp 'alice' }
end
end
# test using a attribute outside controls and as the describe subject
# test using a input outside controls and as the describe subject
describe attribute('val_user') do
it { should cmp 'alice' }
end
control "test using attributes in the test it's block" do
control "test using inputs in the test it's block" do
describe 'alice' do
it { should cmp attribute('val_user') }
end

View file

@ -1,5 +1,5 @@
name: attributes
title: InSpec Profile
name: global-inputs
title: Profile to test inputs in a variety of locations
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com

View file

@ -1,5 +1,5 @@
name: profile-with-required-attributes
title: InSpec example for attributes override
name: profile-with-required-inputs
title: InSpec example for inputs override
maintainer: Chef Software, Inc.
copyright: Chef Software, Inc.
copyright_email: support@chef.io

View file

@ -44,7 +44,7 @@ class PluginV2BaseDslMethods < MiniTest::Test
[
:plugin_name,
:mock_plugin_type,
# [ :attribute_provider, :platform, :fetcher, :source_reader, :control_dsl, :reporter ]
# [ :input_provider, :platform, :fetcher, :source_reader, :reporter ]
].each do |method_name|
klass = Inspec::Plugin::V2::PluginBase
assert_respond_to klass, method_name, 'Plugin DSL methods'

View file

@ -24,7 +24,6 @@ module PluginV2BackCompat
assert_equal Inspec::Plugins::SourceReader, klass
end
# TODO: rename to attribute_provider?
def test_get_plugin_v1_base_for_secrets
klass = Inspec.secrets(1)
assert_kind_of Class, klass

View file

@ -135,7 +135,7 @@ describe Inspec::Reporters::Json do
release: '17.*',
},
],
attributes: [],
attributes: [], # TODO: rename attributes in json reporter
}
profile = report.send(:profiles).first
profile.delete(:groups)

View file

@ -38,7 +38,7 @@ module MockAwsBillingReports
#
# == Returns:
# A Aws::CostandUsageReportService::Types::DescribeReportDefinitionsRespons object with two instance
# attributes:
# properties:
# `report_definitions` An Array that includes a single page of 5 Reports.
# `next_token` A String set to the start of the next page. When `next_token` is nil, there are no more pages.
#

View file

@ -28,25 +28,25 @@ describe 'Inspec::Resources::EtcHostsAllow' do
resource = load_resource('etc_hosts_allow')
it 'parses a line with multiple clients' do
line = 'foo: client1, client2 : some_option'
attributes = resource.send(:parse_line, line)
_(attributes['daemon']).must_equal 'foo'
_(attributes['client_list']).must_equal ['client1', 'client2']
entry_properties = resource.send(:parse_line, line)
_(entry_properties['daemon']).must_equal 'foo'
_(entry_properties['client_list']).must_equal ['client1', 'client2']
end
it 'parses a line with one option' do
line = 'foo: client1, client2 : some_option'
attributes = resource.send(:parse_line, line)
_(attributes['daemon']).must_equal 'foo'
_(attributes['client_list']).must_equal ['client1', 'client2']
_(attributes['options']).must_equal ['some_option']
entry_properties = resource.send(:parse_line, line)
_(entry_properties['daemon']).must_equal 'foo'
_(entry_properties['client_list']).must_equal ['client1', 'client2']
_(entry_properties['options']).must_equal ['some_option']
end
it 'parses a line with multiple options' do
line = 'foo: client1, client2 : some_option : other_option'
attributes = resource.send(:parse_line, line)
_(attributes['daemon']).must_equal 'foo'
_(attributes['client_list']).must_equal ['client1', 'client2']
_(attributes['options']).must_equal ['some_option', 'other_option']
entry_properties = resource.send(:parse_line, line)
_(entry_properties['daemon']).must_equal 'foo'
_(entry_properties['client_list']).must_equal ['client1', 'client2']
_(entry_properties['options']).must_equal ['some_option', 'other_option']
end
end
end

View file

@ -25,7 +25,7 @@ describe 'Inspec::Resources::PGHbaConf' do
_(entries.type).must_include 'hostssl'
_(entries.database).must_include 'acme_test'
end
it 'Verify postgres_hba_conf attributes' do
it 'Verify postgres_hba_conf properties' do
_(resource.auth_method).must_include 'cert'
_(resource.database).must_include 'acme_test'
_(resource.type).must_include 'hostssl'

View file

@ -92,7 +92,7 @@ describe 'Inspec::Resources::Processes' do
})
end
it 'access attributes of a process' do
it 'access information of a process' do
resource = MockLoader.new(:centos6).load_resource('processes', 'postgres: bifrost bifrost')
process = resource.entries[0]
process.user.must_equal 'opscode-pgsql'

View file

@ -4,11 +4,11 @@
require 'helper'
describe Inspec::Runner do
describe '#load_attributes' do
describe '#load_inputs' do
let(:runner) { Inspec::Runner.new({ command_runner: :generic }) }
before do
Inspec::Runner.any_instance.stubs(:validate_attributes_file_readability!)
Inspec::Runner.any_instance.stubs(:validate_inputs_file_readability!)
end
describe 'confirm reporter defaults to cli' do
@ -68,7 +68,7 @@ describe Inspec::Runner do
describe 'when no attrs are specified' do
it 'returns an empty hash' do
options = {}
runner.load_attributes(options).must_equal({})
runner.load_inputs(options).must_equal({})
end
end
@ -76,28 +76,28 @@ describe Inspec::Runner do
it 'raises an exception' do
options = { attrs: ['nope.jpg'] }
Inspec::SecretsBackend.expects(:resolve).with('nope.jpg').returns(nil)
proc { runner.load_attributes(options) }.must_raise Inspec::Exceptions::SecretsBackendNotFound
proc { runner.load_inputs(options) }.must_raise Inspec::Exceptions::SecretsBackendNotFound
end
end
describe 'when an attr is provided and has no attributes' do
describe 'when an attr is provided and has no inputs' do
it 'returns an empty hash' do
secrets = mock
secrets.stubs(:attributes).returns(nil)
secrets.stubs(:inputs).returns(nil)
options = { attrs: ['empty.yaml'] }
Inspec::SecretsBackend.expects(:resolve).with('empty.yaml').returns(secrets)
runner.load_attributes(options).must_equal({})
runner.load_inputs(options).must_equal({})
end
end
describe 'when an attr is provided and has attributes' do
it 'returns a hash containing the attributes' do
describe 'when an attr is provided and has inputs' do
it 'returns a hash containing the inputs' do
options = { attrs: ['file1.yaml'] }
attributes = { foo: 'bar' }
inputs = { foo: 'bar' }
secrets = mock
secrets.stubs(:attributes).returns(attributes)
secrets.stubs(:inputs).returns(inputs)
Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets)
runner.load_attributes(options).must_equal(attributes)
runner.load_inputs(options).must_equal(inputs)
end
end
@ -105,37 +105,37 @@ describe Inspec::Runner do
it 'raises an exception' do
options = { attrs: ['file1.yaml', 'file2.yaml'] }
secrets = mock
secrets.stubs(:attributes).returns(nil)
secrets.stubs(:inputs).returns(nil)
Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets)
Inspec::SecretsBackend.expects(:resolve).with('file2.yaml').returns(nil)
proc { runner.load_attributes(options) }.must_raise Inspec::Exceptions::SecretsBackendNotFound
proc { runner.load_inputs(options) }.must_raise Inspec::Exceptions::SecretsBackendNotFound
end
end
describe 'when multiple attrs are provided and one has no attributes' do
it 'returns a hash containing the attributes from the valid files' do
describe 'when multiple attrs are provided and one has no inputs' do
it 'returns a hash containing the inputs from the valid files' do
options = { attrs: ['file1.yaml', 'file2.yaml'] }
attributes = { foo: 'bar' }
inputs = { foo: 'bar' }
secrets1 = mock
secrets1.stubs(:attributes).returns(nil)
secrets1.stubs(:inputs).returns(nil)
secrets2 = mock
secrets2.stubs(:attributes).returns(attributes)
secrets2.stubs(:inputs).returns(inputs)
Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets1)
Inspec::SecretsBackend.expects(:resolve).with('file2.yaml').returns(secrets2)
runner.load_attributes(options).must_equal(attributes)
runner.load_inputs(options).must_equal(inputs)
end
end
describe 'when multiple attrs are provided and all have attributes' do
it 'returns a hash containing all the attributes' do
describe 'when multiple attrs are provided and all have inputs' do
it 'returns a hash containing all the inputs' do
options = { attrs: ['file1.yaml', 'file2.yaml'] }
secrets1 = mock
secrets1.stubs(:attributes).returns({ key1: 'value1' })
secrets1.stubs(:inputs).returns({ key1: 'value1' })
secrets2 = mock
secrets2.stubs(:attributes).returns({ key2: 'value2' })
secrets2.stubs(:inputs).returns({ key2: 'value2' })
Inspec::SecretsBackend.expects(:resolve).with('file1.yaml').returns(secrets1)
Inspec::SecretsBackend.expects(:resolve).with('file2.yaml').returns(secrets2)
runner.load_attributes(options).must_equal({ key1: 'value1', key2: 'value2' })
runner.load_inputs(options).must_equal({ key1: 'value1', key2: 'value2' })
end
end
end