2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/platform"
|
2018-01-02 19:04:13 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Platform" do
|
2019-05-31 21:59:06 +00:00
|
|
|
let(:resource) { MockLoader.new(:ubuntu1504).load_resource("platform") }
|
2018-01-02 19:04:13 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform parsing on Ubuntu" do
|
|
|
|
_(resource.name).must_equal "ubuntu"
|
|
|
|
_(resource.family).must_equal "debian"
|
|
|
|
_(resource.release).must_equal "15.04"
|
|
|
|
_(resource.arch).must_equal "x86_64"
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform hash parsing on Ubuntu" do
|
|
|
|
_(resource[:name]).must_equal "ubuntu"
|
|
|
|
_(resource[:family]).must_equal "debian"
|
|
|
|
_(resource[:release]).must_equal "15.04"
|
|
|
|
_(resource[:arch]).must_equal "x86_64"
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform families" do
|
|
|
|
expect = %w{debian linux unix os}
|
2018-01-02 19:04:13 +00:00
|
|
|
_(resource.families).must_equal expect
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform? responds correctly" do
|
|
|
|
_(resource.platform?("windows")).must_equal false
|
|
|
|
_(resource.platform?("unix")).must_equal true
|
|
|
|
_(resource.platform?("ubuntu")).must_equal true
|
|
|
|
_(resource.platform?("mac_os_x")).must_equal false
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify family? responds correctly" do
|
|
|
|
_(resource.in_family?("windows")).must_equal false
|
|
|
|
_(resource.in_family?("unix")).must_equal true
|
|
|
|
_(resource.in_family?("ubuntu")).must_equal false
|
|
|
|
_(resource.in_family?("mac_os_x")).must_equal false
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify supported? with multiple families" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ os_family: "windows" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ os_family: "unix" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal true
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads a profile which supports multiple names" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-family': "unix", 'os-name': "ubuntu" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal true
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "reject a profile which supports multiple families" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ os_family: "windows" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ os_family: "redhat" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal false
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads a profile which supports release 15.04" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "15.04" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal true
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads a profile which supports release 15.*" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "15.*" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal true
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads a profile which supports release *.04" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "*.04" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal true
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "reject a profile which supports release 12.*" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "12.*" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(resource.supported?(supports)).must_equal false
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
end
|