2 describe 'memcached' do
4 describe 'with manage_firewall parameter' do
5 ['Debian','RedHat'].each do |osfam|
6 context "on osfamily #{osfam}" do
9 :memorysize => '1000 MB',
10 :processorcount => '1',
14 ['true',true].each do |value|
15 context "set to #{value}" do
16 let(:params) { { :manage_firewall => value } }
18 it { should contain_class('memcached') }
20 it { should contain_firewall('100_tcp_11211_for_memcached') }
21 it { should contain_firewall('100_udp_11211_for_memcached') }
25 ['false',false].each do |value|
26 context "set to #{value}" do
27 let(:params) { { :manage_firewall => value } }
29 it { should contain_class('memcached') }
31 it { should_not contain_firewall('100_tcp_11211_for_memcached') }
32 it { should_not contain_firewall('100_udp_11211_for_memcached') }
36 context 'set to an invalid type (array)' do
37 let(:params) { { :manage_firewall => ['invalid','type'] } }
41 should contain_class('memcached')
42 }.to raise_error(Puppet::Error)
49 let :default_params do
51 :package_ensure => 'present',
52 :logfile => '/var/log/memcached.log',
55 :lock_memory => false,
56 :listen_ip => '0.0.0.0',
60 :max_connections => '8192',
61 :install_dev => false,
64 :large_mem_pages => false,
70 :package_ensure => 'latest',
71 :logfile => '/var/log/memcached.log',
75 :listen_ip => '127.0.0.1',
79 :max_connections => '8193',
83 :large_mem_pages => true,
86 :package_ensure => 'present',
87 :logfile => '/var/log/memcached.log',
89 :lock_memory => false,
90 :listen_ip => '127.0.0.1',
94 :max_connections => '8193',
106 :pidfile => '/var/log/memcached.pid',
109 :package_ensure => 'absent',
113 :service_manage => false
115 ].each do |param_set|
116 describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
119 default_params.merge(param_set)
126 ['Debian'].each do |osfamily|
130 :osfamily => osfamily,
131 :memorysize => '1000 MB',
132 :processorcount => '1',
136 describe "on supported osfamily: #{osfamily}" do
138 it { should contain_class("memcached::params") }
140 it { should contain_package("memcached").with_ensure(param_hash[:package_ensure]) }
142 it { should_not contain_firewall('100_tcp_11211_for_memcached') }
143 it { should_not contain_firewall('100_udp_11211_for_memcached') }
146 if param_hash[:install_dev]
147 should contain_package("libmemcached-dev").with_ensure(param_hash[:package_ensure])
151 it { should contain_file("/etc/memcached.conf").with(
157 if param_hash[:service_manage] == false
158 should_not contain_service('memcached')
159 elsif param_hash[:package_ensure] == 'absent'
160 should contain_service("memcached").with(
161 'ensure' => 'stopped',
165 should contain_service("memcached").with(
166 'ensure' => 'running',
168 'hasrestart' => true,
174 it 'should compile the template based on the class parameters' do
175 content = param_value(
178 '/etc/memcached.conf',
182 "logfile #{param_hash[:logfile]}",
183 "-p #{param_hash[:tcp_port]}",
184 "-U #{param_hash[:udp_port]}",
185 "-u #{param_hash[:user]}",
186 "-c #{param_hash[:max_connections]}",
187 "-t #{param_hash[:processorcount]}"
189 if(param_hash[:max_memory])
190 if(param_hash[:max_memory].end_with?('%'))
191 expected_lines.push("-m 200")
193 expected_lines.push("-m #{param_hash[:max_memory]}")
196 expected_lines.push("-m 950")
198 if(param_hash[:listen_ip] != '')
199 expected_lines.push("-l #{param_hash[:listen_ip]}")
201 if(param_hash[:lock_memory])
202 expected_lines.push("-k")
204 if(param_hash[:pidfile])
205 expected_lines.push("-P #{param_hash[:pidfile]}")
207 if(param_hash[:verbosity])
208 expected_lines.push("-vvv")
210 if(param_hash[:use_sasl])
211 expected_lines.push("-S")
213 if(param_hash[:large_mem_pages])
214 expected_lines.push("-L")
216 (content.split("\n") & expected_lines).should =~ expected_lines
220 ['Redhat'].each do |osfamily|
221 describe 'on supported platform' do
231 # vim: expandtab shiftwidth=2 softtabstop=2