Skip to content

Commit d8449e5

Browse files
author
Ashley Penney
committed
Merge pull request #114 from apenney/beaker
Convert the rspec-system tests over to beaker.
2 parents eb02ba2 + ff91686 commit d8449e5

21 files changed

+381
-201
lines changed

Gemfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ source 'https://rubygems.org'
33
group :development, :test do
44
gem 'rake', :require => false
55
gem 'puppetlabs_spec_helper', :require => false
6-
gem 'rspec-system-puppet', :require => false
76
gem 'puppet-lint', :require => false
87
gem 'serverspec', :require => false
9-
gem 'rspec-system-serverspec', :require => false
10-
gem 'vagrant-wrapper', :require => false
8+
gem 'beaker', :require => false
9+
gem 'beaker-rspec', :require => false
1110
end
1211

1312
if puppetversion = ENV['PUPPET_GEM_VERSION']

Rakefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
require 'puppetlabs_spec_helper/rake_tasks'
2-
require 'rspec-system/rake_task'

spec/acceptance/basic_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'basic tests' do
4+
it 'copied the module' do
5+
shell('ls /etc/puppet/modules/ntp/Modulefile', {:acceptable_exit_codes => 0})
6+
end
7+
end

spec/acceptance/class_spec.rb

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe "ntp class:" do
4+
it 'should run successfully' do
5+
pp = "class { 'ntp': }"
6+
7+
# Apply twice to ensure no errors the second time.
8+
apply_manifest(pp, :catch_failures => true) do |r|
9+
expect(r.stderr).to eq("")
10+
end
11+
apply_manifest(pp, :catch_failures => true) do |r|
12+
expect(r.stderr).to eq("")
13+
expect(r.exit_code).to be_zero
14+
end
15+
end
16+
17+
context 'service_ensure => stopped:' do
18+
it 'runs successfully' do
19+
pp = "class { 'ntp': service_ensure => stopped }"
20+
21+
apply_manifest(pp, :catch_failures => true) do |r|
22+
expect(r.stderr).to eq("")
23+
end
24+
end
25+
end
26+
27+
context 'service_ensure => running:' do
28+
it 'runs successfully' do
29+
pp = "class { 'ntp': service_ensure => running }"
30+
31+
apply_manifest(pp, :catch_failures => true) do |r|
32+
expect(r.stderr).to eq("")
33+
end
34+
end
35+
end
36+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HOSTS:
2+
centos-64-x64.local:
3+
roles:
4+
- master
5+
platform: el-6-i386
6+
box : centos-64-x64-vbox4210-nocm
7+
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
8+
hypervisor : vagrant

spec/acceptance/nodesets/default.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
centos-64-x64.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HOSTS:
2+
ubuntu-server-12042-x64.local:
3+
roles:
4+
- master
5+
platform: ubuntu-server-12.04-amd64
6+
box : ubuntu-server-12042-x64-vbox4210-nocm
7+
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
8+
hypervisor : vagrant

spec/acceptance/ntp_config_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper_acceptance'
2+
3+
case fact('osfamily')
4+
when 'FreeBSD'
5+
line = '0.freebsd.pool.ntp.org iburst maxpoll 9'
6+
when 'Debian'
7+
line = '0.debian.pool.ntp.org iburst'
8+
when 'RedHat'
9+
line = '0.centos.pool.ntp.org'
10+
when 'SuSE'
11+
line = '0.opensuse.pool.ntp.org'
12+
when 'Gentoo'
13+
line = '0.gentoo.pool.ntp.org'
14+
when 'Linux'
15+
case fact('operatingsystem')
16+
when 'ArchLinux'
17+
line = '0.pool.ntp.org'
18+
when 'Gentoo'
19+
line = '0.gentoo.pool.ntp.org'
20+
end
21+
end
22+
23+
describe 'ntp::config class' do
24+
it 'sets up ntp.conf' do
25+
apply_manifest(%{
26+
class { 'ntp': }
27+
}, :catch_failures => true)
28+
end
29+
30+
describe file('/etc/ntp.conf') do
31+
it { should be_file }
32+
it { should contain line }
33+
end
34+
end

