2015-09-08 22:05:05 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-08 22:05:05 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-09-08 22:05:05 +00:00
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
describe 'Inspec::Resources::Package' do
|
2015-10-12 11:22:01 +00:00
|
|
|
# arch linux
|
|
|
|
it 'verify arch linux package parsing' do
|
|
|
|
resource = MockLoader.new(:arch).load_resource('package', 'curl')
|
|
|
|
pkg = { name: 'curl', installed: true, version: '7.37.0-1', type: 'pacman' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.37.0-1'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
2015-10-12 08:38:11 +00:00
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# ubuntu
|
|
|
|
it 'verify ubuntu package parsing' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('package', 'curl')
|
|
|
|
pkg = { name: 'curl', installed: true, version: '7.35.0-1ubuntu2', type: 'deb' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.35.0-1ubuntu2'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
2015-09-08 22:05:05 +00:00
|
|
|
|
2016-10-08 21:26:21 +00:00
|
|
|
# mint
|
|
|
|
it 'verify mint package parsing' do
|
|
|
|
resource = MockLoader.new(:mint17).load_resource('package', 'curl')
|
|
|
|
pkg = { name: 'curl', installed: true, version: '7.35.0-1ubuntu2', type: 'deb' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.35.0-1ubuntu2'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# centos
|
2017-06-28 10:21:15 +00:00
|
|
|
describe 'Rpm' do # rubocop:disable BlockLength
|
|
|
|
let(:pkg) do
|
|
|
|
{
|
|
|
|
name: 'curl',
|
|
|
|
installed: true,
|
|
|
|
version: '7.29.0-19.el7',
|
|
|
|
type: 'rpm',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can parse RPM package info' do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource('package', 'curl')
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.29.0-19.el7'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can build an `rpm` command containing `--dbpath`' do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource(
|
|
|
|
'package',
|
|
|
|
'curl',
|
|
|
|
rpm_dbpath: '/var/lib/fake_rpmdb',
|
|
|
|
)
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.29.0-19.el7'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can add to `resource_skipped` when `--rpmdb` path does not exist' do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource(
|
|
|
|
'package',
|
|
|
|
'curl',
|
|
|
|
rpm_dbpath: '/var/lib/rpmdb_does_not_exist',
|
|
|
|
)
|
|
|
|
_(resource.resource_skipped).wont_equal nil
|
|
|
|
end
|
2015-10-12 11:22:01 +00:00
|
|
|
end
|
2015-09-08 22:05:05 +00:00
|
|
|
|
2016-04-21 08:31:56 +00:00
|
|
|
# hpux
|
|
|
|
it 'verify hpux package parsing' do
|
|
|
|
resource = MockLoader.new(:hpux).load_resource('package', 'vim')
|
|
|
|
pkg = { name: 'vim', installed: true, version: '7.4', type: 'pkg' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.4'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-12-03 03:08:49 +00:00
|
|
|
# wrlinux
|
|
|
|
it 'verify wrlinux package parsing' do
|
|
|
|
resource = MockLoader.new(:wrlinux).load_resource('package', 'curl')
|
2015-11-25 01:06:08 +00:00
|
|
|
pkg = { name: 'curl', installed: true, version: '7.29.0-19.el7', type: 'rpm' }
|
2015-12-03 03:08:49 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2015-11-25 01:06:08 +00:00
|
|
|
_(resource.version).must_equal '7.29.0-19.el7'
|
2015-12-03 03:08:49 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# windows
|
|
|
|
it 'verify windows package parsing' do
|
2016-08-24 12:33:13 +00:00
|
|
|
resource = MockLoader.new(:windows).load_resource('package', 'Chef Client v12.12.15')
|
|
|
|
pkg = { name: 'Chef Client v12.12.15', installed: true, version: '12.12.15.1', type: 'windows' }
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2016-08-24 12:33:13 +00:00
|
|
|
_(resource.version).must_equal '12.12.15.1'
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
2015-09-23 14:11:48 +00:00
|
|
|
|
2016-01-28 13:47:46 +00:00
|
|
|
# solaris 10
|
2017-01-02 17:05:25 +00:00
|
|
|
it 'verify solaris 10 package parsing' do
|
2016-01-28 13:47:46 +00:00
|
|
|
resource = MockLoader.new(:solaris10).load_resource('package', 'SUNWzfsr')
|
|
|
|
pkg = { name: 'SUNWzfsr', installed: true, version: '11.10.0-2006.05.18.01.46', type: 'pkg' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '11.10.0-2006.05.18.01.46'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
|
|
|
# solaris 11
|
2017-01-02 17:05:25 +00:00
|
|
|
it 'verify solaris 11 package parsing' do
|
2016-01-28 13:47:46 +00:00
|
|
|
resource = MockLoader.new(:solaris11).load_resource('package', 'system/file-system/zfs')
|
|
|
|
pkg = { name: 'system/file-system/zfs', installed: true, version: '0.5.11-0.175.3.1.0.5.0', type: 'pkg' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '0.5.11-0.175.3.1.0.5.0'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2017-01-02 16:52:20 +00:00
|
|
|
# darwin (brew)
|
|
|
|
it 'verify brew package parsing' do
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('package', 'curl')
|
|
|
|
pkg = { name: 'curl', installed: true, version: '7.52.1', type: 'brew' }
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal '7.52.1'
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# undefined
|
|
|
|
it 'verify package handling on unsupported os' do
|
|
|
|
resource = MockLoader.new(:undefined).load_resource('package', 'curl')
|
|
|
|
_(resource.installed?).must_equal false
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.info).must_be_nil
|
2015-09-08 22:05:05 +00:00
|
|
|
end
|
|
|
|
end
|