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,14 +14,35 @@ end
require 'vulcano/backend' require 'vulcano/backend'
require 'vulcano/resource' require 'vulcano/resource'
# loads a resource class and instantiates the class with the given arguments class MockLoader
def loadResource (resource, *args) # 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' },
}
# selects operating system
@os = @operating_systems[os || :ubuntu1404]
end
# loads a resource class and instantiates the class with the given arguments
def load_resource(resource, *args)
scriptpath = ::File.realpath(::File.dirname(__FILE__)) scriptpath = ::File.realpath(::File.dirname(__FILE__))
# create mock backend # create mock backend
conf = Vulcano::Backend.target_config({ conf = Vulcano::Backend.target_config({ quiet: true })
quiet: true
})
backend_class = Vulcano::Backend.registry['mock'] backend_class = Vulcano::Backend.registry['mock']
@backend = backend_class.new(conf) @backend = backend_class.new(conf)
@ -32,27 +53,27 @@ def loadResource (resource, *args)
local.file(path) local.file(path)
} }
@backend.files = { @backend.files = {
'/proc/net/bonding/bond0' => mockfile.('bond0'), '/proc/net/bonding/bond0' => mockfile.call('bond0'),
'/etc/ssh/ssh_config' => mockfile.('ssh_config'), '/etc/ssh/ssh_config' => mockfile.call('ssh_config'),
'/etc/ssh/sshd_config' => mockfile.('sshd_config'), '/etc/ssh/sshd_config' => mockfile.call('sshd_config'),
'/etc/passwd' => mockfile.('passwd'), '/etc/passwd' => mockfile.call('passwd'),
'/etc/ntp.conf' => mockfile.('ntp.conf'), '/etc/ntp.conf' => mockfile.call('ntp.conf'),
'/etc/login.defs' => mockfile.('login.defs'), '/etc/login.defs' => mockfile.call('login.defs'),
'/etc/security/limits.conf' => mockfile.('limits.conf'), '/etc/security/limits.conf' => mockfile.call('limits.conf'),
'/etc/inetd.conf' => mockfile.('inetd.conf'), '/etc/inetd.conf' => mockfile.call('inetd.conf'),
'/etc/group' => mockfile.('group'), '/etc/group' => mockfile.call('group'),
'/etc/audit/auditd.conf' => mockfile.('auditd.conf'), '/etc/audit/auditd.conf' => mockfile.call('auditd.conf'),
'/etc/mysql/my.cnf' => mockfile.('mysql.conf'), '/etc/mysql/my.cnf' => mockfile.call('mysql.conf'),
'/etc/mysql/mysql2.conf' => mockfile.('mysql2.conf'), '/etc/mysql/mysql2.conf' => mockfile.call('mysql2.conf'),
'kitchen.yml' => mockfile.('kitchen.yml'), 'kitchen.yml' => mockfile.call('kitchen.yml'),
'example.csv' => mockfile.('example.csv'), 'example.csv' => mockfile.call('example.csv'),
'policyfile.lock.json' => mockfile.('policyfile.lock.json'), 'policyfile.lock.json' => mockfile.call('policyfile.lock.json'),
} }
# create all mock commands # create all mock commands
cmd = lambda {|x| cmd = lambda {|x|
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x)) stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
@backend.mock_command( stdout, '', 0 ) @backend.mock_command(stdout, '', 0)
} }
@backend.commands = { @backend.commands = {
'ps aux' => cmd.call('ps-aux'), 'ps aux' => cmd.call('ps-aux'),
@ -77,6 +98,9 @@ def loadResource (resource, *args)
'/sbin/sysctl -q -n net.ipv4.conf.all.forwarding' => cmd.call('sbin_sysctl'), '/sbin/sysctl -q -n net.ipv4.conf.all.forwarding' => cmd.call('sbin_sysctl'),
} }
# set os emulation
@backend.os = @os
# load resource # load resource
@rclass = Vulcano::Resource.registry[resource] @rclass = Vulcano::Resource.registry[resource]
@ -85,4 +109,10 @@ def loadResource (resource, *args)
# initialize resource with backend and parameters # initialize resource with backend and parameters
@resource = @rclass.new(*args) @resource = @rclass.new(*args)
end
end
def load_resource(*args)
m = MockLoader.new(:ubuntu1404)
m.send('load_resource', *args)
end end

View file

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

View file

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

View file