spec/acceptance/ntp_install_spec.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper_acceptance'
2+
3+
case fact('osfamily')
4+
when 'FreeBSD'
5+
packagename = 'net/ntp'
6+
when 'Gentoo'
7+
packagename = 'net-misc/ntp'
8+
when 'Linux'
9+
case fact('operatingsystem')
10+
when 'ArchLinux'
11+
packagename = 'ntp'
12+
when 'Gentoo'
13+
packagename = 'net-misc/ntp'
14+
end
15+
else
16+
packagename = 'ntp'
17+
end
18+
19+
describe 'ntp::install class' do
20+
it 'installs the package' do
21+
apply_manifest(%{
22+
class { 'ntp': }
23+
}, :catch_failures => true)
24+
end
25+
26+
describe package(packagename) do
27+
it { should be_installed }
28+
end
29+
end
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe "ntp class:" do
4+
it 'applies successfully' do
5+
pp = "class { 'ntp': }"
6+
7+
apply_manifest(pp, :catch_failures => true) do |r|
8+
expect(r.stderr).to eq("")
9+
end
10+
end
11+
12+
describe 'autoconfig' do
13+
it 'raises a deprecation warning' do
14+
pp = "class { 'ntp': autoupdate => true }"
15+
16+
apply_manifest(pp, :catch_failures => true) do |r|
17+
expect(r.stdout).to match(/autoupdate parameter has been deprecated and replaced with package_ensure/)
18+
end
19+
end
20+
end
21+
22+
describe 'config' do
23+
it 'sets the ntp.conf location' do
24+
pp = "class { 'ntp': config => '/etc/antp.conf' }"
25+
apply_manifest(pp, :catch_failures => true)
26+
end
27+
28+
describe file('/etc/antp.conf') do
29+
it { should be_file }
30+
end
31+
end
32+
33+
describe 'config_template' do
34+
it 'sets up template' do
35+
shell('mkdir -p /etc/puppet/modules/test/templates')
36+
shell('echo "testcontent" >> /etc/puppet/modules/test/templates/ntp.conf')
37+
end
38+
39+
it 'sets the ntp.conf location' do
40+
pp = "class { 'ntp': config_template => 'test/ntp.conf' }"
41+
apply_manifest(pp, :catch_failures => true)
42+
end
43+
44+
describe file('/etc/ntp.conf') do
45+
it { should be_file }
46+
it { should contain 'testcontent' }
47+
end
48+
end
49+
50+
describe 'driftfile' do
51+
it 'sets the driftfile location' do
52+
pp = "class { 'ntp': driftfile => '/tmp/driftfile' }"
53+
apply_manifest(pp, :catch_failures => true)
54+
end
55+
56+
describe file('/etc/ntp.conf') do
57+
it { should be_file }
58+
it { should contain 'driftfile /tmp/driftfile' }
59+
end
60+
end
61+
62+
describe 'keys' do
63+
it 'enables the key parameters' do
64+
pp = <<-EOS
65+
class { 'ntp':
66+
keys_enable => true,
67+
keys_file => '/etc/ntp/keys',
68+
keys_controlkey => '/etc/ntp/controlkey',
69+
keys_requestkey => '/etc/ntp/requestkey',
70+
keys_trusted => [ '/etc/ntp/key1', '/etc/ntp/key2' ],
71+
}
72+
EOS
73+
apply_manifest(pp, :catch_failures => true)
74+
end
75+
76+
describe file('/etc/ntp.conf') do
77+
it { should be_file }
78+
it { should contain 'keys /etc/ntp/keys' }
79+
it { should contain 'controlkey /etc/ntp/controlkey' }
80+
it { should contain 'requestkey /etc/ntp/requestkey' }
81+
it { should contain 'trustedkey /etc/ntp/key1 /etc/ntp/key2' }
82+
end
83+
end
84+
85+
describe 'package' do
86+
it 'installs the right package' do
87+
pp = <<-EOS
88+
class { 'ntp':
89+
package_ensure => present,
90+
package_name => ['ntp'],
91+
}
92+
EOS
93+
apply_manifest(pp, :catch_failures => true)
94+
end
95+
96+
describe package('ntp') do
97+
it { should be_installed }
98+
end
99+
end
100+
101+
describe 'panic => false' do
102+
it 'enables the tinker panic setting' do
103+
pp = <<-EOS
104+
class { 'ntp':
105+
panic => false,
106+
}
107+
EOS
108+
apply_manifest(pp, :catch_failures => true)
109+
end
110+
111+
describe file('/etc/ntp.conf') do
112+
it { should contain 'tinker panic' }
113+
end
114+
end
115+
116+
describe 'panic => true' do
117+
it 'disables the tinker panic setting' do
118+
pp = <<-EOS
119+
class { 'ntp':
120+
panic => true,
121+
}
122+
EOS
123+
apply_manifest(pp, :catch_failures => true)
124+
end
125+
126+
describe file('/etc/ntp.conf') do
127+
it { should_not contain 'tinker panic 0' }
128+
end
129+
end
130+
131+
describe 'udlc' do
132+
it 'adds a udlc' do
133+
pp = "class { 'ntp': udlc => true }"
134+
apply_manifest(pp, :catch_failures => true)
135+
end
136+
137+
describe file('/etc/ntp.conf') do
138+
it { should be_file }
139+
it { should contain '127.127.1.0' }
140+
end
141+
end
142+
143+
end

