Merge pull request #42 from chef/unit-test-mock-os

unit test mock os
This commit is contained in:
Dominik Richter 2015-09-22 19:42:54 +02:00
commit 91c8330a4d
29 changed files with 361 additions and 395 deletions

View file

@ -14,75 +14,105 @@ end
require 'vulcano/backend'
require 'vulcano/resource'
# loads a resource class and instantiates the class with the given arguments
def loadResource (resource, *args)
scriptpath = ::File.realpath(::File.dirname(__FILE__))
class MockLoader
# pass the os identifier to emulate a specific operating system
def initialize(os = nil)
# collects emulation operating systems
@operating_systems = {
windows: { family: 'windows', release: nil, arch: nil },
debian6: { family: 'debian', release: '6', arch: 'x86_64' },
debian7: { family: 'debian', release: '7', arch: 'x86_64' },
debian8: { family: 'debian', release: '8', arch: 'x86_64' },
centos5: { family: 'redhat', release: '5.11', arch: 'x86_64' },
centos6: { family: 'redhat', release: '6.6', arch: 'x86_64' },
centos7: { family: 'redhat', release: '7.1.1503', arch: 'x86_64' },
ubuntu1204: { family: 'ubuntu', release: '12.04', arch: 'x86_64' },
ubuntu1404: { family: 'ubuntu', release: '14.04', arch: 'x86_64' },
osx104: { family: 'darwin', release: '10.10.4', arch: nil, name: 'mac_os_x' },
freebsd9: { family: 'freebsd', release: '9', arch: 'amd64' },
freebsd10: { family: 'freebsd', release: '10', arch: 'amd64' },
}
# create mock backend
conf = Vulcano::Backend.target_config({
quiet: true
})
backend_class = Vulcano::Backend.registry['mock']
@backend = backend_class.new(conf)
# selects operating system
@os = @operating_systems[os || :ubuntu1404]
end
# create all mock files
local = Vulcano::Backend.registry['local'].new({})
mockfile = lambda { |x|
path = ::File.join(scriptpath, '/unit/mock/files', x)
local.file(path)
}
@backend.files = {
'/proc/net/bonding/bond0' => mockfile.('bond0'),
'/etc/ssh/ssh_config' => mockfile.('ssh_config'),
'/etc/ssh/sshd_config' => mockfile.('sshd_config'),
'/etc/passwd' => mockfile.('passwd'),
'/etc/ntp.conf' => mockfile.('ntp.conf'),
'/etc/login.defs' => mockfile.('login.defs'),
'/etc/security/limits.conf' => mockfile.('limits.conf'),
'/etc/inetd.conf' => mockfile.('inetd.conf'),
'/etc/group' => mockfile.('group'),
'/etc/audit/auditd.conf' => mockfile.('auditd.conf'),
'/etc/mysql/my.cnf' => mockfile.('mysql.conf'),
'/etc/mysql/mysql2.conf' => mockfile.('mysql2.conf'),
'kitchen.yml' => mockfile.('kitchen.yml'),
'example.csv' => mockfile.('example.csv'),
'policyfile.lock.json' => mockfile.('policyfile.lock.json'),
}
# loads a resource class and instantiates the class with the given arguments
def load_resource(resource, *args)
scriptpath = ::File.realpath(::File.dirname(__FILE__))
# create all mock commands
cmd = lambda {|x|
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
@backend.mock_command( stdout, '', 0 )
}
@backend.commands = {
'ps aux' => cmd.call('ps-aux'),
'type win_secpol.cfg' => cmd.call('secedit-export'),
'secedit /export /cfg win_secpol.cfg' => cmd.call('success'),
'del win_secpol.cfg' => cmd.call('success'),
'su - root -c \'echo $PATH\'' => cmd.call('PATH'),
'(Get-Item \'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule\').GetValue(\'Start\')' => cmd.call('reg_schedule'),
'Auditpol /get /subcategory:\'User Account Management\' /r' => cmd.call('auditpol'),
'/sbin/auditctl -l' => cmd.call('auditctl'),
'yum -v repolist all' => cmd.call('yum-repolist-all'),
'dpkg -s curl' => cmd.call('dpkg-s-curl'),
'rpm -qia curl' => cmd.call('rpm-qia-curl'),
'pacman -Qi curl' => cmd.call('packman-qi-curl'),
'gem list --local -a -q ^rubocop$' => cmd.call('gem-list-local-a-q-rubocop'),
'npm ls -g --json bower' => cmd.call('npm-ls-g--json-bower'),
'pip show jinja2' => cmd.call('pip-show-jinja2'),
"Get-Package -Name 'Mozilla Firefox' | ConvertTo-Json" => cmd.call('get-package'),
"New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name dhcp| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json" => cmd.call('get-service-dhcp'),
"Get-WindowsFeature | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property Name,DisplayName,Description,Installed,InstallState | ConvertTo-Json" => cmd.call('get-windows-feature'),
'lsmod' => cmd.call('lsmod'),
'/sbin/sysctl -q -n net.ipv4.conf.all.forwarding' => cmd.call('sbin_sysctl'),
}
# create mock backend
conf = Vulcano::Backend.target_config({ quiet: true })
backend_class = Vulcano::Backend.registry['mock']
@backend = backend_class.new(conf)
# load resource
@rclass = Vulcano::Resource.registry[resource]
# create all mock files
local = Vulcano::Backend.registry['local'].new({})
mockfile = lambda { |x|
path = ::File.join(scriptpath, '/unit/mock/files', x)
local.file(path)
}
@backend.files = {
'/proc/net/bonding/bond0' => mockfile.call('bond0'),
'/etc/ssh/ssh_config' => mockfile.call('ssh_config'),
'/etc/ssh/sshd_config' => mockfile.call('sshd_config'),
'/etc/passwd' => mockfile.call('passwd'),
'/etc/ntp.conf' => mockfile.call('ntp.conf'),
'/etc/login.defs' => mockfile.call('login.defs'),
'/etc/security/limits.conf' => mockfile.call('limits.conf'),
'/etc/inetd.conf' => mockfile.call('inetd.conf'),
'/etc/group' => mockfile.call('group'),
'/etc/audit/auditd.conf' => mockfile.call('auditd.conf'),
'/etc/mysql/my.cnf' => mockfile.call('mysql.conf'),
'/etc/mysql/mysql2.conf' => mockfile.call('mysql2.conf'),
'kitchen.yml' => mockfile.call('kitchen.yml'),
'example.csv' => mockfile.call('example.csv'),
'policyfile.lock.json' => mockfile.call('policyfile.lock.json'),
}
# merge arguments
args = [@backend] | args
# create all mock commands
cmd = lambda {|x|
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
@backend.mock_command(stdout, '', 0)
}
@backend.commands = {
'ps aux' => cmd.call('ps-aux'),
'type win_secpol.cfg' => cmd.call('secedit-export'),
'secedit /export /cfg win_secpol.cfg' => cmd.call('success'),
'del win_secpol.cfg' => cmd.call('success'),
'su - root -c \'echo $PATH\'' => cmd.call('PATH'),
'(Get-Item \'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule\').GetValue(\'Start\')' => cmd.call('reg_schedule'),
'Auditpol /get /subcategory:\'User Account Management\' /r' => cmd.call('auditpol'),
'/sbin/auditctl -l' => cmd.call('auditctl'),
'yum -v repolist all' => cmd.call('yum-repolist-all'),
'dpkg -s curl' => cmd.call('dpkg-s-curl'),
'rpm -qia curl' => cmd.call('rpm-qia-curl'),
'pacman -Qi curl' => cmd.call('packman-qi-curl'),
'gem list --local -a -q ^rubocop$' => cmd.call('gem-list-local-a-q-rubocop'),
'npm ls -g --json bower' => cmd.call('npm-ls-g--json-bower'),
'pip show jinja2' => cmd.call('pip-show-jinja2'),
"Get-Package -Name 'Mozilla Firefox' | ConvertTo-Json" => cmd.call('get-package'),
"New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name dhcp| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json" => cmd.call('get-service-dhcp'),
"Get-WindowsFeature | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property Name,DisplayName,Description,Installed,InstallState | ConvertTo-Json" => cmd.call('get-windows-feature'),
'lsmod' => cmd.call('lsmod'),
'/sbin/sysctl -q -n net.ipv4.conf.all.forwarding' => cmd.call('sbin_sysctl'),
}
# initialize resource with backend and parameters
@resource = @rclass.new(*args)
# set os emulation
@backend.os = @os
# load resource
@rclass = Vulcano::Resource.registry[resource]
# merge arguments
args = [@backend] | args
# initialize resource with backend and parameters
@resource = @rclass.new(*args)
end
end
def load_resource(*args)
m = MockLoader.new(:ubuntu1404)
m.send('load_resource', *args)
end

