Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make rspec more awesome #304

Merged
merged 3 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 55 additions & 49 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
end
# Make sure package will be installed, service running and ensure of directory.
it do
should contain_package(package).with(
is_expected.to contain_package(package).with(
ensure: 'present',
require: 'Class[Zabbix::Repo]',
tag: 'zabbix'
)
end

it do
should contain_service('zabbix-agent').with(
is_expected.to contain_service('zabbix-agent').with(
ensure: 'running',
enable: true,
hasstatus: true,
Expand All @@ -56,10 +56,10 @@
)
end

it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') }
it { should contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") }
it { should compile.with_all_deps }
it { should contain_class('zabbix::params') }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') }
it { is_expected.to contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('zabbix::params') }
end

context 'when declaring manage_repo is true' do
Expand All @@ -71,10 +71,16 @@

case facts[:osfamily]
when 'Archlinux'
it { should raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented}) }
else
it { should contain_class('zabbix::repo').with_zabbix_version('3.0') }
it { should contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented}) }
when 'Debian'
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.0') }
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to contain_apt__source('zabbix') }
when 'RedHat'
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.0') }
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
it { is_expected.to contain_yumrepo('zabbix') }
end
end

Expand All @@ -85,7 +91,7 @@
}
end

it { should contain_class('zabbix::resources::agent') }
it { is_expected.to contain_class('zabbix::resources::agent') }
end

context 'configuration file with hostnameitem' do
Expand All @@ -95,7 +101,7 @@
}
end

it { should contain_file(config_path).with_content %r{^HostnameItem=system.hostname$} }
it { is_expected.to contain_file(config_path).with_content %r{^HostnameItem=system.hostname$} }
end

context 'ignores hostnameitem if hostname is set' do
Expand All @@ -106,8 +112,8 @@
}
end

it { should contain_file(config_path).without_content %r{^HostnameItem=system.hostname$} }
it { should contain_file(config_path).with_content %r{^Hostname=test$} }
it { is_expected.to contain_file(config_path).without_content %r{^HostnameItem=system.hostname$} }
it { is_expected.to contain_file(config_path).with_content %r{^Hostname=test$} }
end

context 'when declaring manage_firewall is true' do
Expand All @@ -117,7 +123,7 @@
}
end

it { should contain_firewall('150 zabbix-agent') }
it { is_expected.to contain_firewall('150 zabbix-agent') }
end

context 'when declaring manage_firewall is false' do
Expand All @@ -127,17 +133,17 @@
}
end

it { should_not contain_firewall('150 zabbix-agent') }
it { is_expected.not_to contain_firewall('150 zabbix-agent') }
end

context 'it creates a startup script' do
case facts[:osfamily]
when 'Archlinux', 'Fedora'
it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') }
it { should contain_file('/etc/systemd/system/zabbix-agent.service').with_ensure('file') }
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with_ensure('file') }
else
it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('file') }
it { should_not contain_file('/etc/systemd/system/zabbix-agent.service') }
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('file') }
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-agent.service') }
end
end
context 'configuration file with full options' do
Expand Down Expand Up @@ -176,35 +182,35 @@
}
end

