summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile8
-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
7 files changed, 116 insertions, 10 deletions
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..c5e9594
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,8 @@
+require 'rake'
+
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.rspec_opts = '-c'
+ t.pattern = 'spec/*/*_spec.rb'
+end
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