2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/file"
|
|
|
|
require "inspec/resources/virtualization"
|
2018-02-28 19:22:55 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Virtualization" do
|
2019-01-13 05:48:42 +00:00
|
|
|
def mock_proc(mocked_files)
|
|
|
|
proc do |filename|
|
|
|
|
OpenStruct.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
exist?: mocked_files.include?(filename) ? false : true
|
2019-01-13 05:48:42 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2018-02-28 19:22:55 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "fails the resource if OS is not Linux" do
|
2019-01-13 05:48:42 +00:00
|
|
|
mocked_files = []
|
|
|
|
mock_loader = MockLoader.new(:windows)
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2019-01-13 05:48:42 +00:00
|
|
|
mock_loader.backend.stub :file, mock_proc(mocked_files) do
|
2019-06-11 22:24:35 +00:00
|
|
|
mock_resource = mock_loader.load_resource("virtualization")
|
2019-01-13 05:48:42 +00:00
|
|
|
mock_resource.resource_failed?.must_equal true
|
|
|
|
end
|
2018-02-28 19:22:55 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns nil for all properties if no virutalization platform is found" do
|
2019-01-13 05:48:42 +00:00
|
|
|
mocked_files = [
|
2019-06-11 22:24:35 +00:00
|
|
|
"/proc/xen/capabilities",
|
|
|
|
"/proc/modules",
|
|
|
|
"/proc/cpuinfo",
|
|
|
|
"/sys/devices/virtual/misc/kvm",
|
|
|
|
"/proc/bc/0",
|
|
|
|
"/proc/vz",
|
|
|
|
"/proc/bus/pci/devices",
|
|
|
|
"/proc/self/status",
|
|
|
|
"/proc/self/cgroup",
|
|
|
|
"/.dockerenv",
|
|
|
|
"/.dockerinit",
|
|
|
|
"/dev/lxd/sock",
|
|
|
|
"/var/lib/lxd/devlxd",
|
2019-01-13 05:48:42 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
mock_loader = MockLoader.new(:ubuntu)
|
|
|
|
mock_loader.backend.stub :file, mock_proc(mocked_files) do
|
2019-06-11 22:24:35 +00:00
|
|
|
mock_resource = mock_loader.load_resource("virtualization")
|
2019-01-13 05:48:42 +00:00
|
|
|
mock_resource.system.must_be_nil
|
|
|
|
mock_resource.role.must_be_nil
|
|
|
|
end
|
2018-02-28 19:22:55 +00:00
|
|
|
end
|
|
|
|
end
|