@ -4,8 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::AuditDaemonRules' do describe 'Vulcano::Resources::AuditDaemonRules' do
describe 'audit_daemon_rules' do let(:resource) { load_resource('audit_daemon_rules') }
let(:resource) { loadResource('audit_daemon_rules') }
it 'check audit policy parsing' do it 'check audit policy parsing' do
_(resource.send('LIST_RULES')).must_equal [ _(resource.send('LIST_RULES')).must_equal [
@ -15,8 +14,7 @@ describe 'Vulcano::Resources::AuditDaemonRules' do
'exit,always watch=/etc/passwd perm=wa', 'exit,always watch=/etc/passwd perm=wa',
'exit,always watch=/etc/shadow perm=wa', 'exit,always watch=/etc/shadow perm=wa',
'exit,always watch=/etc/sudoers perm=wa', 'exit,always watch=/etc/sudoers perm=wa',
'exit,always watch=/etc/secret_directory perm=r' 'exit,always watch=/etc/secret_directory perm=r',
] ]
end end
end
end end

View file

@ -4,10 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::Bond' do describe 'Vulcano::Resources::Bond' do
let(:resource) { load_resource('bond', 'bond0') }
describe 'parse bond config' do
let(:resource) { loadResource('bond', 'bond0') }
it 'bond must be available' do it 'bond must be available' do
resource.exist?.must_equal true resource.exist?.must_equal true
@ -27,5 +24,4 @@ describe 'Vulcano::Resources::Bond' do
_(resource.content).wont_equal nil _(resource.content).wont_equal nil
_(resource.content).wont_equal '' _(resource.content).wont_equal ''
end end
end
end end

View file

@ -4,14 +4,11 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::CSV' do 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 it 'verify csv parsing' do
_(resource.params).wont_equal nil _(resource.params).wont_equal nil
_(resource.send('1.addressable')).must_equal 'astrolabe' _(resource.send('1.addressable')).must_equal 'astrolabe'
_(resource.send('addressable')).must_equal %w{ast astrolabe berkshelf} _(resource.send('addressable')).must_equal %w{ast astrolabe berkshelf}
end end
end
end end

View file

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

View file

@ -4,8 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::EtcGroup' do describe 'Vulcano::Resources::EtcGroup' do
describe 'etc_group' do let(:resource) { load_resource('etc_group') }
let(:resource) { loadResource('etc_group') }
it 'verify /etc/group config parsing' do it 'verify /etc/group config parsing' do
_(resource.gids).must_equal %w{ 0 33 } _(resource.gids).must_equal %w{ 0 33 }
@ -33,5 +32,4 @@ describe 'Vulcano::Resources::EtcGroup' do
_(wrong_filter.groups).must_equal [] _(wrong_filter.groups).must_equal []
_(wrong_filter.users).must_equal [] _(wrong_filter.users).must_equal []
end end
end
end end

View file

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

View file