View file

@ -4,11 +4,9 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::AuditPolicy' do
describe 'audit_policy' do
let(:resource) { loadResource('audit_policy') }
let(:resource) { load_resource('audit_policy') }
it 'check audit policy parsing' do
_(resource.send('User Account Management')).must_equal 'Success'
end
it 'check audit policy parsing' do
_(resource.send('User Account Management')).must_equal 'Success'
end
end

View file

@ -4,13 +4,11 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::AuditDaemonConf' do
describe 'audit_daemon_conf' do
let(:resource) { loadResource('audit_daemon_conf') }
let(:resource) { load_resource('audit_daemon_conf') }
it 'check audit daemon config parsing' do
_(resource.space_left_action).must_equal 'SYSLOG'
_(resource.action_mail_acct).must_equal 'root'
_(resource.tcp_listen_queue).must_equal '5'
end
it 'check audit daemon config parsing' do
_(resource.space_left_action).must_equal 'SYSLOG'
_(resource.action_mail_acct).must_equal 'root'
_(resource.tcp_listen_queue).must_equal '5'
end
end

View file

@ -4,19 +4,17 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::AuditDaemonRules' do
describe 'audit_daemon_rules' do
let(:resource) { loadResource('audit_daemon_rules') }
let(:resource) { load_resource('audit_daemon_rules') }
it 'check audit policy parsing' do
_(resource.send('LIST_RULES')).must_equal [
'exit,always syscall=rmdir,unlink',
'exit,always auid=1001 (0x3e9) syscall=open',
'exit,always watch=/etc/group perm=wa',
'exit,always watch=/etc/passwd perm=wa',
'exit,always watch=/etc/shadow perm=wa',
'exit,always watch=/etc/sudoers perm=wa',
'exit,always watch=/etc/secret_directory perm=r'
]
end
it 'check audit policy parsing' do
_(resource.send('LIST_RULES')).must_equal [
'exit,always syscall=rmdir,unlink',
'exit,always auid=1001 (0x3e9) syscall=open',
'exit,always watch=/etc/group perm=wa',
'exit,always watch=/etc/passwd perm=wa',
'exit,always watch=/etc/shadow perm=wa',
'exit,always watch=/etc/sudoers perm=wa',
'exit,always watch=/etc/secret_directory perm=r',
]
end
end

