From b1bedbe26227680d47250e1f4c542384baa43982 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 16:06:03 -0400 Subject: Improve the rspec-system tests, making sure we test for the package being installed and the config file at least makes basic sense. --- spec/system/basic_spec.rb | 28 ++++++++-------------------- spec/system/class_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ spec/system/ntp_config_spec.rb | 35 +++++++++++++++++++++++++++++++++++ spec/system/ntp_install_spec.rb | 22 +++++++++++++++++++++- 4 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 spec/system/class_spec.rb create mode 100644 spec/system/ntp_config_spec.rb (limited to 'spec') 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 -- cgit v1.2.3