@ -4,9 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::JSON' do 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 it 'verify json parsing' do
_(resource.params).wont_equal nil _(resource.params).wont_equal nil
@ -14,5 +12,4 @@ describe 'Vulcano::Resources::JSON' do
_(resource.send('run_list')).must_equal %w{apache2 omnibus} _(resource.send('run_list')).must_equal %w{apache2 omnibus}
_(resource.send('cookbook_locks.omnibus.version')).must_equal '2.2.0' _(resource.send('cookbook_locks.omnibus.version')).must_equal '2.2.0'
end end
end
end end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,8 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do describe 'Vulcano::Resources::Passwd' do
describe 'oneget' do let(:resource) { load_resource('oneget', 'Mozilla Firefox') }
let(:resource) { loadResource('oneget', 'Mozilla Firefox') }
it 'verify oneget package detail parsing' do it 'verify oneget package detail parsing' do
pkg = { pkg = {
@ -17,5 +16,4 @@ describe 'Vulcano::Resources::Passwd' do
_(resource.installed?).must_equal true _(resource.installed?).must_equal true
_(resource.info).must_equal pkg _(resource.info).must_equal pkg
end end
end
end end

View file

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

View file

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

View file

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

View file

@ -4,8 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::Processes' do describe 'Vulcano::Resources::Processes' do
describe 'processes' do let(:resource) { load_resource('processes', '/bin/bash') }
let(:resource) { loadResource('processes', '/bin/bash') }
it 'verify processes resource' do it 'verify processes resource' do
_(resource.list).must_equal [{ _(resource.list).must_equal [{
@ -24,5 +23,4 @@ describe 'Vulcano::Resources::Processes' do
_(resource.list.length).must_equal 1 _(resource.list.length).must_equal 1
end end
end
end end

View file

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

View file

@ -4,8 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::SecurityPolicy' do describe 'Vulcano::Resources::SecurityPolicy' do
describe 'security_policy' do let(:resource) { load_resource('security_policy') }
let(:resource) { loadResource('security_policy') }
it 'verify processes resource' do it 'verify processes resource' do
_(resource.MaximumPasswordAge).must_equal 42 _(resource.MaximumPasswordAge).must_equal 42
@ -13,5 +12,4 @@ describe 'Vulcano::Resources::SecurityPolicy' do
_(resource.SeUndockPrivilege).must_equal '*S-1-5-32-544' _(resource.SeUndockPrivilege).must_equal '*S-1-5-32-544'
_(resource.SeRemoteInteractiveLogonRight).must_equal '*S-1-5-32-544,*S-1-5-32-555' _(resource.SeRemoteInteractiveLogonRight).must_equal '*S-1-5-32-544,*S-1-5-32-555'
end end
end
end end

View file

@ -4,10 +4,8 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::Service' do describe 'Vulcano::Resources::Service' do
describe 'service' do
# TODO: make OS dependent # TODO: make OS dependent
let(:resource) { loadResource('service', 'dhcp') } let(:resource) { load_resource('service', 'dhcp') }
# windows # windows
# it 'verify service parsing' do # it 'verify service parsing' do
@ -17,5 +15,4 @@ describe 'Vulcano::Resources::Service' do
# _(resource.enabled?).must_equal true # _(resource.enabled?).must_equal true
# _(resource.running?).must_equal true # _(resource.running?).must_equal true
# end # end
end
end end

View file

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

View file

@ -6,7 +6,7 @@ require 'vulcano/resource'
describe 'Vulcano:Resources::Feature' do describe 'Vulcano:Resources::Feature' do
describe '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 # TODO: set windows as mock os
it 'verify windows feature parsing' do it 'verify windows feature parsing' do

View file

@ -4,9 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::YAML' do 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 it 'verify yaml parsing' do
_(resource.params).wont_be_nil _(resource.params).wont_be_nil
@ -15,5 +13,4 @@ describe 'Vulcano::Resources::YAML' do
_(resource.send('platforms.1.name')).must_equal 'centos-6.7' _(resource.send('platforms.1.name')).must_equal 'centos-6.7'
_(resource.send('platforms.name')).must_equal %w{centos-5.11 centos-6.7} _(resource.send('platforms.name')).must_equal %w{centos-5.11 centos-6.7}
end end
end
end end

View file

@ -4,8 +4,7 @@ require 'helper'
require 'vulcano/resource' require 'vulcano/resource'
describe 'Vulcano::Resources::YumRepo' do describe 'Vulcano::Resources::YumRepo' do
describe 'yum' do let(:resource) { MockLoader.new(:centos7).load_resource('yum') }
let(:resource) { loadResource('yum') }
it 'get repository details' do it 'get repository details' do
_(resource.repositories).must_equal [{ _(resource.repositories).must_equal [{
@ -19,14 +18,14 @@ describe 'Vulcano::Resources::YumRepo' do
'mirrors'=>'http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock', '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)', '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)', 'expire'=>'21600 second(s) (last: Sun Sep 6 10:20:46 2015)',
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo' 'filename'=>'/etc/yum.repos.d/CentOS-Base.repo',
}, { }, {
'id'=>'base-debuginfo/x86_64', 'id'=>'base-debuginfo/x86_64',
'name'=>'CentOS-7 - Debuginfo', 'name'=>'CentOS-7 - Debuginfo',
'status'=>'disabled', 'status'=>'disabled',
'baseurl'=>'http://debuginfo.centos.org/7/x86_64/', 'baseurl'=>'http://debuginfo.centos.org/7/x86_64/',
'expire'=>'21600 second(s) (last: Unknown)', 'expire'=>'21600 second(s) (last: Unknown)',
'filename'=>'/etc/yum.repos.d/CentOS-Debuginfo.repo' 'filename'=>'/etc/yum.repos.d/CentOS-Debuginfo.repo',
}, { }, {
'id'=>'extras/7/x86_64', 'id'=>'extras/7/x86_64',
'name'=>'CentOS-7 - Extras', 'name'=>'CentOS-7 - Extras',
@ -38,7 +37,7 @@ describe 'Vulcano::Resources::YumRepo' do
'mirrors'=>'http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock', '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)', '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)', 'expire'=>'21600 second(s) (last: Sun Sep 6 10:20:48 2015)',
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo' 'filename'=>'/etc/yum.repos.d/CentOS-Base.repo',
}] }]
_(resource.repos.length).must_equal 3 _(resource.repos.length).must_equal 3
end end
@ -73,10 +72,9 @@ describe 'Vulcano::Resources::YumRepo' do
end end
# test serverspec syntax # test serverspec syntax
let(:serverspec) { loadResource('yumrepo', 'extras') } let(:serverspec) { load_resource('yumrepo', 'extras') }
it 'test enabled extra repo (serverspec backwards comptability)' do it 'test enabled extra repo (serverspec backwards comptability)' do
_(serverspec.exists?).must_equal true _(serverspec.exists?).must_equal true
_(serverspec.enabled?).must_equal true _(serverspec.enabled?).must_equal true
end end
end
end end