View file

@ -4,28 +4,24 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Bond' do
let(:resource) { load_resource('bond', 'bond0') }
describe 'parse bond config' do
it 'bond must be available' do
resource.exist?.must_equal true
end
let(:resource) { loadResource('bond', 'bond0') }
it 'eth0 is part of bond' do
_(resource.has_interface?('eth0')).must_equal true
_(resource.has_interface?('eth1')).must_equal false
_(resource.has_interface?('eth2')).must_equal true
end
it 'bond must be available' do
resource.exist?.must_equal true
end
it 'get all interfaces' do
_(resource.interfaces).must_equal %w{eth0 eth2}
end
it 'eth0 is part of bond' do
_(resource.has_interface?('eth0')).must_equal true
_(resource.has_interface?('eth1')).must_equal false
_(resource.has_interface?('eth2')).must_equal true
end
it 'get all interfaces' do
_(resource.interfaces).must_equal %w{eth0 eth2}
end
it 'get proc content' do
_(resource.content).wont_equal nil
_(resource.content).wont_equal ''
end
it 'get proc content' do
_(resource.content).wont_equal nil
_(resource.content).wont_equal ''
end
end

View file

@ -4,14 +4,11 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::CSV' do
describe 'cars' do
let(:resource) { load_resource('csv', 'example.csv') }
let(:resource) { loadResource('csv', 'example.csv') }
it 'verify csv parsing' do
_(resource.params).wont_equal nil
_(resource.send('1.addressable')).must_equal 'astrolabe'
_(resource.send('addressable')).must_equal %w{ast astrolabe berkshelf}
end
it 'verify csv parsing' do
_(resource.params).wont_equal nil
_(resource.send('1.addressable')).must_equal 'astrolabe'
_(resource.send('addressable')).must_equal %w{ast astrolabe berkshelf}
end
end

