2019-06-11 22:24:35 +00:00
|
|
|
require "minitest/autorun"
|
|
|
|
require "tmpdir"
|
2019-11-09 03:08:20 +00:00
|
|
|
require "helpers/mock_loader"
|
2019-06-11 22:24:35 +00:00
|
|
|
require_relative "../../../../lib/inspec/plugin/v2"
|
2018-11-16 22:03:09 +00:00
|
|
|
|
|
|
|
# This file relies on setting environment variables for some
|
|
|
|
# of its tests - it is NOT thread-safe.
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Plugin::V2::ConfigFile" do
|
|
|
|
orig_home = ENV["HOME"]
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-11-09 03:08:20 +00:00
|
|
|
let(:repo_path) { MockLoader.home }
|
|
|
|
let(:config_fixtures_path) { "#{repo_path}/test/fixtures/config_dirs" }
|
2018-11-16 22:03:09 +00:00
|
|
|
let(:config_file_obj) { Inspec::Plugin::V2::ConfigFile.new(constructor_arg) }
|
2019-11-09 03:08:20 +00:00
|
|
|
let(:constructor_arg) { "#{config_fixtures_path}/plugin_config_files/#{fixture_name}.json" }
|
2018-11-16 22:03:09 +00:00
|
|
|
|
|
|
|
after do
|
2019-06-11 22:24:35 +00:00
|
|
|
ENV["HOME"] = orig_home
|
|
|
|
ENV["INSPEC_CONFIG_DIR"] = nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Path Handling
|
|
|
|
#----------------------------------------------------------#
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "locating the file" do
|
|
|
|
describe "when no env var is set" do
|
2018-11-16 22:03:09 +00:00
|
|
|
let(:constructor_arg) { nil }
|
2019-06-11 22:24:35 +00:00
|
|
|
it "defaults to the home directory" do
|
|
|
|
ENV["HOME"] = File.join(config_fixtures_path, "fakehome")
|
|
|
|
expected_path = File.join(ENV["HOME"], ".inspec", "plugins.json")
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.path).must_equal expected_path
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when an env var is set" do
|
2018-11-16 22:03:09 +00:00
|
|
|
let(:constructor_arg) { nil }
|
2019-06-11 22:24:35 +00:00
|
|
|
it "looks to the dir specified by the env var" do
|
|
|
|
ENV["INSPEC_CONFIG_DIR"] = File.join(config_fixtures_path, "meaning-by-path")
|
|
|
|
expected_path = File.join(ENV["INSPEC_CONFIG_DIR"], "plugins.json")
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.path).must_equal expected_path
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when a path is provided to the constructor" do
|
|
|
|
let(:fixture_name) { "no_plugins" }
|
|
|
|
it "uses the provided path" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.path).must_equal constructor_arg
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Reading a File
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "reading the file" do
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the file is missing" do
|
|
|
|
let(:fixture_name) { "nonesuch" }
|
|
|
|
it "creates a empty datastructure" do
|
2018-11-16 22:03:09 +00:00
|
|
|
Dir.mktmpdir do |tmp_dir|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 0
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the file is corrupt" do
|
|
|
|
let(:fixture_name) { "corrupt" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Failed to load")
|
|
|
|
_(ex.message).must_include("JSON")
|
|
|
|
_(ex.message).must_include("unexpected token")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the file is valid" do
|
|
|
|
let(:fixture_name) { "basic" }
|
|
|
|
it "can count plugins" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 3
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can look up plugins by name with a String" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.plugin_by_name("inspec-test-fixture-01")).wont_be_nil
|
|
|
|
_(config_file_obj.plugin_by_name("inspec-test-fixture-99")).must_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can look up plugins by name with a Symbol" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture-01')).wont_be_nil
|
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture-99')).must_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "symbolizes the keys of the entries" do
|
2018-11-16 22:03:09 +00:00
|
|
|
config_file_obj.each do |entry|
|
|
|
|
entry.keys.each do |key|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(key).must_be_kind_of(Symbol)
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "implements Enumerable" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.select { |entry| entry[:name].to_s.start_with?("inspec-test-fixture") }.count).must_equal 3
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Validation
|
|
|
|
#----------------------------------------------------------#
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the file is invalid" do
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because the file version is wrong" do
|
|
|
|
let(:fixture_name) { "bad_plugin_conf_version" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Unsupported")
|
|
|
|
_(ex.message).must_include("version")
|
|
|
|
_(ex.message).must_include("99.99.9")
|
|
|
|
_(ex.message).must_include("1.0.0")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because the file version is missing" do
|
|
|
|
let(:fixture_name) { "missing_plugin_conf_version" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Missing")
|
|
|
|
_(ex.message).must_include("version")
|
|
|
|
_(ex.message).must_include("1.0.0")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because the plugins field is missing" do
|
|
|
|
let(:fixture_name) { "missing_plugins_key" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("missing")
|
|
|
|
_(ex.message).must_include("'plugins'")
|
|
|
|
_(ex.message).must_include("array")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because the plugins field is not an array" do
|
|
|
|
let(:fixture_name) { "hash_plugins_key" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Malformed")
|
|
|
|
_(ex.message).must_include("'plugins'")
|
|
|
|
_(ex.message).must_include("array")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because a plugin entry is not a hash" do
|
|
|
|
let(:fixture_name) { "entry_not_hash" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Malformed")
|
|
|
|
_(ex.message).must_include("Hash")
|
|
|
|
_(ex.message).must_include("at index 2")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because it contains duplicate plugin entries" do
|
|
|
|
let(:fixture_name) { "entry_duplicate" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Malformed")
|
|
|
|
_(ex.message).must_include("duplicate")
|
|
|
|
_(ex.message).must_include("inspec-test-fixture-01")
|
|
|
|
_(ex.message).must_include("at index 1 and 3")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because a plugin entry does not have a name" do
|
|
|
|
let(:fixture_name) { "entry_no_name" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Malformed")
|
|
|
|
_(ex.message).must_include("missing 'name'")
|
|
|
|
_(ex.message).must_include("at index 1")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because a plugin entry has an unrecognized installation type" do
|
|
|
|
let(:fixture_name) { "entry_bad_installation_type" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Malformed")
|
|
|
|
_(ex.message).must_include("unrecognized installation_type")
|
|
|
|
_(ex.message).must_include("one of 'gem' or 'path'")
|
|
|
|
_(ex.message).must_include("at index 1")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "because a path plugin entry does not have a path" do
|
|
|
|
let(:fixture_name) { "entry_no_path_for_path_type" }
|
|
|
|
it "throws an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include("Malformed")
|
|
|
|
_(ex.message).must_include("missing installation path")
|
|
|
|
_(ex.message).must_include("at index 2")
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "modifying the conf file" do
|
2018-11-16 22:03:09 +00:00
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Adding Entries
|
|
|
|
#----------------------------------------------------------#
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "adding an entry" do
|
|
|
|
let(:fixture_name) { "no_plugins" }
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the conf is empty" do
|
|
|
|
it "should add one valid entry" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 0
|
2019-06-11 22:24:35 +00:00
|
|
|
config_file_obj.add_entry(name: "inspec-test-fixture")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 1
|
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture')).wont_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the conf has entries" do
|
|
|
|
let(:fixture_name) { "basic" }
|
|
|
|
it "should append one valid entry" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 3
|
2019-06-11 22:24:35 +00:00
|
|
|
config_file_obj.add_entry(name: "inspec-test-fixture-03")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 4
|
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture-03')).wont_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when adding a gem entry" do
|
|
|
|
it "should add a gem entry" do
|
2018-11-16 22:03:09 +00:00
|
|
|
config_file_obj.add_entry(
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "inspec-test-fixture-03",
|
|
|
|
installation_type: :gem
|
2018-11-16 22:03:09 +00:00
|
|
|
)
|
|
|
|
entry = config_file_obj.plugin_by_name(:'inspec-test-fixture-03')
|
2019-09-30 22:31:55 +00:00
|
|
|
_(entry).wont_be_nil
|
|
|
|
_(entry[:installation_type]).must_equal :gem
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when adding a path entry" do
|
|
|
|
it "should add a path entry" do
|
2018-11-16 22:03:09 +00:00
|
|
|
config_file_obj.add_entry(
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "inspec-test-fixture-03",
|
2018-11-16 22:03:09 +00:00
|
|
|
installation_type: :path,
|
2019-06-11 22:24:35 +00:00
|
|
|
installation_path: "/my/path.rb"
|
2018-11-16 22:03:09 +00:00
|
|
|
)
|
|
|
|
entry = config_file_obj.plugin_by_name(:'inspec-test-fixture-03')
|
2019-09-30 22:31:55 +00:00
|
|
|
_(entry).wont_be_nil
|
|
|
|
_(entry[:installation_type]).must_equal :path
|
|
|
|
_(entry[:installation_path]).must_equal "/my/path.rb"
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when adding a duplicate plugin name" do
|
|
|
|
let(:fixture_name) { "basic" }
|
|
|
|
it "should throw an exception" do
|
|
|
|
assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj.add_entry(name: "inspec-test-fixture-02") }
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when adding an invalid entry" do
|
|
|
|
it "should throw an exception" do
|
2018-11-16 22:03:09 +00:00
|
|
|
[
|
2019-06-11 22:24:35 +00:00
|
|
|
{ name: "inspec-test-fixture", installation_type: :path },
|
|
|
|
{ installation_type: :gem },
|
|
|
|
{ name: "inspec-test-fixture", installation_type: :invalid },
|
|
|
|
{ "name" => "inspec-test-fixture" },
|
2018-11-16 22:03:09 +00:00
|
|
|
].each do |proposed_entry|
|
|
|
|
assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj.add_entry(proposed_entry) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Removing Entries
|
|
|
|
#----------------------------------------------------------#
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "removing an entry" do
|
|
|
|
let(:fixture_name) { "basic" }
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the entry exists" do
|
|
|
|
it "should remove the entry by symbol name" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 3
|
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture-01')).wont_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
config_file_obj.remove_entry(:'inspec-test-fixture-01')
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 2
|
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture-01')).must_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "should remove the entry by String name" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 3
|
|
|
|
_(config_file_obj.plugin_by_name("inspec-test-fixture-01")).wont_be_nil
|
2019-06-11 22:24:35 +00:00
|
|
|
config_file_obj.remove_entry("inspec-test-fixture-01")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 2
|
|
|
|
_(config_file_obj.plugin_by_name("inspec-test-fixture-01")).must_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the entry does not exist" do
|
|
|
|
let(:fixture_name) { "basic" }
|
|
|
|
it "should throw an exception" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config_file_obj.count).must_equal 3
|
|
|
|
_(config_file_obj.plugin_by_name(:'inspec-test-fixture-99')).must_be_nil
|
2018-11-16 22:03:09 +00:00
|
|
|
ex = assert_raises(Inspec::Plugin::V2::ConfigError) { config_file_obj.remove_entry(:'inspec-test-fixture-99') }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(ex.message).must_include "No such entry"
|
|
|
|
_(ex.message).must_include "inspec-test-fixture-99"
|
|
|
|
_(config_file_obj.count).must_equal 3
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "writing the file" do
|
|
|
|
let(:fixture_name) { "unused" }
|
2018-11-16 22:03:09 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the file does not exist" do
|
|
|
|
it "is created" do
|
2018-11-16 22:03:09 +00:00
|
|
|
Dir.mktmpdir do |tmp_dir|
|
2019-06-11 22:24:35 +00:00
|
|
|
path = File.join(tmp_dir, "plugins.json")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(path)).must_equal false
|
2018-11-16 22:03:09 +00:00
|
|
|
cfo_writer = Inspec::Plugin::V2::ConfigFile.new(path)
|
|
|
|
cfo_writer.add_entry(name: :'inspec-resource-lister')
|
|
|
|
cfo_writer.save
|
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(path)).must_equal true
|
2018-11-16 22:03:09 +00:00
|
|
|
cfo_reader = Inspec::Plugin::V2::ConfigFile.new(path)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cfo_reader.existing_entry?(:'inspec-resource-lister')).must_equal true
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the directory does not exist" do
|
|
|
|
it "is created" do
|
2018-11-16 22:03:09 +00:00
|
|
|
Dir.mktmpdir do |tmp_dir|
|
2019-06-11 22:24:35 +00:00
|
|
|
path = File.join(tmp_dir, "subdir", "plugins.json")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(path)).must_equal false
|
2018-11-16 22:03:09 +00:00
|
|
|
cfo_writer = Inspec::Plugin::V2::ConfigFile.new(path)
|
|
|
|
cfo_writer.add_entry(name: :'inspec-resource-lister')
|
|
|
|
cfo_writer.save
|
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(path)).must_equal true
|
2018-11-16 22:03:09 +00:00
|
|
|
cfo_reader = Inspec::Plugin::V2::ConfigFile.new(path)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cfo_reader.existing_entry?(:'inspec-resource-lister')).must_equal true
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the file does exist" do
|
|
|
|
it "is overwritten" do
|
2018-11-16 22:03:09 +00:00
|
|
|
Dir.mktmpdir do |tmp_dir|
|
2019-06-11 22:24:35 +00:00
|
|
|
path = File.join(tmp_dir, "plugins.json")
|
2018-11-16 22:03:09 +00:00
|
|
|
cfo_writer = Inspec::Plugin::V2::ConfigFile.new(path)
|
|
|
|
cfo_writer.add_entry(name: :'inspec-resource-lister')
|
|
|
|
cfo_writer.save
|
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(File.exist?(path)).must_equal true
|
2018-11-16 22:03:09 +00:00
|
|
|
|
|
|
|
cfo_modifier = Inspec::Plugin::V2::ConfigFile.new(path)
|
|
|
|
cfo_modifier.remove_entry(:'inspec-resource-lister')
|
|
|
|
cfo_modifier.add_entry(name: :'inspec-test-fixture')
|
|
|
|
cfo_modifier.save
|
|
|
|
|
|
|
|
cfo_reader = Inspec::Plugin::V2::ConfigFile.new(path)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cfo_reader.existing_entry?(:'inspec-resource-lister')).must_equal false
|
|
|
|
_(cfo_reader.existing_entry?(:'inspec-test-fixture')).must_equal true
|
2018-11-16 22:03:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-24 00:21:31 +00:00
|
|
|
end
|