|
| 1 | +require 'spec_helper' |
| 2 | +describe 'memcached' do |
| 3 | + |
| 4 | + let :default_params do |
| 5 | + { |
| 6 | + :package_ensure => 'present', |
| 7 | + :logfile => '/var/log/memcached.log', |
| 8 | + :max_memory => false, |
| 9 | + :listen_ip => '0.0.0.0', |
| 10 | + :tcp_port => '11211', |
| 11 | + :udp_port => '11211', |
| 12 | + :user => 'nobody', |
| 13 | + :max_connections => '8192' |
| 14 | + } |
| 15 | + end |
| 16 | + |
| 17 | + [ {}, |
| 18 | + { |
| 19 | + :package_ensure => 'latest', |
| 20 | + :logfile => '/var/log/memcached.log', |
| 21 | + :max_memory => '2', |
| 22 | + :listen_ip => '127.0.0.1', |
| 23 | + :tcp_port => '11212', |
| 24 | + :udp_port => '11213', |
| 25 | + :user => 'somebdy', |
| 26 | + :max_connections => '8193' |
| 27 | + } |
| 28 | + ].each do |param_set| |
| 29 | + describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do |
| 30 | + |
| 31 | + let :param_hash do |
| 32 | + default_params.merge(param_set) |
| 33 | + end |
| 34 | + |
| 35 | + let :params do |
| 36 | + param_set |
| 37 | + end |
| 38 | + |
| 39 | + ['Debian', 'Ubuntu'].each do |os| |
| 40 | + |
| 41 | + let :facts do |
| 42 | + { |
| 43 | + :operatingsystem => os, |
| 44 | + :memorysize => '1', |
| 45 | + :processorcount => '1', |
| 46 | + } |
| 47 | + end |
| 48 | + |
| 49 | + describe "on supported operatingsystem: #{os}" do |
| 50 | + |
| 51 | + it { should contain_class('memcached::params') } |
| 52 | + |
| 53 | + it { should contain_package('memcached').with_ensure(param_hash[:package_ensure]) } |
| 54 | + |
| 55 | + it { should contain_file('/etc/memcached.conf').with( |
| 56 | + 'owner' => 'root', |
| 57 | + 'group' => 'root' |
| 58 | + )} |
| 59 | + |
| 60 | + it { should contain_service('memcached').with( |
| 61 | + 'ensure' => 'running', |
| 62 | + 'enable' => true, |
| 63 | + 'hasrestart' => true, |
| 64 | + 'hasstatus' => false |
| 65 | + )} |
| 66 | + |
| 67 | + it 'should compile the template based on the class parameters' do |
| 68 | + content = param_value( |
| 69 | + subject, |
| 70 | + 'file', |
| 71 | + '/etc/memcached.conf', |
| 72 | + 'content' |
| 73 | + ) |
| 74 | + expected_lines = [ |
| 75 | + "logfile #{param_hash[:logfile]}", |
| 76 | + "-l #{param_hash[:listen_ip]}", |
| 77 | + "-p #{param_hash[:tcp_port]}", |
| 78 | + "-U #{param_hash[:udp_port]}", |
| 79 | + "-u #{param_hash[:user]}", |
| 80 | + "-c #{param_hash[:max_connections]}", |
| 81 | + "-t #{facts[:processorcount]}" |
| 82 | + ] |
| 83 | + if(param_hash[:max_memory]) |
| 84 | + expected_lines.push("-m #{param_hash[:max_memory]}") |
| 85 | + else |
| 86 | + expected_lines.push("-m #{((facts[:memorysize].to_f*1024)*0.95).floor}") |
| 87 | + end |
| 88 | + (content.split("\n") & expected_lines).should =~ expected_lines |
| 89 | + end |
| 90 | + end |
| 91 | + end |
| 92 | + ['Redhat'].each do |os| |
| 93 | + describe 'on supported platform' do |
| 94 | + it 'should fail' do |
| 95 | + |
| 96 | + end |
| 97 | + end |
| 98 | + end |
| 99 | + end |
| 100 | + end |
| 101 | +end |
0 commit comments