View file

@ -4,19 +4,16 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'gem' do
let(:resource) { loadResource('gem', 'rubocop') }
it 'verify gem package detail parsing' do
pkg = {
name: 'rubocop',
version: '0.33.0',
type: 'gem',
installed: true,
}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
let(:resource) { load_resource('gem', 'rubocop') }
it 'verify gem package detail parsing' do
pkg = {
name: 'rubocop',
version: '0.33.0',
type: 'gem',
installed: true,
}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
end

View file

@ -4,34 +4,32 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::EtcGroup' do
describe 'etc_group' do
let(:resource) { loadResource('etc_group') }
let(:resource) { load_resource('etc_group') }
it 'verify /etc/group config parsing' do
_(resource.gids).must_equal %w{ 0 33 }
_(resource.groups).must_equal %w{ root www-data }
_(resource.users).must_equal %w{ www-data root }
end
it 'verify /etc/group config parsing' do
_(resource.gids).must_equal %w{ 0 33 }
_(resource.groups).must_equal %w{ root www-data }
_(resource.users).must_equal %w{ www-data root }
end
it 'verify group filter with no users' do
root_filter = resource.where(name: 'root')
_(root_filter.gids).must_equal ['0']
_(root_filter.groups).must_equal ['root']
_(root_filter.users).must_equal []
end
it 'verify group filter with no users' do
root_filter = resource.where(name: 'root')
_(root_filter.gids).must_equal ['0']
_(root_filter.groups).must_equal ['root']
_(root_filter.users).must_equal []
end
it 'verify group filter with users' do
www_filter = resource.where(name: 'www-data')
_(www_filter.gids).must_equal ['33']
_(www_filter.groups).must_equal ['www-data']
_(www_filter.users).must_equal ['www-data', 'root']
end
it 'verify group filter with users' do
www_filter = resource.where(name: 'www-data')
_(www_filter.gids).must_equal ['33']
_(www_filter.groups).must_equal ['www-data']
_(www_filter.users).must_equal ['www-data', 'root']
end
it 'verify group filter with wrong group' do
wrong_filter = resource.where(name: 'wrong_group')
_(wrong_filter.gids).must_equal []
_(wrong_filter.groups).must_equal []
_(wrong_filter.users).must_equal []
end
it 'verify group filter with wrong group' do
wrong_filter = resource.where(name: 'wrong_group')
_(wrong_filter.gids).must_equal []
_(wrong_filter.groups).must_equal []
_(wrong_filter.users).must_equal []
end
end

View file

@ -4,13 +4,11 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::InetdConf' do
describe 'inetd_config' do
let(:resource) { loadResource('inetd_config') }
let(:resource) { load_resource('inetd_config') }
it 'verify limits.conf config parsing' do
_(resource.send('shell')).must_equal nil
_(resource.send('login')).must_equal nil
_(resource.send('ftp')).must_equal %w{stream tcp nowait root /usr/sbin/in.ftpd in.ftpd}
end
it 'verify limits.conf config parsing' do
_(resource.send('shell')).must_equal nil
_(resource.send('login')).must_equal nil
_(resource.send('ftp')).must_equal %w{stream tcp nowait root /usr/sbin/in.ftpd in.ftpd}
end
end

View file

@ -4,15 +4,12 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::JSON' do
describe 'json' do
resource = load_resource('json', 'policyfile.lock.json')
let(:resource) { loadResource('json', 'policyfile.lock.json') }
it 'verify json parsing' do
_(resource.params).wont_equal nil
_(resource.send('name')).must_equal 'demo'
_(resource.send('run_list')).must_equal %w{apache2 omnibus}
_(resource.send('cookbook_locks.omnibus.version')).must_equal '2.2.0'
end
it 'verify json parsing' do
_(resource.params).wont_equal nil
_(resource.send('name')).must_equal 'demo'
_(resource.send('run_list')).must_equal %w{apache2 omnibus}
_(resource.send('cookbook_locks.omnibus.version')).must_equal '2.2.0'
end
end

View file

