mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
add unit tests
This commit is contained in:
parent
678ee2b473
commit
62844eee0c
8 changed files with 86 additions and 0 deletions
|
@ -40,6 +40,8 @@ class MockLoader
|
|||
ubuntu1504: { family: 'ubuntu', release: '15.04', arch: 'x86_64' },
|
||||
windows: { family: 'windows', release: nil, arch: nil },
|
||||
wrlinux: { family: 'wrlinux', release: '7.0(3)I2(2)', arch: 'x86_64' },
|
||||
solaris11: { family: "solaris", release: '11', arch: 'i386'},
|
||||
solaris10: { family: "solaris", release: '10', arch: 'i386'},
|
||||
undefined: { family: nil, release: nil, arch: nil },
|
||||
}
|
||||
|
||||
|
@ -202,6 +204,12 @@ class MockLoader
|
|||
# mount
|
||||
"mount | grep -- ' on /'" => cmd.call("mount"),
|
||||
"mount | grep -- ' on /mnt/iso-disk'" => cmd.call("mount-multiple"),
|
||||
# solaris 10 package manager
|
||||
'pkginfo -l SUNWzfsr' => cmd.call('pkginfo-l-SUNWzfsr'),
|
||||
# solaris 11 package manager
|
||||
'pkg info system/file-system/zfs' => cmd.call('pkg-info-system-file-system-zfs'),
|
||||
# port netstat on solaris 10 & 11
|
||||
'netstat -an -f inet -f inet6' => cmd.call('s11-netstat-an-finet-finet6'),
|
||||
}
|
||||
|
||||
@backend
|
||||
|
|
8
test/unit/mock/cmd/pkg-info-system-file-system-zfs
Normal file
8
test/unit/mock/cmd/pkg-info-system-file-system-zfs
Normal file
|
@ -0,0 +1,8 @@
|
|||
Name: system/file-system/zfs
|
||||
Summary: ZFS file system
|
||||
Category: System/File System
|
||||
State: Installed
|
||||
Version: 0.5.11
|
||||
Build Release: 5.11
|
||||
Branch: 0.175.3.1.0.5.0
|
||||
Packaging Date: October 6, 2015 02:23:22 PM
|
7
test/unit/mock/cmd/pkginfo-l-SUNWzfsr
Normal file
7
test/unit/mock/cmd/pkginfo-l-SUNWzfsr
Normal file
|
@ -0,0 +1,7 @@
|
|||
PKGINST: SUNWzfsr
|
||||
NAME: ZFS (Root)
|
||||
CATEGORY: system
|
||||
ARCH: i386
|
||||
VERSION: 11.10.0,REV=2006.05.18.01.46
|
||||
DESC: ZFS root components
|
||||
STATUS: completely installed
|
32
test/unit/mock/cmd/s11-netstat-an-finet-finet6
Normal file
32
test/unit/mock/cmd/s11-netstat-an-finet-finet6
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
UDP: IPv4
|
||||
Local Address Remote Address State
|
||||
-------------------- -------------------- ----------
|
||||
*.* Unbound
|
||||
10.0.2.15.68 Idle
|
||||
192.168.59.103.68 Idle
|
||||
|
||||
UDP: IPv6
|
||||
Local Address Remote Address State If
|
||||
--------------------------------- --------------------------------- ---------- -----
|
||||
*.* Unbound
|
||||
*.546 Idle
|
||||
|
||||
TCP: IPv4
|
||||
Local Address Remote Address Swind Send-Q Rwind Recv-Q State
|
||||
-------------------- -------------------- ------- ------ ------- ------ -----------
|
||||
127.0.0.1.5999 *.* 0 0 128000 0 LISTEN
|
||||
*.111 *.* 0 0 128000 0 LISTEN
|
||||
*.* *.* 0 0 128000 0 IDLE
|
||||
*.111 *.* 0 0 128000 0 LISTEN
|
||||
*.* *.* 0 0 128000 0 IDLE
|
||||
192.168.59.103.22 192.168.59.3.55016 131008 0 128872 0 ESTABLISHED
|
||||
*.22 *.* 0 0 128000 0 LISTEN
|
||||
*.22 *.* 0 0 128000 0 LISTEN
|
||||
|
||||
TCP: IPv6
|
||||
Local Address Remote Address Swind Send-Q Rwind Recv-Q State If
|
||||
--------------------------------- --------------------------------- ------- ------ ------- ------ ----------- -----
|
||||
::1.5999 *.* 0 0 128000 0 LISTEN
|
||||
*.111 *.* 0 0 128000 0 LISTEN
|
||||
*.* *.* 0 0 128000 0 IDLE
|
|
@ -156,6 +156,7 @@ describe Inspec::Resources::File do
|
|||
describe 'when not on linux or freebsd' do
|
||||
before do
|
||||
resource.stubs(:linux?).returns(false)
|
||||
resource.stubs(:solaris?).returns(false)
|
||||
resource.stubs(:family).returns('fakefamily')
|
||||
end
|
||||
|
||||
|
|
|
@ -51,6 +51,24 @@ describe 'Inspec::Resources::Package' do
|
|||
_(resource.info).must_equal pkg
|
||||
end
|
||||
|
||||
# solaris 10
|
||||
it 'verify windows package parsing' do
|
||||
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
|
||||
it 'verify windows package parsing' do
|
||||
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
|
||||
|
||||
# undefined
|
||||
it 'verify package handling on unsupported os' do
|
||||
resource = MockLoader.new(:undefined).load_resource('package', 'curl')
|
||||
|
|
|
@ -71,4 +71,14 @@ describe 'Inspec::Resources::Port' do
|
|||
resource = MockLoader.new(:ubuntu1404).load_resource('port', '127.0.0.1', 22)
|
||||
_(resource.listening?).must_equal false
|
||||
end
|
||||
|
||||
it 'verify port on Solaris 10' do
|
||||
resource = MockLoader.new(:solaris10).load_resource('port', 22)
|
||||
_(resource.listening?).must_equal true
|
||||
end
|
||||
|
||||
it 'verify port on Solaris 11' do
|
||||
resource = MockLoader.new(:solaris11).load_resource('port', 22)
|
||||
_(resource.listening?).must_equal true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
require 'helper'
|
||||
|
||||
describe PasswdParser do
|
||||
let (:parser) { Class.new() { include PasswdParser }.new }
|
||||
|
||||
|
|
Loading…
Reference in a new issue