Skip to content

Commit

Permalink
Convert the rspec-system tests over to beaker.
Browse files Browse the repository at this point in the history
This converts over the spec tests to be beaker tests.  It adds tests for
all parameters that were untested previously.
  • Loading branch information
Ashley Penney committed Dec 10, 2013
1 parent eb02ba2 commit ff91686
Show file tree
Hide file tree
Showing 21 changed files with 381 additions and 201 deletions.
5 changes: 2 additions & 3 deletions Gemfile
Expand Up @@ -3,11 +3,10 @@ source 'https://rubygems.org'
group :development, :test do
gem 'rake', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'rspec-system-puppet', :require => false
gem 'puppet-lint', :require => false
gem 'serverspec', :require => false
gem 'rspec-system-serverspec', :require => false
gem 'vagrant-wrapper', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
Expand Down
1 change: 0 additions & 1 deletion Rakefile
@@ -1,2 +1 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'rspec-system/rake_task'
7 changes: 7 additions & 0 deletions spec/acceptance/basic_spec.rb
@@ -0,0 +1,7 @@
require 'spec_helper_acceptance'

describe 'basic tests' do
it 'copied the module' do
shell('ls /etc/puppet/modules/ntp/Modulefile', {:acceptable_exit_codes => 0})
end
end
36 changes: 36 additions & 0 deletions spec/acceptance/class_spec.rb
@@ -0,0 +1,36 @@
require 'spec_helper_acceptance'

describe "ntp class:" do
it 'should run successfully' do
pp = "class { 'ntp': }"

# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
expect(r.exit_code).to be_zero
end
end

context 'service_ensure => stopped:' do
it 'runs successfully' do
pp = "class { 'ntp': service_ensure => stopped }"

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
end
end

context 'service_ensure => running:' do
it 'runs successfully' do
pp = "class { 'ntp': service_ensure => running }"

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
end
end
end
8 changes: 8 additions & 0 deletions spec/acceptance/nodesets/centos-64-x64.yml
@@ -0,0 +1,8 @@
HOSTS:
centos-64-x64.local:
roles:
- master
platform: el-6-i386
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
1 change: 1 addition & 0 deletions spec/acceptance/nodesets/default.yml
8 changes: 8 additions & 0 deletions spec/acceptance/nodesets/ubuntu-server-12042-x64.yml
@@ -0,0 +1,8 @@
HOSTS:
ubuntu-server-12042-x64.local:
roles:
- master
platform: ubuntu-server-12.04-amd64
box : ubuntu-server-12042-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor : vagrant
34 changes: 34 additions & 0 deletions spec/acceptance/ntp_config_spec.rb
@@ -0,0 +1,34 @@
require 'spec_helper_acceptance'

case fact('osfamily')
when 'FreeBSD'
line = '0.freebsd.pool.ntp.org iburst maxpoll 9'
when 'Debian'
line = '0.debian.pool.ntp.org iburst'
when 'RedHat'
line = '0.centos.pool.ntp.org'
when 'SuSE'
line = '0.opensuse.pool.ntp.org'
when 'Gentoo'
line = '0.gentoo.pool.ntp.org'
when 'Linux'
case fact('operatingsystem')
when 'ArchLinux'
line = '0.pool.ntp.org'
when 'Gentoo'
line = '0.gentoo.pool.ntp.org'
end
end

describe 'ntp::config class' do
it 'sets up ntp.conf' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain line }
end
end
29 changes: 29 additions & 0 deletions spec/acceptance/ntp_install_spec.rb
@@ -0,0 +1,29 @@
require 'spec_helper_acceptance'

case fact('osfamily')
when 'FreeBSD'
packagename = 'net/ntp'
when 'Gentoo'
packagename = 'net-misc/ntp'
when 'Linux'
case fact('operatingsystem')
when 'ArchLinux'
packagename = 'ntp'
when 'Gentoo'
packagename = 'net-misc/ntp'
end
else
packagename = 'ntp'
end

describe 'ntp::install class' do
it 'installs the package' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end

describe package(packagename) do
it { should be_installed }
end
end
143 changes: 143 additions & 0 deletions spec/acceptance/ntp_parameters_spec.rb
@@ -0,0 +1,143 @@
require 'spec_helper_acceptance'

describe "ntp class:" do
it 'applies successfully' do
pp = "class { 'ntp': }"

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
end

