summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGary Larizza <gary@puppetlabs.com>2012-05-09 16:38:43 -0700
committerGary Larizza <gary@puppetlabs.com>2012-05-09 16:38:43 -0700
commit580e831fbb7ba60cc0206661a8cfe263613c2b5e (patch)
tree5ea4f7ae5ef95e72433e046aed367cf07bfb9172 /spec
parent01d46be262154b76ffd794fadf0d43deeb425fa6 (diff)
Commit spec tests for the haproxy module
Previously, the haproxy module didn't provide rspec tests for the class or defined resource types. This commit adds the tests, a spec_helper file, and a rakefile so you can do `rake spec` and automatically run the tests. I've also committed a symlink in the spec/fixtures/modules/haproxy directory so the rspec-puppet tests will FIND the haproxy class/defined resource types, but I HAVE NOT committed a symlink so that it will find the concat class (which is a dependency for this module). If you choose to run the tests, you must symlink the concat module in the spec/fixtures/modules directory before the spec tests will pass.
Diffstat (limited to 'spec')
-rw-r--r--spec/classes/haproxy_spec.rb61
-rw-r--r--spec/defines/balancermember_spec.rb23
-rw-r--r--spec/defines/config_spec.rb17
-rw-r--r--spec/fixtures/manifests/site.pp0
l---------spec/fixtures/modules/haproxy1
-rw-r--r--spec/spec_helper.rb16
6 files changed, 108 insertions, 10 deletions
diff --git a/spec/classes/haproxy_spec.rb b/spec/classes/haproxy_spec.rb
new file mode 100644
index 0000000..4c90b18
--- /dev/null
+++ b/spec/classes/haproxy_spec.rb
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+describe 'haproxy', :type => :class do
+
+ context 'on Redhat family operatingsystems' do
+ let(:facts) do
+ { :osfamily => 'Redhat' }
+ end
+ it { should include_class('concat::setup') }
+
+ it 'should install the haproxy package' do
+ subject.should contain_package('haproxy').with(
+ 'ensure' => 'present'
+ )
+ end
+
+ it 'should install the haproxy service' do
+ subject.should contain_service('haproxy').with(
+ 'ensure' => 'running',
+ 'enable' => 'true',
+ 'hasrestart' => 'true',
+ 'hasstatus' => 'true'
+ )
+ end
+
+ it 'should set up /etc/haproxy/haproxy.cfg as a concat resource' do
+ subject.should contain_concat('/etc/haproxy/haproxy.cfg').with(
+ 'owner' => '0',
+ 'group' => '0',
+ 'mode' => '0644'
+ )
+ end
+
+ it 'should contain a header concat fragment' do
+ subject.should contain_concat__fragment('00-header').with(
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'order' => '01',
+ 'content' => "# This file managed by Puppet\n"
+ )
+ end
+
+ it 'should contain a haproxy-base concat fragment' do
+ subject.should contain_concat__fragment('haproxy-base').with(
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'order' => '10',
+ 'content' => "global\n chroot /var/lib/haproxy\n daemon \n group haproxy\n log local0\n maxconn 4000\n pidfile /var/run/haproxy.pid\n stats socket /var/lib/haproxy/stats\n user haproxy\n\ndefaults\n log global\n maxconn 8000\n option redispatch\n retries 3\n stats enable\n timeout http-request 10s\n timeout queue 1m\n timeout connect 10s\n timeout client 1m\n timeout server 1m\n timeout check 10s\n"
+ )
+ end
+ end
+
+ context 'on non-Redhat family operatingsystems' do
+ let(:facts) do
+ { :osfamily => 'Debian' }
+ end
+ it do
+ expect {
+ should contain_service('haproxy')
+ }.to raise_error(Puppet::Error, /operating system is not supported with the haproxy module/)
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/defines/balancermember_spec.rb b/spec/defines/balancermember_spec.rb
new file mode 100644
index 0000000..75b761e
--- /dev/null
+++ b/spec/defines/balancermember_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe 'haproxy::balancermember' do
+ let(:title) { 'tyler' }
+ let(:facts) do
+ { :ipaddress => '1.1.1.1',
+ :hostname => 'dero'
+ }
+ end
+ let(:params) do
+ { :name => 'tyler',
+ :listening_service => 'croy',
+ :balancer_port => '18140',
+ :balancermember_options => 'check'
+ }
+ end
+
+ it { should contain_concat__fragment('croy_balancermember_tyler').with(
+ 'order' => '20',
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'content' => " server dero 1.1.1.1:18140 check \n"
+ ) }
+end \ No newline at end of file
diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb
new file mode 100644
index 0000000..89993ee
--- /dev/null
+++ b/spec/defines/config_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'haproxy::config' do
+ let(:title) { 'tyler' }
+ let(:facts) {{ :ipaddress => '1.1.1.1' }}
+ let(:params) do
+ { :name => 'croy',
+ :virtual_ip_port => '18140'
+ }
+ end
+
+ it { should contain_concat__fragment('croy_config_block').with(
+ 'order' => '20',
+ 'target' => '/etc/haproxy/haproxy.cfg',
+ 'content' => "\nlisten croy 1.1.1.1:18140\n balance roundrobin\n option tcplog\n option ssl-hello-chk\n"
+ ) }
+end \ No newline at end of file
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spec/fixtures/manifests/site.pp
diff --git a/spec/fixtures/modules/haproxy b/spec/fixtures/modules/haproxy
new file mode 120000
index 0000000..1b20c9f
--- /dev/null
+++ b/spec/fixtures/modules/haproxy
@@ -0,0 +1 @@
+../../../ \ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5fda588..9dbbf18 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,17 +1,13 @@
-dir = File.expand_path(File.dirname(__FILE__))
-$LOAD_PATH.unshift File.join(dir, 'lib')
-
-require 'mocha'
require 'puppet'
-require 'rspec'
-require 'spec/autorun'
+require 'rubygems'
+require 'rspec-puppet'
-Spec::Runner.configure do |config|
- config.mock_with :mocha
+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
-# We need this because the RAL uses 'should' as a method. This
-# allows us the same behaviour but with a different method name.
class Object
alias :must :should
end