spec/acceptance/ntp_service_spec.rb

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require 'spec_helper_acceptance'
2+
3+
case fact('osfamily')
4+
when 'RedHat', 'FreeBSD', 'Linux', 'Gentoo'
5+
servicename = 'ntpd'
6+
else
7+
servicename = 'ntp'
8+
end
9+
10+
describe 'ntp::service class' do
11+
it 'sets up the service' do
12+
apply_manifest(%{
13+
class { 'ntp': }
14+
}, :catch_failures => true)
15+
end
16+
17+
describe service(servicename) do
18+
it { should be_enabled }
19+
it { should be_running }
20+
end
21+
end
22+
23+
describe 'service parameters' do
24+
it 'starts the service' do
25+
pp = <<-EOS
26+
class { 'ntp':
27+
service_enable => true,
28+
service_ensure => running,
29+
service_manage => true,
30+
service_name => '#{servicename}'
31+
}
32+
EOS
33+
apply_manifest(pp, :catch_failures => true)
34+
end
35+
36+
describe service(servicename) do
37+
it { should be_running }
38+
it { should be_enabled }
39+
end
40+
end
41+
42+
describe 'service is unmanaged' do
43+
it 'shouldnt stop the service' do
44+
pp = <<-EOS
45+
class { 'ntp':
46+
service_enable => false,
47+
service_ensure => stopped,
48+
service_manage => false,
49+
service_name => '#{servicename}'
50+
}
51+
EOS
52+
apply_manifest(pp, :catch_failures => true)
53+
end
54+
55+
describe service(servicename) do
56+
it { should be_running }
57+
it { should be_enabled }
58+
end
59+
end

spec/system/preferred_servers_spec.rb renamed to spec/acceptance/preferred_servers_spec.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
require 'spec_helper_system'
1+
require 'spec_helper_acceptance'
22

33
describe 'preferred servers' do
4-
it 'applies cleanly' do
5-
puppet_apply(%{
4+
pp = <<-EOS
65
class { '::ntp':
76
servers => ['a', 'b', 'c', 'd'],
87
preferred_servers => ['c', 'd'],
98
}
10-
})
9+
EOS
10+
11+
it 'applies cleanly' do
12+
apply_manifest(pp, :catch_failures => true) do |r|
13+
expect(r.stderr).to eq("")
14+
end
1115
end
1216

1317
describe file('/etc/ntp.conf') do

spec/acceptance/restrict_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe "ntp class with restrict:" do
4+
context 'should run successfully' do
5+
pp = "class { 'ntp': restrict => ['test restrict']}"
6+
7+
it 'runs twice' do
8+
2.times do
9+
apply_manifest(pp, :catch_failures => true) do |r|
10+
expect(r.stderr).to be_empty
11+
end
12+
end
13+
end
14+
end
15+
16+
describe file('/etc/ntp.conf') do
17+
it { should contain('test restrict') }
18+
end
19+
20+
end

0 commit comments

Comments
 (0)