@ -5,17 +5,17 @@ require 'vulcano/resource'
describe 'Vulcano::Resources::KernelModule' do
it 'verify kernel_module parsing' do
resource = loadResource('kernel_module', 'bridge')
resource = load_resource('kernel_module', 'bridge')
_(resource.loaded?).must_equal true
end
it 'verify kernel_module parsing' do
resource = loadResource('kernel_module', 'bridges')
resource = load_resource('kernel_module', 'bridges')
_(resource.loaded?).must_equal false
end
it 'verify kernel_module parsing' do
resource = loadResource('kernel_module', 'dhcp')
resource = load_resource('kernel_module', 'dhcp')
_(resource.loaded?).must_equal false
end
end

View file

@ -4,12 +4,9 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::KernelParameter' do
describe 'kernel_parameter' do
let(:resource) { loadResource('kernel_parameter', 'net.ipv4.conf.all.forwarding') }
it 'verify kernel_parameter parsing' do
_(resource.value).must_equal 1
end
let(:resource) { load_resource('kernel_parameter', 'net.ipv4.conf.all.forwarding') }
it 'verify kernel_parameter parsing' do
_(resource.value).must_equal 1
end
end

View file

@ -4,12 +4,10 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::LimitsConf' do
describe 'limits_conf' do
let(:resource) { loadResource('limits_conf') }
let(:resource) { load_resource('limits_conf') }
it 'verify limits.conf config parsing' do
_(resource.send('*')).must_equal [['soft', 'core', '0'], ['hard', 'rss', '10000']]
_(resource.send('ftp')).must_equal [["hard", "nproc", "0"]]
end
it 'verify limits.conf config parsing' do
_(resource.send('*')).must_equal [['soft', 'core', '0'], ['hard', 'rss', '10000']]
_(resource.send('ftp')).must_equal [["hard", "nproc", "0"]]
end
end

View file

@ -4,14 +4,12 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::LoginDef' do
describe 'login_defs' do
let(:resource) { loadResource('login_defs') }
let(:resource) { load_resource('login_defs') }
it 'verify login.def config parsing' do
_(resource.UMASK).must_equal '022'
_(resource.PASS_MIN_DAYS).must_equal '0'
_(resource.PASS_WARN_AGE).must_equal '7'
_(resource.USERDEL_CMD).must_equal nil
end
it 'verify login.def config parsing' do
_(resource.UMASK).must_equal '022'
_(resource.PASS_MIN_DAYS).must_equal '0'
_(resource.PASS_WARN_AGE).must_equal '7'
_(resource.USERDEL_CMD).must_equal nil
end
end

View file

@ -2,13 +2,11 @@
require 'helper'
describe 'Vulcano::Resources::MysqlConf' do
describe 'mysql_conf' do
let(:resource) { loadResource('mysql_conf', '/etc/mysql/my.cnf') }
let(:resource) { load_resource('mysql_conf', '/etc/mysql/my.cnf') }
it 'verify mysql.conf config parsing' do
_(resource.client['port']).must_equal '3306'
_(resource.mysqld['user']).must_equal 'mysql'
_(resource.mysqld['key_buffer_size']).must_equal '16M'
end
it 'verify mysql.conf config parsing' do
_(resource.client['port']).must_equal '3306'
_(resource.mysqld['user']).must_equal 'mysql'
_(resource.mysqld['key_buffer_size']).must_equal '16M'
end
end

View file

@ -4,18 +4,16 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'npm' do
let(:resource) { loadResource('npm', 'bower') }
let(:resource) { load_resource('npm', 'bower') }
it 'verify npm package detail parsing' do
pkg = {
name: 'bower',
version: '1.4.1',
type: 'npm',
installed: true,
}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
it 'verify npm package detail parsing' do
pkg = {
name: 'bower',
version: '1.4.1',
type: 'npm',
installed: true,
}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
end

View file

@ -4,15 +4,12 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::NtpConf' do
describe 'ntp_conf' do
let(:resource) { loadResource('ntp_conf') }
it 'verify ntp config parsing' do
_(resource.driftfile).must_equal '/var/lib/ntp/ntp.drift'
_(resource.server).must_equal %w{
0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org
}
end
let(:resource) { load_resource('ntp_conf') }
it 'verify ntp config parsing' do
_(resource.driftfile).must_equal '/var/lib/ntp/ntp.drift'
_(resource.server).must_equal %w{
0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org
}
end
end

View file

