Failing tests for input plugin

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-05-02 13:24:18 -04:00
parent 82f910e320
commit 962dfc8d90
10 changed files with 141 additions and 0 deletions

View file

@ -1,5 +1,7 @@
require 'functional/helper'
# For tests related to reading inputs from plugins, see plugins_test.rb
describe 'inputs' do
include FunctionalHelper
let(:inputs_profiles_path) { File.join(profile_path, 'inputs') }

View file

@ -95,6 +95,55 @@ describe 'cli command plugins' do
end
end
#=========================================================================================#
# Input plugin type
#=========================================================================================#
describe 'input plugins' do
include FunctionalHelper
let(:env) { { INSPEC_CONFIG_DIR: "#{config_dir_path}/input_plugin") }
let(:profile) { "#{profile_path}/inputs/plugin" }
describe 'when an input is provided only by a plugin' do
it 'should find the value' do
controls = 'only_in_plugin'
cmd = "exec #{profile} --controls #{controls}"
run_result = run_inspec_process(cmd, json: true, env: env)
run_result.must_have_all_controls_passing
run_result.stderr.must_be_empty
end
end
describe 'when an input is provided both inline and by a higher-precedence plugin' do
it 'should use the value from the plugin' do
controls = 'collide_plugin_higher'
cmd = "exec #{profile} --controls #{controls}"
run_result = run_inspec_process(cmd, json: true, env: env)
run_result.must_have_all_controls_passing
run_result.stderr.must_be_empty
end
end
describe 'when an input is provided both inline and by a lower-precedence plugin' do
it 'should use the value from inline' do
controls = 'collide_inline_higher'
cmd = "exec #{profile} --controls #{controls}"
run_result = run_inspec_process(cmd, json: true, env: env)
run_result.must_have_all_controls_passing
run_result.stderr.must_be_empty
end
end
describe 'when listing available inputs' do
it 'should list available inputs' do
controls = 'list_inputs'
cmd = "exec #{profile} --controls #{controls}"
run_result = run_inspec_process(cmd, json: true, env: env)
run_result.must_have_all_controls_passing
run_result.stderr.must_be_empty
end
end
end
#=========================================================================================#
# inspec plugin command
#=========================================================================================#

View file

@ -0,0 +1,10 @@
{
"plugins_config_version" : "1.0.0",
"plugins": [
{
"name": "inspec-input-test-fixture",
"installation_type": "path",
"installation_path": "test/unit/mock/plugins/inspec-input-test-fixture/lib/inspec-input-test-fixture.rb"
}
]
}

View file

@ -0,0 +1,3 @@
# inspec-input-test-fixture
Input plugin used to test input plugin type in test/functional/plugins_test.rb

View file

@ -0,0 +1,4 @@
libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
require 'inspec-input-test-fixture/plugin'

View file

@ -0,0 +1,9 @@
module InspecPlugins::InputTestFixture
class InputImplementation < Inspec.plugin(2, :input)
# TODO
# fetch?
# default_priority?
# list_profiles?
# list_inputs?
end
end

View file

@ -0,0 +1,13 @@
require 'inspec-input-test-fixture/version'
module InspecPlugins
module InputTestFixture
class Plugin < ::Inspec.plugin(2)
plugin_name :'inspec-input-test-fixture'
input :test_fixture do
require 'inspec-inspec-test-fixture/input'
InspecPlugins::InputTestFixture::InputImplementation
end
end
end
end

View file

@ -0,0 +1,5 @@
module InspecPlugins
module InputTestFixture
VERSION = '0.1.0'.freeze
end
end

View file

@ -0,0 +1,38 @@
control 'only_in_plugin' do
describe attribute('test_only_in_plugin') do
it { should cmp 'only_in_plugin' }
end
end
control 'collide_plugin_higher' do
describe attribute('test_collide_plugin_higher', value: 'wrong', priority: 10) do
it { should cmp 'collide_plugin_higher' }
end
end
control 'collide_inline_higher' do
describe attribute('test_collide_inline_higher', value: 'collide_inline_higher', priority: 70) do
it { should cmp 'collide_inline_higher' }
end
end
control 'list_inputs' do
inputs = Inspec::InputRegistry.list_inputs_for_profile(:'input-test-fixture')
describe inputs do
it { should_not be_nil }
it { should be_kind_of Hash }
end
describe inputs.keys do
[
'test_only_in_plugin',
'test_collide_inline_higher',
'test_collide_plugin_higher',
'test_not_mentioned_inline',
].each do |input_name|
it { should include input_name }
end
it { should_not include 'nonesuch' }
end
end

View file

@ -0,0 +1,8 @@
name: input-test-fixture
title: A title
maintainer: Chef InSpec team
copyright: Chef InSpec team
copyright_email: inspec@chef.io
license: Apache-2.0
summary: Profile to test reading and listing inputs from a plugin
version: 0.1.0