it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^EnableRemoteCommands=1$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Hostname=10050$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Include=/etc/zabbix/zabbix_agentd.d$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ListenPort=10050$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFileSize=4$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_agentd.log$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogRemoteCommands=0$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_agentd.pid$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^RefreshActiveChecks=120$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Server=192.168.1.1$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ServerActive=192.168.1.1$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^StartAgents=3$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Timeout=30$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^UnsafeUserParameters=0$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSConnect=cert$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSAccept=cert$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/file.ca$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/file.crl$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertIssuer=Zabbix.Com$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertSubject=MySubJect$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/tls.crt$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/tls.key$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKIdentity=/etc/zabbix/keys/tlspskidentity.id$} }
it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKFile=/etc/zabbix/keys/tlspskfile.key$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^AllowRoot=0$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSend=5$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^BufferSize=100$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^DebugLevel=4$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^EnableRemoteCommands=1$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Hostname=10050$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Include=/etc/zabbix/zabbix_agentd.d$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ListenPort=10050$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFileSize=4$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_agentd.log$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^LogRemoteCommands=0$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^PidFile=/var/run/zabbix/zabbix_agentd.pid$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^RefreshActiveChecks=120$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Server=192.168.1.1$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^ServerActive=192.168.1.1$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^StartAgents=3$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^Timeout=30$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^UnsafeUserParameters=0$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSConnect=cert$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSAccept=cert$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCAFile=/etc/zabbix/keys/file.ca$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCRLFile=/etc/zabbix/keys/file.crl$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertIssuer=Zabbix.Com$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSServerCertSubject=MySubJect$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSCertFile=/etc/zabbix/keys/tls.crt$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSKeyFile=/etc/zabbix/keys/tls.key$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKIdentity=/etc/zabbix/keys/tlspskidentity.id$} }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^TLSPSKFile=/etc/zabbix/keys/tlspskfile.key$} }
end
end
end
Expand Down
45 changes: 23 additions & 22 deletions spec/classes/database_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end
context 'with all defaults' do
it 'fails' do
should raise_error(Puppet::Error, %r{We do not work.})
is_expected.to raise_error(Puppet::Error, %r{We do not work.})
end
end
path2 = if facts[:osfamily] == 'RedHat'
Expand All @@ -36,11 +36,12 @@
}
end

it { should contain_class('zabbix::database::mysql') }
it { should compile.with_all_deps }
it { should contain_exec('zabbix_server_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < schema.sql && touch /etc/zabbix/.schema.done") }
it { should contain_exec('zabbix_server_images.sql').with_command("cd #{path2} && if [ -f images.sql.gz ]; then gunzip -f images.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < images.sql && touch /etc/zabbix/.images.done") }
it { should contain_exec('zabbix_server_data.sql').with_command("cd #{path2} && if [ -f data.sql.gz ]; then gunzip -f data.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < data.sql && touch /etc/zabbix/.data.done") }
it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < schema.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command("cd #{path2} && if [ -f images.sql.gz ]; then gunzip -f images.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < images.sql && touch /etc/zabbix/.images.done") }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command("cd #{path2} && if [ -f data.sql.gz ]; then gunzip -f data.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < data.sql && touch /etc/zabbix/.data.done") }
it { is_expected.to contain_class('zabbix::params') }
end

describe 'when zabbix_type is proxy and zabbix version is 2.4' do
Expand All @@ -54,10 +55,10 @@
zabbix_version: '2.4'
}
end
it { should contain_class('zabbix::database::mysql') }
it { is_expected.to contain_class('zabbix::database::mysql') }
# this doesn't make much sense because the class requires other classes
# it { should compile.with_all_deps }
it { should contain_exec('zabbix_proxy_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
context 'when zabbix_type is server and zabbix version is 3.0' do
let :params do
Expand All @@ -70,11 +71,11 @@
zabbix_version: '3.0'
}
end
it { should contain_class('zabbix::database::mysql') }
it { should compile.with_all_deps }
it { should contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { should contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { should contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
end

describe 'when zabbix_type is proxy and zabbix version is 3.0' do
Expand All @@ -88,10 +89,10 @@
zabbix_version: '3.0'
}
end
it { should contain_class('zabbix::database::mysql') }
it { is_expected.to contain_class('zabbix::database::mysql') }
# this doesn't make much sense because the class requires other classes
# it { should compile.with_all_deps }
it { should contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
context 'when zabbix_type is server and zabbix version is 3.2' do
let :params do
Expand All @@ -104,11 +105,11 @@
zabbix_version: '3.2'
}
end
it { should contain_class('zabbix::database::mysql') }
it { should compile.with_all_deps }
it { should contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { should contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { should contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
end

describe 'when zabbix_type is proxy and zabbix version is 3.2' do
Expand All @@ -122,10 +123,10 @@
zabbix_version: '3.2'
}
end
it { should contain_class('zabbix::database::mysql') }
it { is_expected.to contain_class('zabbix::database::mysql') }
# this doesn't make much sense because the class requires other classes
# it { should compile.with_all_deps }
it { should contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
end
end
Expand Down
Loading