From 661c6731d78f4008ace836a65953be59643a299b Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 6 Jan 2014 17:39:48 -0500 Subject: [PATCH] Convert existing tests over to beakr-rspec. --- .nodeset.yml | 19 ------------ Gemfile | 6 ++-- .../apt_builddep_spec.rb | 6 ++-- spec/{system => acceptance}/apt_key_spec.rb | 14 ++++----- spec/{system => acceptance}/apt_ppa_spec.rb | 24 ++++++--------- .../{system => acceptance}/apt_source_spec.rb | 12 ++++---- spec/{system => acceptance}/class_spec.rb | 9 ++---- spec/acceptance/nodesets/debian-70rc1-x64.yml | 8 +++++ spec/acceptance/nodesets/default.yml | 8 +++++ .../nodesets/ubuntu-server-12042-x64.yml | 8 +++++ spec/spec_helper_acceptance.rb | 26 ++++++++++++++++ spec/spec_helper_system.rb | 30 ------------------- spec/system/basic_spec.rb | 10 ------- 13 files changed, 78 insertions(+), 102 deletions(-) delete mode 100644 .nodeset.yml rename spec/{system => acceptance}/apt_builddep_spec.rb (86%) rename spec/{system => acceptance}/apt_key_spec.rb (74%) rename spec/{system => acceptance}/apt_ppa_spec.rb (57%) rename spec/{system => acceptance}/apt_source_spec.rb (75%) rename spec/{system => acceptance}/class_spec.rb (61%) create mode 100644 spec/acceptance/nodesets/debian-70rc1-x64.yml create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-12042-x64.yml create mode 100644 spec/spec_helper_acceptance.rb delete mode 100644 spec/spec_helper_system.rb delete mode 100644 spec/system/basic_spec.rb diff --git a/.nodeset.yml b/.nodeset.yml deleted file mode 100644 index ad056fe..0000000 --- a/.nodeset.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -default_set: 'ubuntu-server-12042-x64' -sets: - 'debian-607-x64': - nodes: - "main.foo.vm": - prefab: 'debian-607-x64' - 'debian-70rc1-x64': - nodes: - "main.foo.vm": - prefab: 'debian-70rc1-x64' - 'ubuntu-server-10044-x64': - nodes: - "main.foo.vm": - prefab: 'ubuntu-server-10044-x64' - 'ubuntu-server-12042-x64': - nodes: - "main.foo.vm": - prefab: 'ubuntu-server-12042-x64' diff --git a/Gemfile b/Gemfile index 15bd29d..b89b579 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,9 @@ group :development, :test do gem 'rake', :require => false gem 'rspec-puppet', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'rspec-system', :require => false - gem 'rspec-system-puppet', :require => false - gem 'rspec-system-serverspec', :require => false + gem 'serverspec', :require => false + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/spec/system/apt_builddep_spec.rb b/spec/acceptance/apt_builddep_spec.rb similarity index 86% rename from spec/system/apt_builddep_spec.rb rename to spec/acceptance/apt_builddep_spec.rb index fa16ab4..b61fca2 100644 --- a/spec/system/apt_builddep_spec.rb +++ b/spec/acceptance/apt_builddep_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe 'apt::builddep' do @@ -16,9 +16,7 @@ describe 'apt::builddep' do apt::builddep { 'glusterfs-server': } EOS - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - end + apply_manifest(pp, :catch_failures => true) end describe 'should install g++ as a dependency' do diff --git a/spec/system/apt_key_spec.rb b/spec/acceptance/apt_key_spec.rb similarity index 74% rename from spec/system/apt_key_spec.rb rename to spec/acceptance/apt_key_spec.rb index 4842cb5..5f69e25 100644 --- a/spec/system/apt_key_spec.rb +++ b/spec/acceptance/apt_key_spec.rb @@ -1,11 +1,11 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe 'apt::key' do context 'reset' do it 'clean up keys' do - shell('apt-key del 4BD6EC30') - shell('apt-key del D50582E6') + shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) + shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2]) end end @@ -24,20 +24,18 @@ describe 'apt::key' do } EOS - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - end + apply_manifest(pp, :catch_failures => true) end describe 'keys should exist' do it 'finds puppetlabs key' do shell('apt-key list | grep 4BD6EC30') do |r| - r.exit_code.should be_zero + expect(r.exit_code).to be_zero end end it 'finds jenkins key' do shell('apt-key list | grep D50582E6') do |r| - r.exit_code.should be_zero + expect(r.exit_code).to be_zero end end end diff --git a/spec/system/apt_ppa_spec.rb b/spec/acceptance/apt_ppa_spec.rb similarity index 57% rename from spec/system/apt_ppa_spec.rb rename to spec/acceptance/apt_ppa_spec.rb index 2e2baf5..5bee3c6 100644 --- a/spec/system/apt_ppa_spec.rb +++ b/spec/acceptance/apt_ppa_spec.rb @@ -1,11 +1,11 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe 'apt::ppa' do context 'reset' do it 'removes ppa' do - shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*') - shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') + shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2]) + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2]) end end @@ -13,19 +13,15 @@ describe 'apt::ppa' do it 'should work with no errors' do pp = <<-EOS include '::apt' - apt::ppa { 'ppa:drizzle-developers/ppa': } + apt::ppa { 'ppa:canonical-kernel-team/ppa': } EOS - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - end + apply_manifest(pp, :catch_failures => true) end describe 'contains the source file' do - it 'contains a drizzle ppa source' do - shell('ls /etc/apt/sources.list.d/drizzle-developers-ppa-*.list') do |r| - r.exit_code.should be_zero - end + it 'contains a kernel ppa source' do + shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0]) end end end @@ -43,15 +39,13 @@ describe 'apt::ppa' do apt::ppa { 'ppa:raravena80/collectd5': } EOS - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - end + apply_manifest(pp, :catch_failures => true) end end context 'reset' do it 'removes added ppas' do - shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*') + shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*') shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') end end diff --git a/spec/system/apt_source_spec.rb b/spec/acceptance/apt_source_spec.rb similarity index 75% rename from spec/system/apt_source_spec.rb rename to spec/acceptance/apt_source_spec.rb index 6a445e1..044af57 100644 --- a/spec/system/apt_source_spec.rb +++ b/spec/acceptance/apt_source_spec.rb @@ -1,11 +1,11 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe 'apt::source' do context 'reset' do it 'clean up puppetlabs repo' do - shell('apt-key del 4BD6EC30') - shell('rm /etc/apt/sources.list.d/puppetlabs.list') + shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) + shell('rm /etc/apt/sources.list.d/puppetlabs.list', :acceptable_exit_codes => [0,1,2]) end end @@ -21,15 +21,13 @@ describe 'apt::source' do } EOS - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - end + apply_manifest(pp, :catch_failures => true) end describe 'key should exist' do it 'finds puppetlabs key' do shell('apt-key list | grep 4BD6EC30') do |r| - r.exit_code.should be_zero + expect(r.exit_code).to be_zero end end end diff --git a/spec/system/class_spec.rb b/spec/acceptance/class_spec.rb similarity index 61% rename from spec/system/class_spec.rb rename to spec/acceptance/class_spec.rb index 7bb6b8d..f228e4c 100644 --- a/spec/system/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe 'apt class' do @@ -10,11 +10,8 @@ describe 'apt class' do 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 - end + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) end end end diff --git a/spec/acceptance/nodesets/debian-70rc1-x64.yml b/spec/acceptance/nodesets/debian-70rc1-x64.yml new file mode 100644 index 0000000..a1b59c0 --- /dev/null +++ b/spec/acceptance/nodesets/debian-70rc1-x64.yml @@ -0,0 +1,8 @@ +HOSTS: + debian-70rc1-x64: + roles: + - master + platform: debian-70rc1-x64 + box : debian-70rc1-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box + hypervisor : vagrant diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..2b8fe4a --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,8 @@ +HOSTS: + ubuntu-server-12042-x64: + 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 diff --git a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml new file mode 100644 index 0000000..2b8fe4a --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml @@ -0,0 +1,8 @@ +HOSTS: + ubuntu-server-12042-x64: + 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 diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..0073e4d --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,26 @@ +require 'beaker-rspec' + +hosts.each do |host| + # Install Puppet + install_package host, 'rubygems' + on host, 'gem install puppet --no-ri --no-rdoc' + on host, "mkdir -p #{host['distmoduledir']}" +end + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + puppet_module_install(:source => proj_root, :module_name => 'apt') + hosts.each do |host| + shell('/bin/touch /etc/puppet/hiera.yaml') + shell('puppet module install puppetlabs-stdlib', { :acceptable_exit_codes => [0,1] }) + end + end +end diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb deleted file mode 100644 index 490a601..0000000 --- a/spec/spec_helper_system.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rspec-system/spec_helper' -require 'rspec-system-puppet/helpers' -require 'rspec-system-serverspec/helpers' - -include RSpecSystemPuppet::Helpers - -include Serverspec::Helper::RSpecSystem -include Serverspec::Helper::DetectOS - -RSpec.configure do |c| - # Project root - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - - # Enable colour - c.tty = true - - c.include RSpecSystemPuppet::Helpers - - # This is where we 'setup' the nodes before running our tests - c.before :suite do - # May as well update here as this can only run on apt-get machines. - shell('apt-get update') - # Install puppet - puppet_install - - # Install modules and dependencies - puppet_module_install(:source => proj_root, :module_name => 'apt') - shell('puppet module install puppetlabs-stdlib') - end -end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb deleted file mode 100644 index 3008356..0000000 --- a/spec/system/basic_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 -end -- 2.45.2