diff options
| author | Micah Anderson <micah@riseup.net> | 2016-11-04 10:54:28 -0400 | 
|---|---|---|
| committer | Micah Anderson <micah@riseup.net> | 2016-11-04 10:54:28 -0400 | 
| commit | 34a381efa8f6295080c843f86bfa07d4e41056af (patch) | |
| tree | 9282cf5d4c876688602705a7fa0002bc4a810bde /puppet/modules/haproxy/spec | |
| parent | 0a72bc6fd292bf9367b314fcb0347c4d35042f16 (diff) | |
| parent | 5821964ff7e16ca7aa9141bd09a77d355db492a9 (diff) | |
Merge branch 'develop'
Diffstat (limited to 'puppet/modules/haproxy/spec')
| m--------- | puppet/modules/haproxy | 0 | ||||
| -rw-r--r-- | puppet/modules/haproxy/spec/classes/haproxy_spec.rb | 138 | ||||
| -rw-r--r-- | puppet/modules/haproxy/spec/defines/balancermember_spec.rb | 82 | ||||
| -rw-r--r-- | puppet/modules/haproxy/spec/defines/listen_spec.rb | 53 | ||||
| -rw-r--r-- | puppet/modules/haproxy/spec/spec.opts | 6 | ||||
| -rw-r--r-- | puppet/modules/haproxy/spec/spec_helper.rb | 1 | 
6 files changed, 280 insertions, 0 deletions
diff --git a/puppet/modules/haproxy b/puppet/modules/haproxy deleted file mode 160000 -Subproject af322a73c013f80a958ab7d5d31d0c75cf6d052 diff --git a/puppet/modules/haproxy/spec/classes/haproxy_spec.rb b/puppet/modules/haproxy/spec/classes/haproxy_spec.rb new file mode 100644 index 00000000..4b5902ce --- /dev/null +++ b/puppet/modules/haproxy/spec/classes/haproxy_spec.rb @@ -0,0 +1,138 @@ +require 'spec_helper' + +describe 'haproxy', :type => :class do +  let(:default_facts) do +    { +      :concat_basedir => '/dne', +      :ipaddress      => '10.10.10.10' +    } +  end +  context 'on supported platforms' do +    describe 'for OS-agnostic configuration' do +      ['Debian', 'RedHat'].each do |osfamily| +        context "on #{osfamily} family operatingsystems" do +          let(:facts) do +            { :osfamily => osfamily }.merge default_facts +          end +          let(:params) do +            {'enable' => true} +          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', +              'require'    => [ +                'Concat[/etc/haproxy/haproxy.cfg]', +                'File[/var/lib/haproxy]' +              ] +            ) +          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 manage the chroot directory' do +            subject.should contain_file('/var/lib/haproxy').with( +              'ensure' => 'directory' +            ) +          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' +            ) +          end +          describe 'Base concat fragment contents' do +            let(:contents) { param_value(subject, 'concat::fragment', 'haproxy-base', 'content').split("\n") } +            it 'should contain global and defaults sections' do +              contents.should include('global') +              contents.should include('defaults') +            end +            it 'should log to an ip address for local0' do +              contents.should be_any { |match| match =~ /  log  \d+(\.\d+){3} local0/ } +            end +            it 'should specify the default chroot' do +              contents.should include('  chroot  /var/lib/haproxy') +            end +            it 'should specify the correct user' do +              contents.should include('  user  haproxy') +            end +            it 'should specify the correct group' do +              contents.should include('  group  haproxy') +            end +            it 'should specify the correct pidfile' do +              contents.should include('  pidfile  /var/run/haproxy.pid') +            end +          end +        end +        context "on #{osfamily} family operatingsystems without managing the service" do +          let(:facts) do +            { :osfamily => osfamily }.merge default_facts +          end +          let(:params) do +            { +              'enable'         => true, +              'manage_service' => false, +            } +          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_not contain_service('haproxy') +          end +        end +      end +    end +    describe 'for OS-specific configuration' do +      context 'only on Debian family operatingsystems' do +        let(:facts) do +          { :osfamily => 'Debian' }.merge default_facts +        end +        it 'should manage haproxy service defaults' do +          subject.should contain_file('/etc/default/haproxy').with( +            'before'  => 'Service[haproxy]', +            'require' => 'Package[haproxy]' +          ) +          verify_contents(subject, '/etc/default/haproxy', ['ENABLED=1']) +        end +      end +      context 'only on RedHat family operatingsystems' do +        let(:facts) do +          { :osfamily => 'RedHat' }.merge default_facts +        end +      end +    end +  end +  context 'on unsupported operatingsystems' do +    let(:facts) do +      { :osfamily => 'RainbowUnicorn' }.merge default_facts +    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 diff --git a/puppet/modules/haproxy/spec/defines/balancermember_spec.rb b/puppet/modules/haproxy/spec/defines/balancermember_spec.rb new file mode 100644 index 00000000..74bc7a8b --- /dev/null +++ b/puppet/modules/haproxy/spec/defines/balancermember_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe 'haproxy::balancermember' do +  let(:title) { 'tyler' } +  let(:facts) do +    { +      :ipaddress => '1.1.1.1', +      :hostname  => 'dero' +    } +  end + +  context 'with a single balancermember option' do +    let(:params) do +      { +        :name              => 'tyler', +        :listening_service => 'croy', +        :ports             => '18140', +        :options           => 'check' +      } +    end + +    it { should contain_concat__fragment('croy_balancermember_tyler').with( +      'order'   => '20-croy-tyler', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "  server dero 1.1.1.1:18140 check\n\n" +    ) } +  end + +  context 'with multiple balancermember options' do +    let(:params) do +      { +        :name              => 'tyler', +        :listening_service => 'croy', +        :ports             => '18140', +        :options           => ['check', 'close'] +      } +    end + +    it { should contain_concat__fragment('croy_balancermember_tyler').with( +      'order'   => '20-croy-tyler', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "  server dero 1.1.1.1:18140 check close\n\n" +    ) } +  end + +  context 'with multiple servers' do +    let(:params) do +      { +        :name              => 'tyler', +        :listening_service => 'croy', +        :ports             => '18140', +        :server_names      => ['server01', 'server02'], +        :ipaddresses       => ['192.168.56.200', '192.168.56.201'], +        :options           => ['check'] +      } +    end + +    it { should contain_concat__fragment('croy_balancermember_tyler').with( +      'order'   => '20-croy-tyler', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "  server server01 192.168.56.200:18140 check\n  server server02 192.168.56.201:18140 check\n\n" +    ) } +  end +  context 'with multiple servers and multiple ports' do +    let(:params) do +      { +        :name              => 'tyler', +        :listening_service => 'croy', +        :ports             => ['18140','18150'], +        :server_names      => ['server01', 'server02'], +        :ipaddresses       => ['192.168.56.200', '192.168.56.201'], +        :options           => ['check'] +      } +    end + +    it { should contain_concat__fragment('croy_balancermember_tyler').with( +      'order'   => '20-croy-tyler', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "  server server01 192.168.56.200:18140,192.168.56.200:18150 check\n  server server02 192.168.56.201:18140,192.168.56.201:18150 check\n\n" +    ) } +  end +end diff --git a/puppet/modules/haproxy/spec/defines/listen_spec.rb b/puppet/modules/haproxy/spec/defines/listen_spec.rb new file mode 100644 index 00000000..31dd4c85 --- /dev/null +++ b/puppet/modules/haproxy/spec/defines/listen_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'haproxy::listen' do +  let(:title) { 'tyler' } +  let(:facts) {{ :ipaddress => '1.1.1.1' }} +  context "when only one port is provided" do +    let(:params) do +      { +        :name  => 'croy', +        :ports => '18140' +      } +    end + +    it { should contain_concat__fragment('croy_listen_block').with( +      'order'   => '20-croy-00', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "listen croy\n\n  bind 1.1.1.1:18140\n\n  balance  roundrobin\n  option  tcplog\n  option  ssl-hello-chk\n" +    ) } +  end +  context "when an array of ports is provided" do +    let(:params) do +      { +        :name      => 'apache', +        :ipaddress => '23.23.23.23', +        :ports     => [ +          '80', +          '443', +        ] +      } +    end + +    it { should contain_concat__fragment('apache_listen_block').with( +      'order'   => '20-apache-00', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "listen apache\n\n  bind 23.23.23.23:80\n\n  bind 23.23.23.23:443\n\n  balance  roundrobin\n  option  tcplog\n  option  ssl-hello-chk\n" +    ) } +  end +  context "when a comma-separated list of ports is provided" do +    let(:params) do +      { +        :name      => 'apache', +        :ipaddress => '23.23.23.23', +        :ports     => '80,443' +      } +    end + +    it { should contain_concat__fragment('apache_listen_block').with( +      'order'   => '20-apache-00', +      'target'  => '/etc/haproxy/haproxy.cfg', +      'content' => "listen apache\n\n  bind 23.23.23.23:80\n\n  bind 23.23.23.23:443\n\n  balance  roundrobin\n  option  tcplog\n  option  ssl-hello-chk\n" +    ) } +  end +end diff --git a/puppet/modules/haproxy/spec/spec.opts b/puppet/modules/haproxy/spec/spec.opts new file mode 100644 index 00000000..91cd6427 --- /dev/null +++ b/puppet/modules/haproxy/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/puppet/modules/haproxy/spec/spec_helper.rb b/puppet/modules/haproxy/spec/spec_helper.rb new file mode 100644 index 00000000..2c6f5664 --- /dev/null +++ b/puppet/modules/haproxy/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper'  | 
