2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/packages"
|
2017-02-03 20:42:55 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Packages" do
|
|
|
|
it "verify packages resource" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", /^vim$/)
|
2017-02-03 20:42:55 +00:00
|
|
|
_(resource.entries.length).must_equal 1
|
|
|
|
_(resource.entries[0].to_h).must_equal({
|
2019-06-11 22:24:35 +00:00
|
|
|
status: "installed",
|
|
|
|
name: "vim",
|
|
|
|
version: "7.4.1689-3ubuntu1.2",
|
|
|
|
architecture: "amd64",
|
2017-02-03 20:42:55 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "package name matches with output (string)" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", "xserver-xorg")
|
2017-02-03 20:42:55 +00:00
|
|
|
_(resource.to_s).must_equal 'Packages /xserver\\-xorg/'
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "packages using where filters" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", /.+root$/)
|
2017-02-03 20:42:55 +00:00
|
|
|
_(resource.entries.length).must_equal 3
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.where { status != "installed" }.names).must_equal(%w{fakeroot libfakeroot})
|
2017-02-03 20:42:55 +00:00
|
|
|
_(resource.where { version =~ /^0\.2.+/ }.entries[0].to_h).must_equal({
|
|
|
|
status: "installed",
|
|
|
|
name: "overlayroot",
|
|
|
|
version: "0.27ubuntu1.2",
|
2019-06-11 22:24:35 +00:00
|
|
|
architecture: "amd64",
|
2017-02-03 20:42:55 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "package name matches with output (regex)" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", /vim/)
|
|
|
|
_(resource.to_s).must_equal "Packages /vim/"
|
2017-02-03 20:42:55 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns a list of packages with a wildcard" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", /^xserver-xorg.*/)
|
|
|
|
_(resource.statuses).must_equal ["installed"]
|
2017-02-03 20:42:55 +00:00
|
|
|
_(resource.entries.length).must_equal 3
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "all packages on Ubuntu" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", /.+/)
|
2018-01-26 07:57:34 +00:00
|
|
|
_(resource.entries.length).must_equal 14
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can find packages with same name but different architectures on Ubuntu" do
|
|
|
|
resource = MockLoader.new(:ubuntu1604).load_resource("packages", /libc6/)
|
|
|
|
_(resource.architectures).must_include "amd64"
|
|
|
|
_(resource.architectures).must_include "i386"
|
2018-01-26 07:57:34 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can find packages with same name but different architectures on CentOS" do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource("packages", /libstdc/)
|
|
|
|
_(resource.architectures).must_include "x86_64"
|
|
|
|
_(resource.architectures).must_include "i686"
|
2017-02-13 13:13:22 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "all packages on CentOS" do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource("packages", /.+/)
|
2018-01-26 07:57:34 +00:00
|
|
|
_(resource.entries.length).must_equal 12
|
2017-02-13 13:13:22 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "packages on CentOS" do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource("packages", /^chef\-.+/)
|
2017-02-13 13:13:22 +00:00
|
|
|
_(resource.entries.length).must_equal 1
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.where { status == "installed" }.names).must_equal(["chef-compliance"])
|
2017-02-13 13:13:22 +00:00
|
|
|
_(resource.entries[0].to_h).must_equal({
|
|
|
|
status: "installed",
|
|
|
|
name: "chef-compliance",
|
|
|
|
version: "1.3.1-1.el6",
|
2018-01-26 07:57:34 +00:00
|
|
|
architecture: "x86_64",
|
2017-02-13 13:13:22 +00:00
|
|
|
})
|
|
|
|
end
|
2017-02-03 20:42:55 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "skips on non debian platforms" do
|
|
|
|
resource = MockLoader.new(:hpux).load_resource("packages", "bash")
|
|
|
|
_(resource.resource_exception_message).must_equal "The packages resource is not yet supported on OS hpux"
|
2017-02-03 20:42:55 +00:00
|
|
|
end
|
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
# rubocop:disable Style/BlockDelimiters
|
2019-06-11 22:24:35 +00:00
|
|
|
it "fails if the packages name is not a string or regexp" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_ {
|
2019-07-09 00:20:30 +00:00
|
|
|
resources = MockLoader.new(:ubuntu1604).load_resource("packages", %i{a b})
|
2017-02-03 20:42:55 +00:00
|
|
|
resources.send(:entries, nil)
|
|
|
|
}.must_raise(RuntimeError)
|
|
|
|
end
|
|
|
|
end
|