diff --git a/spec/acceptance/suites/default/redis_adminstration_spec.rb b/spec/acceptance/suites/default/redis_adminstration_spec.rb index 2e7a4ea..89b800b 100644 --- a/spec/acceptance/suites/default/redis_adminstration_spec.rb +++ b/spec/acceptance/suites/default/redis_adminstration_spec.rb @@ -1,39 +1,32 @@ -# rubocop:disable RSpec/MultipleExpectations require 'spec_helper_acceptance' # systcl settings are untestable in docker -unless default['hypervisor'] =~ %r{docker} - describe 'redis::administration' do - it 'runs successfully' do - pp = <<-EOS - include redis - include redis::administration - EOS +describe 'redis::administration', unless: default['hypervisor'] =~ %r{docker} do + it 'runs successfully' do + pp = <<-EOS + include redis + include redis::administration + EOS - # Apply twice to ensure no errors the second time. - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - it 'sets overcommit_memory to 1 in a seperate sysctl file' do - shell('/bin/cat /proc/sys/vm/overcommit_memory') do |result| - expect(result.stdout).to match(%r{^1$}) - end - end - it 'disables thp' do - shell('/bin/cat /sys/kernel/mm/transparent_hugepage/enabled') do |result| - expect(result.stdout).to match(%r{^always madvise \[never\]$}) - end - end - it 'sets somaxconn to 65535' do - shell('/bin/cat /proc/sys/net/core/somaxconn') do |result| - expect(result.stdout).to match(%r{^65535$}) - end - end - it 'shows no warnings about kernel settings in logs' do - shell('timeout 1s redis-server --port 7777 --loglevel verbose', acceptable_exit_codes: [0, 124]) do |result| - expect(result.stdout).not_to match(%r{WARNING}) - expect(result.exit_code).to match(124) - end - end + # Apply twice to ensure no errors the second time. + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + + describe file('/proc/sys/vm/overcommit_memory') do + its(:content) { is_expected.to eq("1\n") } + end + + describe file('/sys/kernel/mm/transparent_hugepage/enabled') do + its(:content) { is_expected.to eq("always madvise [never]\n") } + end + + describe file('/proc/sys/net/core/somaxconn') do + its(:content) { is_expected.to eq("65535\n") } + end + + describe command('timeout 1s redis-server --port 7777 --loglevel verbose') do + its(:stderr) { is_expected.not_to match(%r{WARNING}) } + its(:exit_status) { is_expected.to eq(124) } end end diff --git a/spec/acceptance/suites/default/redisget_spec.rb b/spec/acceptance/suites/default/redisget_spec.rb index f7c199c..5d9391c 100644 --- a/spec/acceptance/suites/default/redisget_spec.rb +++ b/spec/acceptance/suites/default/redisget_spec.rb @@ -1,110 +1,111 @@ -# rubocop:disable RSpec/MultipleExpectations require 'spec_helper_acceptance' describe 'redis::get() function' do it 'runs successfully' do pp = <<-EOS include redis package { 'redis-rubygem' : ensure => '3.3.3', name => 'redis', provider => 'puppet_gem', } EOS # Apply twice to ensure no errors the second time. apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) + end - shell('redis-cli SET mykey "Hello"') do |result| - expect(result.stdout).to match('OK') - end + describe command('redis-cli SET mykey "Hello"') do + its(:stdout) { is_expected.to match(%r{OK}) } + end - shell('redis-cli GET mykey') do |result| - expect(result.stdout).to match('Hello') - end + describe command('redis-cli GET mykey') do + its(:stdout) { is_expected.to match('Hello') } end - it 'returns a value from MyKey with the redis::get() function' do - pp = <<-EOS - $mykey = redis::get('mykey', 'redis://127.0.0.1:6379') + context 'with mykey set to Hello' do + it 'returns a value from MyKey with the redis::get() function' do + pp = <<-EOS + $mykey = redis::get('mykey', 'redis://127.0.0.1:6379') - notify{"mykey value: ${mykey}":} - EOS + notify{"mykey value: ${mykey}":} + EOS - # Check output for function return value - apply_manifest(pp, catch_failures: true) do |r| - expect(r.stdout).to match(%r{mykey value: Hello}) + # Check output for function return value + apply_manifest(pp, catch_failures: true) do |r| + expect(r.stdout).to match(%r{mykey value: Hello}) + end end - end - it 'returns a value from valid MyKey with the redis::get() function while specifying a default' do - pp = <<-EOS - $mykey = redis::get('mykey', 'redis://127.0.0.1:6379', 'default_value') + it 'returns a value from valid MyKey with the redis::get() function while specifying a default' do + pp = <<-EOS + $mykey = redis::get('mykey', 'redis://127.0.0.1:6379', 'default_value') - notify{"mykey value: ${mykey}":} - EOS + notify{"mykey value: ${mykey}":} + EOS - # Check output for function return value - apply_manifest(pp, catch_failures: true) do |r| - expect(r.stdout).to match(%r{mykey value: Hello}) + # Check output for function return value + apply_manifest(pp, catch_failures: true) do |r| + expect(r.stdout).to match(%r{mykey value: Hello}) + end end - end - it 'returns an empty string when value not present with redis::get() function' do - pp = <<-EOS - $foo_key = redis::get('foo', 'redis://127.0.0.1:6379') + it 'returns an empty string when value not present with redis::get() function' do + pp = <<-EOS + $foo_key = redis::get('foo', 'redis://127.0.0.1:6379') - if empty($foo_key){ - notify{"foo_key value was empty string":} - } - EOS + if empty($foo_key){ + notify{"foo_key value was empty string":} + } + EOS - # Check output for function return value - apply_manifest(pp, catch_failures: true) do |r| - expect(r.stdout).to match(%r{foo_key value was empty string}) + # Check output for function return value + apply_manifest(pp, catch_failures: true) do |r| + expect(r.stdout).to match(%r{foo_key value was empty string}) + end end - end - it 'returns the specified default value when key not present with redis::get() function' do - pp = <<-EOS - $foo_key = redis::get('foo', 'redis://127.0.0.1:6379', 'default_value') + it 'returns the specified default value when key not present with redis::get() function' do + pp = <<-EOS + $foo_key = redis::get('foo', 'redis://127.0.0.1:6379', 'default_value') - notify { $foo_key: } - EOS + notify { $foo_key: } + EOS - # Check output for function return value - apply_manifest(pp, catch_failures: true) do |r| - expect(r.stdout).to match(%r{default_value}) + # Check output for function return value + apply_manifest(pp, catch_failures: true) do |r| + expect(r.stdout).to match(%r{default_value}) + end end - end - it 'returns the specified default value when connection to redis server fails' do - pp = <<-EOS - # Bogus port for redis server - $foo_key = redis::get('foo', 'redis://127.0.0.1:12345', 'default_value') + it 'returns the specified default value when connection to redis server fails' do + pp = <<-EOS + # Bogus port for redis server + $foo_key = redis::get('foo', 'redis://127.0.0.1:12345', 'default_value') - notify { $foo_key: } - EOS + notify { $foo_key: } + EOS - # Check output for function return value - apply_manifest(pp, catch_failures: true) do |r| - expect(r.stdout).to match(%r{default_value}) + # Check output for function return value + apply_manifest(pp, catch_failures: true) do |r| + expect(r.stdout).to match(%r{default_value}) + end end - end - it 'returns an error when specifying a non connectable redis server' do - pp = <<-EOS - # Bogus port for redis server - $foo_key = redis::get('foo', 'redis://127.0.0.1:12345') + it 'returns an error when specifying a non connectable redis server' do + pp = <<-EOS + # Bogus port for redis server + $foo_key = redis::get('foo', 'redis://127.0.0.1:12345') - notify { $foo_key: } - EOS + notify { $foo_key: } + EOS - # Check output for error when can't connect to bogus redis - apply_manifest(pp, acceptable_exit_codes: [1]) do |r| - expect(r.stderr).to match(%r{Error connecting to Redis on 127.0.0.1:12345 \(Errno::ECONNREFUSED\)}) + # Check output for error when can't connect to bogus redis + apply_manifest(pp, acceptable_exit_codes: [1]) do |r| + expect(r.stderr).to match(%r{Error connecting to Redis on 127.0.0.1:12345 \(Errno::ECONNREFUSED\)}) + end end end end