Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit 67532f8

Browse files
committed
Merge pull request #123 from danieldreier/refactor_tests
Refactor acceptance tests
2 parents 51cf627 + 2cec963 commit 67532f8

File tree

9 files changed

+200
-177
lines changed

9 files changed

+200
-177
lines changed

CONTRIBUTING.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
11
Testing
22
=======
33

4-
Tests on the puppet-puppet module can be run via `rake`.
4+
Puppet-puppet is tested via beaker and rspec-puppet. Rspec-puppet tests are run
5+
automatically for pull requests via travis-ci, or can be triggered manually
6+
by running `rake spec` after doing a `bundle install`.
57

6-
#### Beaker acceptance tests
7-
```
8-
BEAKER_destroy=no BEAKER_provision=onpass rake acceptance
8+
Beaker tests are run slightly differently for puppet-puppet than for other
9+
beaker-tested projects because the test suite should be run independently for
10+
each test case to prevent contamination between environments. For example,
11+
running the apache-passenger based puppet master test case will cause obvious
12+
conflicts if the nginx-unicorn puppet master is subsequently built on the same
13+
virtual machine. Rspec tags are used to accomplish this in the test cases.
14+
15+
Running beaker tests for unicorn puppetmaster on the default nodeset (debian 7):
16+
```bash
17+
rspec . --tag servertype:unicorn --pattern "spec/acceptance/**/*_spec.rb"
918
```
1019

11-
Run beaker acceptance tests on debian 7:
20+
Same as above, but only only destroying the VM if the build is successful, to
21+
help troubleshooting:
1222
```
13-
BEAKER_set=debian-73-x64 BEAKER_destroy=onpass BEAKER_provision=no rake acceptance
23+
BEAKER_destroy=onpass BEAKER_provision=yes rspec . --tag servertype:unicorn --pattern "spec/acceptance/**/*_spec.rb"
1424
```
15-
See spec/acceptance/nodesets for a list of possible node names; use the filename without .yml.
25+
26+
Same as above, but on a different nodeset (see `spec/acceptance/nodesets` for
27+
options):
28+
```bash
29+
BEAKER_set=sles-11sp1-x64 BEAKER_destroy=onpass BEAKER_provision=yes rspec . --tag servertype:unicorn --pattern "spec/acceptance/**/*_spec.rb"
30+
```
31+
32+
The presence of an OS/distro in the nodeset list does not imply support. The
33+
SLES example above is expected to fail most test cases but is included to lower
34+
the bar for future contributors who want to add support for additional distros.
35+
36+
The rake command includes acceptance testing tasks, but these should not be
37+
used because they will run all of the acceptance tests on the same VM, which
38+
is expected to fail.
1639

1740
If a beaker test fails, you can SSH into the environment if you use BEAKER_PROVISION=onpass.
1841
The path of the vagrantfile will be `.vagrant/beaker_vagrant_files/debian-73-x64.yml`
1942
if you followed the above instructions, and slightly different if you used a
2043
different nodeset. `cd` to that directory and `vagrant ssh` to access the VM.
2144
The tests that ran are in /tmp with randomly generated filenames.
22-
```
2345

2446
#### rspec-puppet tests
2547
(note that these are run automatically by travis CI on pull requests)

spec/acceptance/agent_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe 'agent', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
44
context 'with default parameters' do
5-
it 'should run with no errors' do
5+
it 'should run with no errors', :agent do
66
pp = <<-EOS
77
class { 'puppet::agent': }
88
EOS

spec/acceptance/nodesets/default.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
HOSTS:
2-
ubuntu-server-12042-x64:
2+
debian-73-x64:
33
roles:
44
- master
5-
platform: ubuntu-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
5+
platform: debian-7-amd64
6+
box : debian-73-x64-virtualbox-nocm
7+
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
88
hypervisor : vagrant
99
CONFIG:
1010
log_level: debug
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'passenger server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
context 'running on passenger', :servertype => 'passenger', :webserver => 'apache' do
5+
it 'should run with no errors' do
6+
pp = <<-EOS
7+
class { 'puppet::server':
8+
servertype => 'passenger',
9+
ca => true,
10+
servername => $::hostname,
11+
}
12+
EOS
13+
14+
# Run it twice and test for idempotency
15+
apply_manifest(pp, :catch_failures => true)
16+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
17+
end
18+
it_behaves_like 'basic working puppetmaster'
19+
20+
# sanity checks to ensure the passenger setup doesn't bring in other services
21+
describe service('nginx') do
22+
it { should_not be_enabled }
23+
it { should_not be_running }
24+
end
25+
describe service('puppetmaster') do
26+
it { should_not be_enabled }
27+
it { should_not be_running }
28+
end
29+
describe service('puppetserver') do
30+
it { should_not be_enabled }
31+
it { should_not be_running }
32+
end
33+
34+
end
35+
end

spec/acceptance/server_spec.rb

Lines changed: 0 additions & 164 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'thin server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
5+
context 'running on thin', :servertype => 'thin', :webserver => 'nginx' do
6+
it 'should run with no errors' do
7+
pp = <<-EOS
8+
class { "puppet::server":
9+
servertype => 'thin',
10+
ca => true,
11+
}
12+
EOS
13+
14+
# Run it twice and test for idempotency
15+
apply_manifest(pp, :catch_failures => true)
16+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
17+
end
18+
19+
describe package('thin') do
20+
it { should be_installed.by('gem') }
21+
end
22+
23+
describe service('thin-puppetmaster') do
24+
it { should be_enabled }
25+
it { should be_running }
26+
end
27+
28+
it_behaves_like "basic working puppetmaster"
29+
it_behaves_like "nginx-based webserver"
30+
31+
end
32+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
context 'running on unicorn', :servertype => 'unicorn', :webserver => 'nginx' do
5+
it 'should run with no errors' do
6+
pp = <<-EOS
7+
class { 'puppet::server':
8+
servertype => 'unicorn',
9+
ca => true,
10+
}
11+
EOS
12+
13+
# Run it twice and test for idempotency
14+
apply_manifest(pp, :catch_failures => true)
15+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
16+
end
17+
18+
it_behaves_like "basic working puppetmaster"
19+
it_behaves_like "nginx-based webserver"
20+
21+
end
22+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
context 'running on webrick/standalone', :server => 'webrick', :webserver => 'builtin' do
5+
it 'should run with no errors' do
6+
pp = <<-EOS
7+
class { 'puppet::server':
8+
servertype => 'standalone',
9+
ca => true,
10+
}
11+
EOS
12+
13+
# Run it twice and test for idempotency
14+
apply_manifest(pp, :catch_failures => true)
15+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
16+
end
17+
18+
describe service('puppetmaster') do
19+
it { should be_enabled }
20+
it { should be_running }
21+
end
22+
23+
# sanity checks to ensure the webrick setup doesn't bring in other services
24+
describe service('nginx') do
25+
it { should_not be_enabled }
26+
it { should_not be_running }
27+
end
28+
describe service('apache2') do
29+
it { should_not be_enabled }
30+
it { should_not be_running }
31+
end
32+
describe service('httpd') do
33+
it { should_not be_enabled }
34+
it { should_not be_running }
35+
end
36+
describe service('puppetserver') do
37+
it { should_not be_enabled }
38+
it { should_not be_running }
39+
end
40+
41+
it_behaves_like 'basic working puppetmaster'
42+
43+
end
44+
end

0 commit comments

Comments
 (0)