summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2013-07-09 16:06:03 -0400
committerAshley Penney <ashley.penney@puppetlabs.com>2013-07-09 16:06:03 -0400
commitb1bedbe26227680d47250e1f4c542384baa43982 (patch)
treed1602a5244a7e15676ae0e01573851cd559ebe0f
parent19b140786a6483a02b96d60605dc257d3625d3b7 (diff)
Improve the rspec-system tests, making sure we test for the package
being installed and the config file at least makes basic sense.
-rw-r--r--spec/system/basic_spec.rb28
-rw-r--r--spec/system/class_spec.rb39
-rw-r--r--spec/system/ntp_config_spec.rb35
-rw-r--r--spec/system/ntp_install_spec.rb22
4 files changed, 103 insertions, 21 deletions
diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb
index 87fedd2..7b717a0 100644
--- a/spec/system/basic_spec.rb
+++ b/spec/system/basic_spec.rb
@@ -1,25 +1,13 @@
require 'spec_helper_system'
-describe 'basic tests:' do
- # Using puppet_apply as a subject
- context puppet_apply 'notice("foo")' do
- its(:stdout) { should =~ /foo/ }
- its(:stderr) { should be_empty }
- its(:exit_code) { should be_zero }
- end
-
- # Using puppet_apply as a helper
- it 'my class should work with no errors' do
- pp = <<-EOS
- class { 'ntp': }
- EOS
-
- # Run it twice and test for idempotency
- puppet_apply(pp) do |r|
- r.exit_code.should_not == 1
- r.refresh
- r.exit_code.should be_zero
+# Here we put the more basic fundamental tests, ultra obvious stuff.
+describe "basic tests:" do
+ context 'make sure we have copied the module across' do
+ # No point diagnosing any more if the module wasn't copied properly
+ context shell 'ls /etc/puppet/modules/ntp' do
+ its(:stdout) { should =~ /Modulefile/ }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
end
end
end
-
diff --git a/spec/system/class_spec.rb b/spec/system/class_spec.rb
new file mode 100644
index 0000000..49dfc64
--- /dev/null
+++ b/spec/system/class_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper_system'
+
+describe "ntp class:" do
+ context 'should run successfully' do
+ pp = "class { 'ntp': }"
+
+ context puppet_apply(pp) do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+ end
+
+ context 'service_ensure => stopped:' do
+ pp = "class { 'ntp': service_ensure => stopped }"
+
+ context puppet_apply(pp) do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+ end
+
+ context 'service_ensure => running:' do
+ pp = "class { 'ntp': service_ensure => running }"
+
+ context puppet_apply(pp) do |r|
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+ end
+end
diff --git a/spec/system/ntp_config_spec.rb b/spec/system/ntp_config_spec.rb
new file mode 100644
index 0000000..263bc9d
--- /dev/null
+++ b/spec/system/ntp_config_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper_system'
+
+describe 'ntp::config class' do
+ let(:os) {
+ node.facts['osfamily']
+ }
+
+ puppet_apply(%{
+ class { 'ntp': }
+ })
+
+ case node.facts['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 'Linux'
+ case node.facts['operatingsystem']
+ when 'ArchLinux'
+ line = '0.pool.ntp.org'
+ when 'Gentoo'
+ line = '0.gentoo.pool.ntp.org'
+ end
+ end
+
+ describe file('/etc/ntp.conf') do
+ it { should be_file }
+ it { should contain line }
+ end
+
+end
diff --git a/spec/system/ntp_install_spec.rb b/spec/system/ntp_install_spec.rb
index 434cf58..39759c5 100644
--- a/spec/system/ntp_install_spec.rb
+++ b/spec/system/ntp_install_spec.rb
@@ -1,11 +1,31 @@
require 'spec_helper_system'
+
describe 'ntp::install class' do
let(:os) {
node.facts['osfamily']
}
- describe package('ntp') do
+ case node.facts['osfamily']
+ when 'FreeBSD'
+ packagename = 'net/ntp'
+ when 'Linux'
+ case node.facts['operatingsystem']
+ when 'ArchLinux'
+ packagename = 'ntp'
+ when 'Gentoo'
+ packagename = 'net-misc/ntp'
+ end
+ else
+ packagename = 'ntp'
+ end
+
+ puppet_apply(%{
+ class { 'ntp': }
+ })
+
+ describe package(packagename) do
it { should be_installed }
end
+
end