overhaul test helper for mock data

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-09-06 20:24:25 +02:00
parent 305bb39668
commit 383738add2

View file

@ -6,37 +6,49 @@ require 'vulcano/backend'
# loads a resource class and instantiates the class with the given arguments
def loadResource (resource, *args)
# test mappings
scriptpath = IO::File.realpath(IO::File.dirname(__FILE__))
@mapping = {
'/proc/net/bonding/bond0' => IO::File.join(scriptpath, '/unit/mock/files/bond0'),
'/etc/ssh/ssh_config' => IO::File.join(scriptpath, '/unit/mock/files/ssh_config'),
'/etc/ssh/sshd_config' => IO::File.join(scriptpath, '/unit/mock/files/sshd_config'),
'/etc/passwd' => IO::File.join(scriptpath, '/unit/mock/files/passwd'),
'/etc/ntp.conf' => IO::File.join(scriptpath, '/unit/mock/files/ntp.conf'),
'/etc/login.defs' => IO::File.join(scriptpath, '/unit/mock/files/login.defs'),
'/etc/security/limits.conf' => IO::File.join(scriptpath, '/unit/mock/files/limits.conf'),
'/etc/inetd.conf' => IO::File.join(scriptpath, '/unit/mock/files/inetd.conf'),
'/etc/group' => IO::File.join(scriptpath, '/unit/mock/files/group'),
'/etc/audit/auditd.conf' => IO::File.join(scriptpath, '/unit/mock/files/auditd.conf')
}
@cmd_mapping = {
'ps aux' => IO::File.join(scriptpath, '/unit/mock/cmd/ps-aux'),
'type win_secpol.cfg' => IO::File.join(scriptpath, '/unit/mock/cmd/secedit-export'),
'secedit /export /cfg win_secpol.cfg' => IO::File.join(scriptpath, '/unit/mock/cmd/success'),
'del win_secpol.cfg' => IO::File.join(scriptpath, '/unit/mock/cmd/success'),
'su - root -c \'echo $PATH\'' => IO::File.join(scriptpath, '/unit/mock/cmd/PATH'),
'(Get-Item \'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule\').GetValue(\'Start\')' => IO::File.join(scriptpath, '/unit/mock/cmd/reg_schedule'),
'Auditpol /get /subcategory:\'User Account Management\' /r' => IO::File.join(scriptpath, '/unit/mock/cmd/auditpol'),
'/sbin/auditctl -l' => IO::File.join(scriptpath, '/unit/mock/cmd/auditctl'),
'yum -v repolist all' => IO::File.join(scriptpath, '/unit/mock/cmd/yum-repolist-all')
}
# create mock backend
conf = Vulcano::Backend.target_config({})
backend_class = Vulcano::Backend.registry['mock']
@backend = backend_class.new(conf, @mapping, @cmd_mapping)
@backend = backend_class.new(conf)
# create all mock files
local = Vulcano::Backend.registry['local'].new({})
mockfile = lambda { |x|
path = IO::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')
}
# create all mock commands
Struct.new("MockCommand", :stdout, :stderr, :exit_status)
cmd = lambda {|x|
stdout = IO::File.read(IO::File.join(scriptpath, '/unit/mock/cmd/'+x))
Struct::MockCommand.new( stdout, '', 0 )
}
@backend.commands = {
'ps aux' => cmd.('ps-aux'),
'type win_secpol.cfg' => cmd.('secedit-export'),
'secedit /export /cfg win_secpol.cfg' => cmd.('success'),
'del win_secpol.cfg' => cmd.('success'),
'su - root -c \'echo $PATH\'' => cmd.('PATH'),
'(Get-Item \'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule\').GetValue(\'Start\')' => cmd.('reg_schedule'),
'Auditpol /get /subcategory:\'User Account Management\' /r' => cmd.('auditpol'),
'/sbin/auditctl -l' => cmd.('auditctl'),
'yum -v repolist all' => cmd.('yum-repolist-all'),
}
# load resource
@rclass = Vulcano::Resource.registry[resource]