Skip to content

Commit

Permalink
Add rspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arioch committed Jul 25, 2013
1 parent db72b6c commit 1bfcfdf
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 63 deletions.
8 changes: 8 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fixtures:
repositories:
concat: 'git://github.com/puppetlabs/puppetlabs-concat.git'
stdlib: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'

symlinks:
keepalived: "#{source_dir}"

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.swp
.DS_Store
Gemfile.lock
pkg
spec/fixtures
18 changes: 12 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
source 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.1.0']
puppetversion = ENV.key?('PUPPET_VERSION') ? "~> #{ENV['PUPPET_VERSION']}" : ['>= 3.2.1']
gem 'puppet', puppetversion

facterversion = ENV.key?('FACTER_VERSION') ? "= #{ENV['FACTER_VERSION']}" : ['>= 1.6.17']
if puppetversion =~ /^3/
## rspec-hiera-puppet is puppet 3 only
gem 'rspec-hiera-puppet', '>=1.0.0'
end

facterversion = ENV.key?('FACTER_VERSION') ? "~> #{ENV['FACTER_VERSION']}" : ['>= 1.7.1']

gem 'facter', facterversion

gem 'rake'
gem 'rspec'
gem 'puppet-lint', '>=0.3.2'
gem 'rspec-puppet', '>=0.1.5'
gem 'librarian-puppet', '>=0.9.7'
gem 'puppetlabs_spec_helper', '>=0.3.0'
gem 'rspec-hiera-puppet', '>=1.0.0'
gem 'rspec-puppet', '>=0.1.6'
gem 'puppetlabs_spec_helper', '>=0.4.1'

57 changes: 0 additions & 57 deletions Gemfile.lock

This file was deleted.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,19 @@ b. Master node is unavailable
}
}

## Unit testing

Plain RSpec:

$ rake spec

Using bundle:

$ bundle exec rake spec

Test against a specific Puppet or Facter version:

$ PUPPET_VERSION=3.2.1 bundle update && bundle exec rake spec
$ PUPPET_VERSION=2.7.19 bundle update && bundle exec rake spec
$ FACTER_VERSION=1.6.8 bundle update && bundle exec rake spec

17 changes: 17 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rake'
require 'rspec/core/rake_task'
require 'puppetlabs_spec_helper/rake_tasks'

RSpec::Core::RakeTask.new(:spec_verbose) do |t|
t.pattern = 'spec/*/*_spec.rb'
t.rspec_opts = File.read('spec/spec.opts').chomp || ""
end

task :test do
Rake::Task[:spec_prep].invoke
Rake::Task[:spec_verbose].invoke
Rake::Task[:spec_clean].invoke
end


task :default => [:spec, :lint]
103 changes: 103 additions & 0 deletions spec/classes/keepalived_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
require 'spec_helper'

describe 'keepalived', :type => :class do
let (:facts) { debian_facts }

describe 'without parameters' do
it { should create_class('keepalived') }
it { should include_class('keepalived::install') }
it { should include_class('keepalived::config') }
it { should include_class('keepalived::service') }

it { should contain_package('keepalived').with_ensure('present') }

it { should contain_file('/etc/keepalived/keepalived.conf').with(
'ensure' => 'present',
'group' => 'root',
'mode' => '0644',
'owner' => 'root'
)
}

it { should contain_service('keepalived').with(
'ensure' => 'running',
'enable' => 'true',
'hasrestart' => 'false',
'hasstatus' => 'false'
)
}
end

describe 'with parameter: config_dir' do
let (:params) { { :config_dir => '_VALUE_' } }

it { should contain_file('_VALUE_').with_ensure('directory') }
end

describe 'with parameter: config_dir_mode' do
let (:params) { { :config_dir_mode => '_VALUE_' } }

it { should contain_file('/etc/keepalived').with_mode('_VALUE_') }
end

describe 'with parameter: config_file_mode' do
let (:params) { { :config_file_mode => '_VALUE_' } }

it { should contain_file('/etc/keepalived/keepalived.conf').with_mode('_VALUE_') }
end

describe 'with parameter: config_group' do
let (:params) { { :config_group => '_VALUE_' } }

it { should contain_file('/etc/keepalived').with_group('_VALUE_') }
end

describe 'with parameter: config_owner' do
let (:params) { { :config_owner => '_VALUE_' } }

it { should contain_file('/etc/keepalived').with_owner('_VALUE_') }
end

describe 'with parameter: pkg_ensure' do
let (:params) { { :pkg_ensure => '_VALUE_' } }

it { should contain_package('keepalived').with_ensure('_VALUE_') }
end

describe 'with parameter: pkg_list' do
let (:params) { { :pkg_list => '_VALUE_' } }

it { should contain_package('_VALUE_') }
end

describe 'with parameter: service_enable' do
let (:params) { { :service_enable => true } }

it { should contain_service('keepalived').with_enable(true) }
end

describe 'with parameter: service_ensure' do
let (:params) { { :service_ensure => '_VALUE_' } }

it { should contain_service('keepalived').with_ensure('_VALUE_') }
end

describe 'with parameter: service_hasrestart' do
let (:params) { { :service_hasrestart => true } }

it { should contain_service('keepalived').with_hasrestart(true) }
end

describe 'with parameter: service_hasstatus' do
let (:params) { { :service_hasstatus => true } }

it { should contain_service('keepalived').with_hasstatus(true) }
end

describe 'with parameter: service_name' do
let (:params) { { :service_name => '_VALUE_' } }

it { should contain_service('_VALUE_').with_name('_VALUE_') }
end
end

1 change: 1 addition & 0 deletions spec/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--format documentation --color --backtrace
23 changes: 23 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rubygems'
require 'rspec-puppet'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
end

def centos_facts
{
:operatingsystem => 'CentOS',
:osfamily => 'RedHat',
}
end

def debian_facts
{
:operatingsystem => 'Debian',
:osfamily => 'Debian',
}
end

0 comments on commit 1bfcfdf

Please sign in to comment.