@ -4,18 +4,16 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'oneget' do
let(:resource) { loadResource('oneget', 'Mozilla Firefox') }
let(:resource) { load_resource('oneget', 'Mozilla Firefox') }
it 'verify oneget package detail parsing' do
pkg = {
name: 'Mozilla Firefox 40.0.3 (x86 en-US)',
version: '40.0.3',
type: 'oneget',
installed: true,
}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
it 'verify oneget package detail parsing' do
pkg = {
name: 'Mozilla Firefox 40.0.3 (x86 en-US)',
version: '40.0.3',
type: 'oneget',
installed: true,
}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
end

View file

@ -4,12 +4,9 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::OsEnv' do
describe 'os_env' do
let(:resource) { loadResource('os_env', 'PATH') }
it 'verify ntp config parsing' do
_(resource.split).must_equal %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
end
let(:resource) { load_resource('os_env', 'PATH') }
it 'verify ntp config parsing' do
_(resource.split).must_equal %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
end
end

View file

@ -4,25 +4,22 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'passwd' do
let(:resource) { loadResource('passwd') }
let(:resource) { load_resource('passwd') }
it 'verify passwd parsing' do
_(resource.usernames).must_equal %w{root www-data}
_(resource.uids).must_equal %w{0 33}
end
it 'verify passwd parsing' do
_(resource.usernames).must_equal %w{root www-data}
_(resource.uids).must_equal %w{0 33}
end
it 'verify root passwd resource' do
root = resource.uid(0)
_(root.username).must_equal 'root'
_(root.count).must_equal 1
end
it 'verify www-data resource' do
www = resource.uid(33)
_(www.username).must_equal 'www-data'
_(www.count).must_equal 1
end
it 'verify root passwd resource' do
root = resource.uid(0)
_(root.username).must_equal 'root'
_(root.count).must_equal 1
end
it 'verify www-data resource' do
www = resource.uid(33)
_(www.username).must_equal 'www-data'
_(www.count).must_equal 1
end
end

View file

@ -4,14 +4,11 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'pip' do
let(:resource) { loadResource('pip', 'jinja2') }
it 'verify pip package detail parsing' do
pkg = {:name=>"Jinja2", :installed=>true, :version=>"2.8", :type=>"pip"}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
let(:resource) { load_resource('pip', 'jinja2') }
it 'verify pip package detail parsing' do
pkg = {:name=>"Jinja2", :installed=>true, :version=>"2.8", :type=>"pip"}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
end

View file

@ -4,25 +4,23 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Processes' do
describe 'processes' do
let(:resource) { loadResource('processes', '/bin/bash') }
let(:resource) { load_resource('processes', '/bin/bash') }
it 'verify processes resource' do
_(resource.list).must_equal [{
user: 'root',
pid: '1',
cpu: '0.0',
mem: '0.0',
vsz: '18084',
rss: '3228',
tty: '?',
stat: 'Ss',
start: '14:15',
time: '0:00',
command: '/bin/bash'
}]
it 'verify processes resource' do
_(resource.list).must_equal [{
user: 'root',
pid: '1',
cpu: '0.0',
mem: '0.0',
vsz: '18084',
rss: '3228',
tty: '?',
stat: 'Ss',
start: '14:15',
time: '0:00',
command: '/bin/bash'
}]
_(resource.list.length).must_equal 1
end
_(resource.list.length).must_equal 1
end
end

View file

