Skip to content

Commit

Permalink
initial pass at rspec-puppet tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Merrill committed Jan 12, 2015
1 parent b2351ea commit 7927438
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fixtures:
symlinks:
gluster: "#{source_dir}"
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pkg/
spec/fixtures
.rspec_system
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'puppetlabs_spec_helper/rake_tasks'
14 changes: 14 additions & 0 deletions spec/classes/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

describe 'gluster::client', :type => :class do
let :facts do
{
:osfamily => 'RedHat',
:architecture => 'x86_64',
}
end
let :params do { :version => 'LATEST', } end
it 'should include gluster::install' do
should create_class('gluster::install')
end
end
73 changes: 73 additions & 0 deletions spec/classes/install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'spec_helper'

describe 'gluster::install', :type => :class do
# describe 'installing on an unsupported OS' do
# let :facts do { :osfamily => 'Amiga' } end
# expect { subject }.to raise_error(Puppet::Error, //)
# end
describe 'installing on an unsupported architecture' do
let :facts do { :architecture => 'zLinux' } end
it 'should not install' do
expect { subject }.to raise_error(Puppet::Error, /not yet supported/)
end
end
describe 'installing on Red Hat Enterprise Linux' do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => '6',
:architecture => 'x86_64',
}
end
context 'when repo is true' do
let :params do
{ :server => true }
end
it 'should create gluster::repo' do
should create_class('gluster::repo')
end
end
context 'when repo is false' do
let :params do
{ :repo => false }
end
it 'should not create gluster::repo' do
should_not create_class('gluster::repo')
end
end
context 'when client is true' do
let :params do
{ :client => true }
end
it 'should install glusterfs-fuse package' do
should create_package('glusterfs-fuse')
end
end
context 'when client is false' do
let :params do
{ :client => false }
end
it 'should not install glusterfs-fuse package' do
should_not create_package('glusterfs-fuse')
end
end
context 'when server is true' do
let :params do
{ :server => true }
end
it 'should install glusterfs-server' do
should create_package('glusterfs-server')
end
end
context 'when server is false' do
let :params do
{ :server => false }
end
it 'should not install glusterfs-server' do
should_not create_package('glusterfs-server')
end
end

end
end
54 changes: 54 additions & 0 deletions spec/classes/repo_yum_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

describe 'gluster::repo::yum', :type => :class do
describe 'version not specified' do
it 'should not install' do
expect { subject }.to raise_error(Puppet::Error, /Version not specified/)
end
end
describe 'bogus version' do
let :params do { :version => 'foobar', } end
it 'should not install' do
expect { subject }.to raise_error(Puppet::Error, /doesn't make sense!/)
end
end
describe 'unsupported architecture' do
let :facts do { :architecture => 'zLinux', } end
let :params do { :version => 'LATEST', } end
it 'should not install' do
expect { subject }.to raise_error(Puppet::Error, /not yet supported/)
end
end
describe 'latest version on x86_64' do
let :facts do { :architecture => 'x86_64', } end
let :params do
{
:version => 'LATEST',
:repo_key_path => '/etc/pki/rpm-gpg/',
:repo_key_name => 'RPM-GPG-KEY-gluster.pub',
:repo_key_source => 'puppet:///modules/gluster/RPM-GPG-KEY-gluster.pub',
}
end
it 'should install' do
should create_file('/etc/pki/rpm-gpg/RPM-GPG-KEY-gluster.pub')
should create_yumrepo('glusterfs-x86_64')
end
end
describe 'latest version on x86_64 with priority' do
let :facts do { :architecture => 'x86_64', } end
let :params do
{
:version => 'LATEST',
:repo_key_path => '/etc/pki/rpm-gpg/',
:repo_key_name => 'RPM-GPG-KEY-gluster.pub',
:repo_key_source => 'puppet:///modules/gluster/RPM-GPG-KEY-gluster.pub',
:priority => '50',
}
end
it 'should install' do
should create_file('/etc/pki/rpm-gpg/RPM-GPG-KEY-gluster.pub')
should create_package('yum-plugin-priorities')
should create_yumrepo('glusterfs-x86_64')
end
end
end
7 changes: 7 additions & 0 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe 'gluster::service', :type => :class do
it 'should start the service' do
should create_service('glusterd')
end
end
16 changes: 16 additions & 0 deletions spec/defines/mount_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe 'gluster::mount', :type => :define do
let(:title) { 'rspec' }
describe 'no volume specified' do
it 'should fail' do
expect { subject }.to raise_error(Puppet::Error, /Volume parameter is mandatory/)
end
end
describe 'bogus ensure value' do
let :params do { :volume => 'rspec', :ensure => 'foobar' } end
it 'should fail' do
expect { subject }.to raise_error(Puppet::Error, /Unknown option/)
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper'

0 comments on commit 7927438

Please sign in to comment.