Merge pull request #106 from chef/improve-unit-tests

Merged change bc858650-a843-4b95-a43c-361183d79ad1

From review branch improve-unit-tests into master

Signed-off-by: drichter <drichter@chef.io>
This commit is contained in:
chef-delivery 2015-10-12 05:00:49 -07:00
commit 3f67521514
29 changed files with 144 additions and 195 deletions

View file

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

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::AuditDaemonConf' do
let(:resource) { load_resource('audit_daemon_conf') }
it 'check audit daemon config parsing' do
resource = MockLoader.new(:windows).load_resource('audit_daemon_conf')
_(resource.space_left_action).must_equal 'SYSLOG'
_(resource.action_mail_acct).must_equal 'root'
_(resource.tcp_listen_queue).must_equal '5'

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::AuditDaemonRules' do
let(:resource) { load_resource('audit_daemon_rules') }
it 'check audit policy parsing' do
resource = MockLoader.new(:windows).load_resource('audit_daemon_rules')
_(resource.send('LIST_RULES')).must_equal [
'exit,always syscall=rmdir,unlink',
'exit,always auid=1001 (0x3e9) syscall=open',

View file

@ -6,23 +6,18 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Bond' do
let(:resource) { load_resource('bond', 'bond0') }
it 'bond must be available' do
it 'check linux bond on ubuntu' do
resource = MockLoader.new(:ubuntu1404).load_resource('bond', 'bond0')
# bond must be available
resource.exist?.must_equal true
end
it 'eth0 is part of bond' do
# eth0 is part of bond
_(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
# get all interfaces
_(resource.interfaces).must_equal %w{eth0 eth2}
end
it 'get proc content' do
# get proc content
_(resource.content).wont_equal nil
_(resource.content).wont_equal ''
end

View file

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

View file

@ -5,10 +5,9 @@
require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
let(:resource) { load_resource('gem', 'rubocop') }
describe 'Vulcano::Resources::Gem' do
it 'verify gem package detail parsing' do
resource = load_resource('gem', 'rubocop')
pkg = {
name: 'rubocop',
version: '0.33.0',

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::InetdConf' do
let(:resource) { load_resource('inetd_config') }
it 'verify limits.conf config parsing' do
resource = load_resource('inetd_config')
_(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}

View file

@ -5,7 +5,7 @@
require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Group' do
describe 'Vulcano::Resources::Interface' do
# ubuntu 14.04
it 'verify interface on ubuntu' do

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::JSON' do
resource = load_resource('json', 'policyfile.lock.json')
it 'verify json parsing' do
resource = load_resource('json', 'policyfile.lock.json')
_(resource.params).wont_equal nil
_(resource.send('name')).must_equal 'demo'
_(resource.send('run_list')).must_equal %w{apache2 omnibus}

View file

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

View file

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

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::LoginDef' do
let(:resource) { load_resource('login_defs') }
it 'verify login.def config parsing' do
resource = load_resource('login_defs')
_(resource.UMASK).must_equal '022'
_(resource.PASS_MIN_DAYS).must_equal '0'
_(resource.PASS_WARN_AGE).must_equal '7'

View file

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

View file

@ -5,10 +5,9 @@
require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
let(:resource) { load_resource('npm', 'bower') }
describe 'Vulcano::Resources::Npm' do
it 'verify npm package detail parsing' do
resource = load_resource('npm', 'bower')
pkg = {
name: 'bower',
version: '1.4.1',

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::NtpConf' do
let(:resource) { load_resource('ntp_conf') }
it 'verify ntp config parsing' do
resource = load_resource('ntp_conf')
_(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

View file

@ -5,7 +5,7 @@
require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'Vulcano::Resources::OneGet' do
it 'verify oneget package detail parsing' do
resource = MockLoader.new(:windows).load_resource('oneget', 'Mozilla Firefox')

View file

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

View file

@ -5,49 +5,47 @@
require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Passwd' do
describe 'package' do
# 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
describe 'Vulcano::Resources::Package' do
# 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
# 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
# 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
# centos
it 'verify centos package parsing' do
resource = MockLoader.new(:centos7).load_resource('package', 'curl')
pkg = { name: 'curl', installed: true, version: '7.29.0', type: 'rpm' }
_(resource.installed?).must_equal true
_(resource.version).must_equal '7.29.0'
_(resource.info).must_equal pkg
end
# centos
it 'verify centos package parsing' do
resource = MockLoader.new(:centos7).load_resource('package', 'curl')
pkg = { name: 'curl', installed: true, version: '7.29.0', type: 'rpm' }
_(resource.installed?).must_equal true
_(resource.version).must_equal '7.29.0'
_(resource.info).must_equal pkg
end
# # windows
it 'verify windows package parsing' do
resource = MockLoader.new(:windows).load_resource('package', 'Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161')
pkg = { name: 'Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161', installed: true, version: '9.0.30729.6161', type: 'windows' }
_(resource.installed?).must_equal true
_(resource.version).must_equal '9.0.30729.6161'
_(resource.info).must_equal pkg
end
# windows
it 'verify windows package parsing' do
resource = MockLoader.new(:windows).load_resource('package', 'Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161')
pkg = { name: 'Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161', installed: true, version: '9.0.30729.6161', type: 'windows' }
_(resource.installed?).must_equal true
_(resource.version).must_equal '9.0.30729.6161'
_(resource.info).must_equal pkg
end
# undefined
it 'verify package handling on unsupported os' do
resource = MockLoader.new(:undefined).load_resource('package', 'curl')
_(resource.installed?).must_equal false
_(resource.info).must_equal nil
end
# undefined
it 'verify package handling on unsupported os' do
resource = MockLoader.new(:undefined).load_resource('package', 'curl')
_(resource.installed?).must_equal false
_(resource.info).must_equal nil
end
end

View file

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

View file

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

View file

@ -6,7 +6,6 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Port' do
it 'verify port on Ubuntu 14.04' do
resource = MockLoader.new(:ubuntu1404).load_resource('port', 22)
_(resource.listening?).must_equal true

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Processes' do
let(:resource) { load_resource('processes', '/bin/bash') }
it 'verify processes resource' do
resource = load_resource('processes', '/bin/bash')
_(resource.list).must_equal [{
user: 'root',
pid: '1',
@ -20,7 +19,7 @@ describe 'Vulcano::Resources::Processes' do
stat: 'Ss',
start: '14:15',
time: '0:00',
command: '/bin/bash'
command: '/bin/bash',
}]
_(resource.list.length).must_equal 1

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::SecurityPolicy' do
let(:resource) { load_resource('security_policy') }
it 'verify processes resource' do
resource = load_resource('security_policy')
_(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'

View file

@ -8,28 +8,25 @@ require 'vulcano/resource'
describe 'Vulcano::Resources::SshConf' do
describe 'ssh_config' do
let(:resource) { load_resource('ssh_config') }
it 'check ssh config parsing' do
resource = load_resource('ssh_config')
_(resource.Host).must_equal '*'
_(resource.Tunnel).must_equal nil
_(resource.SendEnv).must_equal 'LANG LC_*'
_(resource.HashKnownHosts).must_equal 'yes'
end
end
describe 'sshd_config' do
let(:resource) { load_resource('sshd_config') }
it 'check protocol version' do
resource = load_resource('sshd_config')
_(resource.Port).must_equal '22'
_(resource.UsePAM).must_equal 'yes'
_(resource.ListenAddress).must_equal nil
_(resource.HostKey).must_equal [
'/etc/ssh/ssh_host_rsa_key',
'/etc/ssh/ssh_host_dsa_key',
'/etc/ssh/ssh_host_ecdsa_key'
'/etc/ssh/ssh_host_ecdsa_key',
]
end
end

View file

@ -5,7 +5,7 @@
require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::Service' do
describe 'Vulcano::Resources::User' do
# ubuntu 14.04 with upstart
it 'read user on ubuntu' do

View file

@ -7,11 +7,8 @@ require 'vulcano/resource'
describe 'Vulcano:Resources::Feature' do
describe 'feature' do
let(:resource) { MockLoader.new(:windows).load_resource('windows_feature', 'dhcp') }
# TODO: set windows as mock os
it 'verify windows feature parsing' do
resource = MockLoader.new(:windows).load_resource('windows_feature', 'dhcp')
pkg = { name: 'DHCP', description: 'Dynamic Host Configuration Protocol (DHCP) Server enables you to centrally configure, manage, and provide temporary IP addresses and related information for client computers.', installed: false, type: 'windows-feature' }
_(resource.info).must_equal pkg
_(resource.installed?).must_equal false

View file

@ -4,9 +4,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::YAML' do
let(:resource) { load_resource('yaml', 'kitchen.yml') }
it 'verify yaml parsing' do
resource = load_resource('yaml', 'kitchen.yml')
_(resource.params).wont_be_nil
_(resource.send('driver.name')).must_equal 'vagrant'
_(resource.send('driver.customize.memory')).must_equal 1024

View file

@ -6,9 +6,8 @@ require 'helper'
require 'vulcano/resource'
describe 'Vulcano::Resources::YumRepo' do
let(:resource) { MockLoader.new(:centos7).load_resource('yum') }
it 'get repository details' do
resource = MockLoader.new(:centos7).load_resource('yum')
_(resource.repositories).must_equal [{
'id'=>'base/7/x86_64',
'name'=>'CentOS-7 - Base',
@ -42,40 +41,27 @@ describe 'Vulcano::Resources::YumRepo' do
'filename'=>'/etc/yum.repos.d/CentOS-Base.repo',
}]
_(resource.repos.length).must_equal 3
end
it 'get repository details' do
# get repository details
_(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
# test its syntax repo
_(resource.extras.exist?).must_equal true
_(resource.extras.enabled?).must_equal true
end
it 'test enabled extra repo' do
# test enabled extra repo
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
# test enabled extra repo with short name
extras = resource.repo('extras')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal true
end
it 'test disabled extra-source repo' do
# test disabled extra-source repo
extras = resource.repo('base-debuginfo/x86_64')
_(extras.exist?).must_equal true
_(extras.enabled?).must_equal false
end
# test serverspec syntax
let(:serverspec) { load_resource('yumrepo', 'extras') }
it 'test enabled extra repo (serverspec backwards comptability)' do
serverspec = load_resource('yumrepo', 'extras')
_(serverspec.exists?).must_equal true
_(serverspec.enabled?).must_equal true
end

View file

@ -4,79 +4,77 @@
require 'helper'
describe 'SimpleConfig' do
describe 'default parser' do
it 'should parse an empty string' do
cur = SimpleConfig.new('')
cur.params.must_equal({})
end
describe 'SimpleConfig Default Parser' do
it 'should parse an empty string' do
cur = SimpleConfig.new('')
cur.params.must_equal({})
end
it 'should parse only spaces' do
cur = SimpleConfig.new(' ')
cur.params.must_equal({})
end
it 'should parse only spaces' do
cur = SimpleConfig.new(' ')
cur.params.must_equal({})
end
it 'should parse only tabs' do
cur = SimpleConfig.new("\t")
cur.params.must_equal({})
end
it 'should parse only tabs' do
cur = SimpleConfig.new("\t")
cur.params.must_equal({})
end
it 'should parse only newlines' do
cur = SimpleConfig.new("\n")
cur.params.must_equal({})
end
it 'should parse only newlines' do
cur = SimpleConfig.new("\n")
cur.params.must_equal({})
end
it 'should parse a simple assignment' do
cur = SimpleConfig.new('a = b')
cur.params.must_equal({ 'a' => 'b' })
end
it 'should parse a simple assignment' do
cur = SimpleConfig.new('a = b')
cur.params.must_equal({ 'a' => 'b' })
end
it 'should parse a multiple assignments' do
cur = SimpleConfig.new("a = b\n\nc = d")
cur.params.must_equal({ 'a' => 'b', 'c' => 'd' })
end
it 'should parse a multiple assignments' do
cur = SimpleConfig.new("a = b\n\nc = d")
cur.params.must_equal({ 'a' => 'b', 'c' => 'd' })
end
it 'handles files with only comments' do
cur = SimpleConfig.new('#a comment')
cur.params.must_equal({})
end
it 'handles files with only comments' do
cur = SimpleConfig.new('#a comment')
cur.params.must_equal({})
end
it 'handles separate comments and assignments' do
cur = SimpleConfig.new("# hello world\n\na = b")
cur.params.must_equal({ 'a' => 'b' })
end
it 'handles separate comments and assignments' do
cur = SimpleConfig.new("# hello world\n\na = b")
cur.params.must_equal({ 'a' => 'b' })
end
it 'handles comments and assignments combined' do
cur = SimpleConfig.new('a = b# hello')
cur.params.must_equal({ 'a' => 'b' })
end
it 'handles comments and assignments combined' do
cur = SimpleConfig.new('a = b# hello')
cur.params.must_equal({ 'a' => 'b' })
end
it 'handles groups' do
cur = SimpleConfig.new('[g]')
cur.params.must_equal({ 'g' => {} })
cur.groups.must_equal(['g'])
end
it 'handles groups' do
cur = SimpleConfig.new('[g]')
cur.params.must_equal({ 'g' => {} })
cur.groups.must_equal(['g'])
end
it 'handles non-group assignments and groups' do
cur = SimpleConfig.new("a = b\n[g]")
cur.params.must_equal({ 'a' => 'b', 'g' => {} })
cur.groups.must_equal(['g'])
end
it 'handles non-group assignments and groups' do
cur = SimpleConfig.new("a = b\n[g]")
cur.params.must_equal({ 'a' => 'b', 'g' => {} })
cur.groups.must_equal(['g'])
end
it 'handles assignments in groups' do
cur = SimpleConfig.new("[g]\na = b")
cur.params.must_equal({ 'g' => { 'a' => 'b' } })
cur.groups.must_equal(['g'])
end
it 'handles assignments in groups' do
cur = SimpleConfig.new("[g]\na = b")
cur.params.must_equal({ 'g' => { 'a' => 'b' } })
cur.groups.must_equal(['g'])
end
it 'handles multiple groups' do
cur = SimpleConfig.new("[g]\na = b\n[k]\n\nc = d")
res = {
'g' => { 'a' => 'b' },
'k' => { 'c' => 'd' },
}
cur.params.must_equal(res)
cur.groups.must_equal(['g', 'k'])
end
it 'handles multiple groups' do
cur = SimpleConfig.new("[g]\na = b\n[k]\n\nc = d")
res = {
'g' => { 'a' => 'b' },
'k' => { 'c' => 'd' },
}
cur.params.must_equal(res)
cur.groups.must_equal(['g', 'k'])
end
end