@ -4,16 +4,14 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::RegistryKey' do
describe 'registry_key' do
let(:resource) { loadResource('registry_key', 'Task Scheduler', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') }
let(:resource_without_name) { loadResource('registry_key', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') }
let(:resource) { load_resource('registry_key', 'Task Scheduler', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') }
let(:resource_without_name) { load_resource('registry_key', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') }
it 'read reg key with human readable name' do
_(resource.Start).must_equal 2
end
it 'read reg key with human readable name' do
_(resource.Start).must_equal 2
end
it 'read reg key without human readable name' do
_(resource_without_name.Start).must_equal 2
end
it 'read reg key without human readable name' do
_(resource_without_name.Start).must_equal 2
end
end

View file

@ -4,14 +4,12 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::SecurityPolicy' do
describe 'security_policy' do
let(:resource) { loadResource('security_policy') }
let(:resource) { load_resource('security_policy') }
it 'verify processes resource' do
_(resource.MaximumPasswordAge).must_equal 42
_(resource.send('MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SecurityLevel')).must_equal '4,0'
_(resource.SeUndockPrivilege).must_equal '*S-1-5-32-544'
_(resource.SeRemoteInteractiveLogonRight).must_equal '*S-1-5-32-544,*S-1-5-32-555'
end
it 'verify processes resource' do
_(resource.MaximumPasswordAge).must_equal 42
_(resource.send('MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SecurityLevel')).must_equal '4,0'
_(resource.SeUndockPrivilege).must_equal '*S-1-5-32-544'
_(resource.SeRemoteInteractiveLogonRight).must_equal '*S-1-5-32-544,*S-1-5-32-555'
end
end

View file

@ -4,18 +4,15 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Service' do
describe 'service' do
# TODO: make OS dependent
let(:resource) { load_resource('service', 'dhcp') }
# TODO: make OS dependent
let(:resource) { loadResource('service', 'dhcp') }
# windows
# it 'verify service parsing' do
# pkg = { name: 'dhcp', description: 'DHCP Client', installed: true, running: true, enabled: true, type: 'windows' }
# _(resource.info).must_equal pkg
# _(resource.installed?).must_equal true
# _(resource.enabled?).must_equal true
# _(resource.running?).must_equal true
# end
end
# windows
# it 'verify service parsing' do
# pkg = { name: 'dhcp', description: 'DHCP Client', installed: true, running: true, enabled: true, type: 'windows' }
# _(resource.info).must_equal pkg
# _(resource.installed?).must_equal true
# _(resource.enabled?).must_equal true
# _(resource.running?).must_equal true
# end
end

View file

@ -6,8 +6,7 @@ require 'vulcano/resource'
describe 'Vulcano::Resources::SshConf' do
describe 'ssh_config' do
let(:resource) { loadResource('ssh_config') }
let(:resource) { load_resource('ssh_config') }
it 'check ssh config parsing' do
_(resource.Host).must_equal '*'
@ -19,8 +18,7 @@ describe 'Vulcano::Resources::SshConf' do
end
describe 'sshd_config' do
let(:resource) { loadResource('sshd_config') }
let(:resource) { load_resource('sshd_config') }
it 'check protocol version' do
_(resource.Port).must_equal '22'

View file

@ -6,7 +6,7 @@ require 'vulcano/resource'
describe 'Vulcano:Resources::Feature' do
describe 'feature' do
let(:resource) { loadResource('windows_feature', 'dhcp') }
let(:resource) { MockLoader.new(:windows).load_resource('windows_feature', 'dhcp') }
# TODO: set windows as mock os
it 'verify windows feature parsing' do

View file

@ -4,16 +4,13 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::YAML' do
describe 'yaml' do
let(:resource) { load_resource('yaml', 'kitchen.yml') }
let(:resource) { loadResource('yaml', 'kitchen.yml') }
it 'verify yaml parsing' do
_(resource.params).wont_be_nil
_(resource.send('driver.name')).must_equal 'vagrant'
_(resource.send('driver.customize.memory')).must_equal 1024
_(resource.send('platforms.1.name')).must_equal 'centos-6.7'
_(resource.send('platforms.name')).must_equal %w{centos-5.11 centos-6.7}
end
it 'verify yaml parsing' do
_(resource.params).wont_be_nil
_(resource.send('driver.name')).must_equal 'vagrant'
_(resource.send('driver.customize.memory')).must_equal 1024
_(resource.send('platforms.1.name')).must_equal 'centos-6.7'
_(resource.send('platforms.name')).must_equal %w{centos-5.11 centos-6.7}
end
end

View file

@ -4,79 +4,77 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::YumRepo' do
describe 'yum' do
let(:resource) { loadResource('yum') }
let(:resource) { MockLoader.new(:centos7).load_resource('yum') }
it 'get repository details' do
_(resource.repositories).must_equal [{
'id'=>'base/7/x86_64',
'name'=>'CentOS-7 - Base',
'status'=>'enabled',
'revision'=>'1427842153',
'updated'=>'Tue Mar 31 22:50:46 2015',
'pkgs'=>'8652',
'size'=>'6.3 G',
'mirrors'=>'http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock',
'baseurl'=>'http://ftp.hosteurope.de/mirror/centos.org/7.1.1503/os/x86_64/ (9 more)',
'expire'=>'21600 second(s) (last: Sun Sep 6 10:20:46 2015)',
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo'
}, {
'id'=>'base-debuginfo/x86_64',
'name'=>'CentOS-7 - Debuginfo',
'status'=>'disabled',
'baseurl'=>'http://debuginfo.centos.org/7/x86_64/',
'expire'=>'21600 second(s) (last: Unknown)',
'filename'=>'/etc/yum.repos.d/CentOS-Debuginfo.repo'
}, {
'id'=>'extras/7/x86_64',
'name'=>'CentOS-7 - Extras',
'status'=>'enabled',
'revision'=>'1441314199',
'updated'=>'Thu Sep 3 21:03:33 2015',
'pkgs'=>'181',
'size'=>'742 M',
'mirrors'=>'http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock',
'baseurl'=>'http://mirror.informatik.hs-fulda.de/centos7.1.1503/extras/x86_64/ (9 more)',
'expire'=>'21600 second(s) (last: Sun Sep 6 10:20:48 2015)',
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo'
}]
_(resource.repos.length).must_equal 3
end
it 'get repository details' do
_(resource.repositories).must_equal [{
'id'=>'base/7/x86_64',
'name'=>'CentOS-7 - Base',
'status'=>'enabled',
'revision'=>'1427842153',
'updated'=>'Tue Mar 31 22:50:46 2015',
'pkgs'=>'8652',
'size'=>'6.3 G',
'mirrors'=>'http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock',
'baseurl'=>'http://ftp.hosteurope.de/mirror/centos.org/7.1.1503/os/x86_64/ (9 more)',
'expire'=>'21600 second(s) (last: Sun Sep 6 10:20:46 2015)',
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo',
}, {
'id'=>'base-debuginfo/x86_64',
'name'=>'CentOS-7 - Debuginfo',
'status'=>'disabled',
'baseurl'=>'http://debuginfo.centos.org/7/x86_64/',
'expire'=>'21600 second(s) (last: Unknown)',
'filename'=>'/etc/yum.repos.d/CentOS-Debuginfo.repo',
}, {
'id'=>'extras/7/x86_64',
'name'=>'CentOS-7 - Extras',
'status'=>'enabled',
'revision'=>'1441314199',
'updated'=>'Thu Sep 3 21:03:33 2015',
'pkgs'=>'181',
'size'=>'742 M',
'mirrors'=>'http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock',
'baseurl'=>'http://mirror.informatik.hs-fulda.de/centos7.1.1503/extras/x86_64/ (9 more)',
'expire'=>'21600 second(s) (last: Sun Sep 6 10:20:48 2015)',
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo',
}]
_(resource.repos.length).must_equal 3
end
it 'get repository details' do
_(resource.repos).must_equal %w{base/7/x86_64 base-debuginfo/x86_64 extras/7/x86_64}
end
it 'get repository details' do
_(resource.repos).must_equal %w{base/7/x86_64 base-debuginfo/x86_64 extras/7/x86_64}
end
# its('epel') { should exist }
# its('epel') { should be_enabled }
it 'test its syntax repo' do
_(resource.extras.exist?).must_equal true
_(resource.extras.enabled?).must_equal true
end
# its('epel') { should exist }
# its('epel') { should be_enabled }
it 'test its syntax repo' do
_(resource.extras.exist?).must_equal true
_(resource.extras.enabled?).must_equal true
end
it 'test enabled extra repo' do
extras = resource.repo('extras/7/x86_64')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal true
end
it 'test enabled extra repo' do
extras = resource.repo('extras/7/x86_64')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal true
end
it 'test enabled extra repo with short name' do
extras = resource.repo('extras')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal true
end
it 'test enabled extra repo with short name' do
extras = resource.repo('extras')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal true
end
it 'test disabled extra-source repo' do
extras = resource.repo('base-debuginfo/x86_64')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal false
end
it 'test disabled extra-source repo' do
extras = resource.repo('base-debuginfo/x86_64')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal false
end
# test serverspec syntax
let(:serverspec) { loadResource('yumrepo', 'extras') }
it 'test enabled extra repo (serverspec backwards comptability)' do
_(serverspec.exists?).must_equal true
_(serverspec.enabled?).must_equal true
end
# test serverspec syntax
let(:serverspec) { load_resource('yumrepo', 'extras') }
it 'test enabled extra repo (serverspec backwards comptability)' do
_(serverspec.exists?).must_equal true
_(serverspec.enabled?).must_equal true
end
end