describe 'autoconfig' do
it 'raises a deprecation warning' do
pp = "class { 'ntp': autoupdate => true }"

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/autoupdate parameter has been deprecated and replaced with package_ensure/)
end
end
end

describe 'config' do
it 'sets the ntp.conf location' do
pp = "class { 'ntp': config => '/etc/antp.conf' }"
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/antp.conf') do
it { should be_file }
end
end

describe 'config_template' do
it 'sets up template' do
shell('mkdir -p /etc/puppet/modules/test/templates')
shell('echo "testcontent" >> /etc/puppet/modules/test/templates/ntp.conf')
end

it 'sets the ntp.conf location' do
pp = "class { 'ntp': config_template => 'test/ntp.conf' }"
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'testcontent' }
end
end

describe 'driftfile' do
it 'sets the driftfile location' do
pp = "class { 'ntp': driftfile => '/tmp/driftfile' }"
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'driftfile /tmp/driftfile' }
end
end

describe 'keys' do
it 'enables the key parameters' do
pp = <<-EOS
class { 'ntp':
keys_enable => true,
keys_file => '/etc/ntp/keys',
keys_controlkey => '/etc/ntp/controlkey',
keys_requestkey => '/etc/ntp/requestkey',
keys_trusted => [ '/etc/ntp/key1', '/etc/ntp/key2' ],
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'keys /etc/ntp/keys' }
it { should contain 'controlkey /etc/ntp/controlkey' }
it { should contain 'requestkey /etc/ntp/requestkey' }
it { should contain 'trustedkey /etc/ntp/key1 /etc/ntp/key2' }
end
end

describe 'package' do
it 'installs the right package' do
pp = <<-EOS
class { 'ntp':
package_ensure => present,
package_name => ['ntp'],
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe package('ntp') do
it { should be_installed }
end
end

describe 'panic => false' do
it 'enables the tinker panic setting' do
pp = <<-EOS
class { 'ntp':
panic => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should contain 'tinker panic' }
end
end

describe 'panic => true' do
it 'disables the tinker panic setting' do
pp = <<-EOS
class { 'ntp':
panic => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should_not contain 'tinker panic 0' }
end
end

describe 'udlc' do
it 'adds a udlc' do
pp = "class { 'ntp': udlc => true }"
apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain '127.127.1.0' }
end
end

end
59 changes: 59 additions & 0 deletions spec/acceptance/ntp_service_spec.rb
@@ -0,0 +1,59 @@
require 'spec_helper_acceptance'

case fact('osfamily')
when 'RedHat', 'FreeBSD', 'Linux', 'Gentoo'
servicename = 'ntpd'
else
servicename = 'ntp'
end

describe 'ntp::service class' do
it 'sets up the service' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end

describe service(servicename) do
it { should be_enabled }
it { should be_running }
end
end

describe 'service parameters' do
it 'starts the service' do
pp = <<-EOS
class { 'ntp':
service_enable => true,
service_ensure => running,
service_manage => true,
service_name => '#{servicename}'
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe service(servicename) do
it { should be_running }
it { should be_enabled }
end
end

describe 'service is unmanaged' do
it 'shouldnt stop the service' do
pp = <<-EOS
class { 'ntp':
service_enable => false,
service_ensure => stopped,
service_manage => false,
service_name => '#{servicename}'
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe service(servicename) do
it { should be_running }
it { should be_enabled }
end
end
@@ -1,13 +1,17 @@
require 'spec_helper_system'
require 'spec_helper_acceptance'

describe 'preferred servers' do
it 'applies cleanly' do
puppet_apply(%{
pp = <<-EOS
class { '::ntp':
servers => ['a', 'b', 'c', 'd'],
preferred_servers => ['c', 'd'],
}
})
EOS

it 'applies cleanly' do
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
end

describe file('/etc/ntp.conf') do
Expand Down
20 changes: 20 additions & 0 deletions spec/acceptance/restrict_spec.rb
@@ -0,0 +1,20 @@
require 'spec_helper_acceptance'

describe "ntp class with restrict:" do
context 'should run successfully' do
pp = "class { 'ntp': restrict => ['test restrict']}"

it 'runs twice' do
2.times do
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to be_empty
end
end
end
end

describe file('/etc/ntp.conf') do
it { should contain('test restrict') }
end

end

0 comments on commit ff91686

Please sign in to comment.