File: instance_service_spec.rb

package info (click to toggle)
puppet-module-puppetlabs-haproxy 8.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: ruby: 3,979; sh: 14; makefile: 4
file content (197 lines) | stat: -rw-r--r-- 5,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# frozen_string_literal: true

require 'spec_helper'

describe 'haproxy::instance_service' do
  let(:facts) do
    {
      concat_basedir: '/dne',
      networking: {
        ip: '10.10.10.10'
      },
      os: {
        family: 'Debian'
      }
    }
  end
  let(:params) do
    {
      'haproxy_init_source' => 'foo'
    }
  end

  context 'when on any platform' do
    # haproxy::instance 'haproxy' with defaults

    context 'with title haproxy and defaults params' do
      let(:title) { 'haproxy' }
      let(:params) do
        {
          'haproxy_init_source' => '/foo/bar'
        }
      end

      it 'installs the haproxy package' do
        subject.should contain_package('haproxy').with(
          'ensure' => 'present',
        )
      end

      it 'creates the exec directory' do
        subject.should contain_file('/opt/haproxy/bin').with(
          'ensure' => 'directory', 'owner' => 'root',
          'group' => 'root', 'mode' => '0744'
        )
      end

      it 'creates a link to the exec' do
        subject.should contain_file('/opt/haproxy/bin/haproxy-haproxy').with(
          'ensure' => 'link',
          'target' => '/usr/sbin/haproxy',
        )
      end

      it 'does not create an init.d file' do
        subject.should_not contain_file('/etc/init.d/haproxy-haproxy').with(
          'ensure' => 'file',
        )
      end
    end

    # haproxy::instance 'haproxy' with custom settings

    context 'with title group1 and custom settings' do
      let(:title) { 'haproxy' }
      let(:pre_condition) do
        <<-PUPPETCODE
        service {'haproxy-#{title}': }
        PUPPETCODE
      end
      let(:params) do
        {
          'haproxy_package' => 'customhaproxy',
          'bindir' => '/weird/place',
          'haproxy_init_source' => '/foo/bar'
        }
      end

      it 'installs the customhaproxy package' do
        subject.should contain_package('customhaproxy').with(
          'ensure' => 'present',
        )
      end

      it 'creates the exec directory' do
        subject.should contain_file('/weird/place').with(
          'ensure' => 'directory', 'owner' => 'root',
          'group' => 'root', 'mode' => '0744'
        )
      end

      it 'creates a link to the exec' do
        subject.should contain_file('/weird/place/haproxy-haproxy').with(
          'ensure' => 'link',
          'target' => '/opt/customhaproxy/sbin/haproxy',
        )
      end

      it 'does not create an init.d file' do
        subject.should_not contain_file('/etc/init.d/haproxy-haproxy').with(
          'ensure' => 'file',
        )
      end

      it 'does not manage the default init.d file' do
        subject.should_not contain_file('/etc/init.d/haproxy').with(
          'ensure' => 'file',
        )
      end
    end

    # haproxy::instance 'group1' with defaults

    context 'with title group1 and defaults params' do
      let(:title) { 'group1' }
      let(:pre_condition) do
        <<-PUPPETCODE
        service {'haproxy-#{title}': }
        PUPPETCODE
      end
      let(:params) do
        {
          'haproxy_init_source' => '/foo/bar'
        }
      end

      it 'installs the haproxy package' do
        subject.should contain_package('haproxy').with(
          'ensure' => 'present',
        )
      end

      it 'creates the exec directory' do
        subject.should contain_file('/opt/haproxy/bin').with(
          'ensure' => 'directory', 'owner' => 'root',
          'group' => 'root', 'mode' => '0744'
        )
      end

      it 'creates a link to the exec' do
        subject.should contain_file('/opt/haproxy/bin/haproxy-group1').with(
          'ensure' => 'link',
          'target' => '/usr/sbin/haproxy',
        )
      end

      it 'does not create an init.d file' do
        subject.should_not contain_file('/etc/init.d/haproxy-haproxy').with(
          'ensure' => 'file',
        )
      end
    end
  end

  # haproxy::instance 'group1' with custom settings

  context 'with title group1 and defaults params' do
    let(:title) { 'group1' }
    let(:pre_condition) do
      <<-PUPPETCODE
        service {'haproxy-#{title}': }
      PUPPETCODE
    end
    let(:params) do
      {
        'haproxy_package' => 'customhaproxy',
        'bindir' => '/weird/place',
        'haproxy_init_source' => '/init/source/haproxy'
      }
    end

    it 'installs the customhaproxy package' do
      subject.should contain_package('customhaproxy').with(
        'ensure' => 'present',
      )
    end

    it 'creates the exec directory' do
      subject.should contain_file('/weird/place').with(
        'ensure' => 'directory', 'owner' => 'root',
        'group' => 'root', 'mode' => '0744'
      )
    end

    it 'creates a link to the exec' do
      subject.should contain_file('/weird/place/haproxy-group1').with(
        'ensure' => 'link',
        'target' => '/opt/customhaproxy/sbin/haproxy',
      )
    end

    it 'removes any obsolete init.d file' do
      subject.should contain_file('/etc/init.d/haproxy-group1').with(
        'ensure' => 'absent',
      )
    end
  end
end