2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/parse_config"
|
2016-08-05 10:07:14 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::ParseConfig" do
|
2016-08-05 10:07:14 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify parse_config resource" do
|
2016-08-05 10:07:14 +00:00
|
|
|
options = {
|
2019-06-11 22:24:35 +00:00
|
|
|
assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
|
2016-08-05 10:07:14 +00:00
|
|
|
}
|
2019-06-11 22:24:35 +00:00
|
|
|
resource = MockLoader.new(:centos6).load_resource("parse_config", "kernel.domainname = example.com", options)
|
|
|
|
result = { "kernel.domainname" => "example.com" }
|
2016-08-05 10:07:14 +00:00
|
|
|
_(resource.params).must_equal result
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.content).must_equal "kernel.domainname = example.com"
|
|
|
|
_(resource.send("kernel.domainname")).must_equal "example.com"
|
2016-08-05 10:07:14 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify parse_config_file resource" do
|
2016-08-05 10:07:14 +00:00
|
|
|
options = {
|
2019-06-11 22:24:35 +00:00
|
|
|
assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
|
2016-08-05 10:07:14 +00:00
|
|
|
}
|
2019-06-11 22:24:35 +00:00
|
|
|
resource = MockLoader.new(:centos6).load_resource("parse_config_file", "/etc/sysctl.conf", options)
|
|
|
|
result = { "kernel.domainname" => "example.com" }
|
2016-08-05 10:07:14 +00:00
|
|
|
_(resource.params).must_equal result
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.send("kernel.domainname")).must_equal "example.com"
|
2016-08-05 10:07:14 +00:00
|
|
|
end
|
2020-09-15 15:43:30 +00:00
|
|
|
|
|
|
|
it "parse_config resource accepts arrays due to rspec's its behavior" do
|
|
|
|
options = {
|
|
|
|
assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
|
|
|
|
}
|
|
|
|
params = [:[], "kernel.domainname"]
|
|
|
|
resource = MockLoader.new(:centos6).load_resource("parse_config", "kernel.domainname = example.com", options)
|
|
|
|
_(resource.send(*params)).must_equal "example.com"
|
|
|
|
end
|
2016-08-05 10:07:14 +00:00
|
|
|
end
|