You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

memcached_spec.rb 2.8KB

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