mirror of
https://github.com/inspec/inspec
synced 2024-12-21 10:33:23 +00:00
811318f2f8
* Functional tests for userdir option * Accepts --config-dir CLI option * Actually loads a config file from the config dir, more cases to test * Able to load config and verify contents from config-dir * Functional tests to ensure precedence for config options * Enable setting config dir via env var * .inspec, not .inspec.d * Begin converting PluginCtl to PluginLoader/Registry * Able to load and partially validate the plugins.json file * More work on the plugin loader * Break the world, move next gen stuff to plugin/ * Be sure to require base cli in bundled plugins * Move test file * Revert changes to v1 plugin, so we can have a separate one * Checkpoint commit * Move v2 plugin work to v2 area * Move plugins v1 code into an isolated directory * rubocop fixes * Rip out the stuff about a user-dir config file, just use a plugin file * Two psuedocode test file * Working base API, moock plugin type, and loader. * Adjust load path to be more welcoming * Silence circular depencency warning, which was breaking a unit test * Linting * Fix plugin type registry, add tests to cover * Feedback from Jerry Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
87 lines
2.2 KiB
Ruby
87 lines
2.2 KiB
Ruby
require 'helper'
|
|
|
|
describe Inspec::Plugins::Resource do
|
|
let(:base) { Inspec::Plugins::Resource }
|
|
|
|
describe '#name' do
|
|
it "won't register a nil resource" do
|
|
Class.new(base) do name nil; end
|
|
Inspec::Resource.registry.keys.wont_include nil
|
|
Inspec::Resource.registry.keys.wont_include ''
|
|
end
|
|
|
|
it "will register a valid name" do
|
|
Class.new(base) do name 'hello'; end
|
|
Inspec::Resource.registry['hello'].wont_be :nil?
|
|
end
|
|
end
|
|
|
|
def create(&block)
|
|
random_name = (0...50).map { (65 + rand(26)).chr }.join
|
|
Class.new(base) do
|
|
name random_name
|
|
instance_eval(&block)
|
|
end
|
|
Inspec::Resource.registry[random_name]
|
|
end
|
|
|
|
describe '#desc' do
|
|
it "will register a description" do
|
|
expected = rand.to_s
|
|
create { desc expected }.desc.must_equal expected
|
|
end
|
|
|
|
it "can change the description" do
|
|
c = create { desc rand.to_s }
|
|
c.desc(x = rand.to_s)
|
|
c.desc.must_equal x
|
|
end
|
|
end
|
|
|
|
describe '#example' do
|
|
it "will register a description" do
|
|
expected = rand.to_s
|
|
create { example expected }.example.must_equal expected
|
|
end
|
|
|
|
it "can change the description" do
|
|
c = create { example rand.to_s }
|
|
c.example(x = rand.to_s)
|
|
c.example.must_equal x
|
|
end
|
|
end
|
|
|
|
describe 'supported platform' do
|
|
def supports_meta(supports)
|
|
Inspec::Resource.supports['os'] = supports
|
|
load_resource('os')
|
|
end
|
|
|
|
it 'loads a profile which supports multiple families' do
|
|
m = supports_meta([
|
|
{ os_family: 'windows' },
|
|
{ os_family: 'unix' }
|
|
])
|
|
m.check_supports.must_equal true
|
|
Inspec::Resource.supports['os'] = nil
|
|
end
|
|
|
|
it 'loads a profile which supports multiple names' do
|
|
m = supports_meta([
|
|
{ os_family: 'windows', os_name: 'windows_2000'},
|
|
{ os_family: 'unix', os_name: 'ubuntu' }
|
|
])
|
|
m.check_supports.must_equal true
|
|
Inspec::Resource.supports['os'] = nil
|
|
end
|
|
|
|
it 'reject a profile which supports multiple families' do
|
|
m = supports_meta([
|
|
{ os_family: 'windows' },
|
|
{ os_family: 'redhat' }
|
|
])
|
|
m.check_supports.must_equal false
|
|
Inspec::Resource.supports['os'] = nil
|
|
end
|
|
end
|
|
end
|