2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/runner_mock"
|
|
|
|
require "inspec/runner"
|
2017-04-26 00:47:01 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec keyword" do
|
2017-04-26 00:47:01 +00:00
|
|
|
def load(content)
|
2019-06-11 22:24:35 +00:00
|
|
|
runner = Inspec::Runner.new({ backend: "mock", test_collector: Inspec::RunnerMock.new })
|
2017-06-15 16:10:47 +00:00
|
|
|
runner.eval_with_virtual_profile(content)
|
2017-04-26 00:47:01 +00:00
|
|
|
end
|
|
|
|
|
2017-04-26 01:07:39 +00:00
|
|
|
def load_in_profile(cmd)
|
2019-06-11 22:24:35 +00:00
|
|
|
MockLoader.load_profile("complete-profile").runner_context.load(cmd)
|
2017-04-26 01:07:39 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "is a vailable as a global keyword" do
|
|
|
|
load("inspec") # wont raise anything
|
2017-04-26 01:03:53 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "is a vailable inside of control blocks" do
|
|
|
|
load("control 1 do inspec end") # wont raise anything
|
2017-04-26 01:03:53 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "provides version information" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(load("inspec.version")).must_equal Inspec::VERSION
|
2017-04-26 01:04:59 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "is associated with resources" do
|
|
|
|
i = load("os.inspec")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(i).wont_be_nil
|
|
|
|
_(i.backend).must_be_kind_of Train::Transports::Mock::Connection
|
2017-04-26 00:47:01 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "prints a nice to_s" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(load("inspec").to_s).must_equal "Inspec::Backend::Class"
|
2017-04-26 00:47:01 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "prints a nice inspect line" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(load("inspec").inspect).must_equal "Inspec::Backend::Class @transport=Train::Transports::Mock::Connection"
|
2017-04-26 00:47:01 +00:00
|
|
|
end
|
2017-04-26 01:07:39 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec.profile.files" do
|
|
|
|
it "lists an empty array when calling #files without any files loaded" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(load("inspec.profile.files")).must_equal([])
|
2017-04-26 01:07:39 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "lists all profile files when calling #files" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(load_in_profile("inspec.profile.files").sort).must_equal %w{a_sub_dir/sub_items.conf items.conf}
|
2017-04-26 01:07:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec.profile.file" do
|
|
|
|
it "raises an error if a file was not found" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(proc { load('inspec.profile.file("test")') }).must_raise RuntimeError
|
2017-04-26 01:07:39 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "provides file contents when calling file(...)" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(load_in_profile('inspec.profile.file("items.conf")')).must_equal "one\ntwo\nthree\n"
|
2017-04-26 01:07:39 +00:00
|
|
|
end
|
|
|
|
end
|
2017-04-26 00:47:01 +00:00
|
|
|
end
|