diff --git a/.travis.yml b/.travis.yml index 91be52b..6be4579 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: ruby rvm: - - 1.9.3 - - 2.0.0 - 2.1.0 before_script: diff --git a/Gemfile b/Gemfile index ceb1e63..3b4e75a 100644 --- a/Gemfile +++ b/Gemfile @@ -4,16 +4,15 @@ gem 'rake' group :lint do gem 'rubocop', '~> 0.18' - gem 'foodcritic', '~> 3.0' + gem 'foodcritic', '~> 5.0' end group :unit, :integration do - gem 'berkshelf', '~> 3.0' + gem 'berkshelf', '~> 4.0' end group :unit do - gem 'chefspec', '~> 3.1' - gem 'rspec-expectations', '~> 2.14.0' + gem 'chefspec', '~> 4.3' end group :integration do diff --git a/README.md b/README.md index b63ffb4..4ab4f7a 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ This cookbook doesn't have direct dependencies on other cookbooks. Attributes ========== -* `node[:beanstalkd][:opts]` - The opts array value, defaults to {} -* `node[:beanstalkd][:start_during_boot]` - The start during boot value, defaults to false (beanstalkd on Ubuntu only) +* `node[:beanstalkd][:opts]` - The opts array value, defaults to `{l: '127.0.01', p: '11300'}` +* `node[:beanstalkd][:start_during_boot]` - The start during boot value, defaults to false (beanstalkd on Debian only) Usage ===== diff --git a/attributes/default.rb b/attributes/default.rb index c51e250..42f6385 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,7 +5,10 @@ # Copyright 2012-2014, Escape Studios # -default[:beanstalkd][:opts] = {} +default[:beanstalkd][:opts] = { + :p => '11300', + :l => '127.0.0.1' +} -# Ubuntu only +# Debian Only default[:beanstalkd][:start_during_boot] = false diff --git a/spec/unit/debian_spec.rb b/spec/unit/debian_spec.rb new file mode 100644 index 0000000..28ec679 --- /dev/null +++ b/spec/unit/debian_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe 'beanstalkd::default' do + let(:chef_run) do + ChefSpec::ServerRunner.new(:platform => 'debian', :version => '7.2') do |node| + node.automatic[:fqdn] = 'myserver' + end.converge(described_recipe) + end + + it 'should install beanstalkd service' do + expect(chef_run).to upgrade_package('beanstalkd') + end + + it 'should start beanstalkd service' do + expect(chef_run).to enable_service('beanstalkd') + expect(chef_run).to start_service('beanstalkd') + end + + it 'should creates a defaults file at /etc/default/beanstalkd' do + expect(chef_run).to(render_file('/etc/default/beanstalkd').with_content do |content| + expect(content).to include('Generated by Chef for myserver') + expect(content).to include('DAEMON_OPTS="-p 11300 -l 127.0.0.1 "') + end) + end +end diff --git a/spec/unit/default_spec.rb b/spec/unit/default_spec.rb index e3a1fea..d2d28f2 100644 --- a/spec/unit/default_spec.rb +++ b/spec/unit/default_spec.rb @@ -1,5 +1,26 @@ require 'spec_helper' describe 'beanstalkd::default' do - let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } + let(:chef_run) do + ChefSpec::ServerRunner.new(:platform_family => 'centos') do |node| + node.automatic[:fqdn] = 'myserver' + end.converge(described_recipe) + end + + it 'should install beanstalkd service' do + expect(chef_run).to upgrade_package('beanstalkd') + end + + it 'should start beanstalkd service' do + expect(chef_run).to enable_service('beanstalkd') + expect(chef_run).to start_service('beanstalkd') + end + + it 'should creates a defaults file at /etc/sysconfig/beanstalkd' do + expect(chef_run).to(render_file('/etc/sysconfig/beanstalkd').with_content do |content| + expect(content).to include('Generated by Chef for myserver') + expect(content).to include('BEANSTALKD_ADDR=127.0.0.1') + expect(content).to include('BEANSTALKD_PORT=11300') + end) + end end diff --git a/spec/unit/ubuntu_spec.rb b/spec/unit/ubuntu_spec.rb new file mode 100644 index 0000000..9f98677 --- /dev/null +++ b/spec/unit/ubuntu_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe 'beanstalkd::default' do + let(:chef_run) do + ChefSpec::ServerRunner.new(:platform => 'ubuntu', :version => '14.04') do |node| + node.automatic[:fqdn] = 'myserver' + end.converge(described_recipe) + end + + it 'should install beanstalkd service' do + expect(chef_run).to upgrade_package('beanstalkd') + end + + it 'should start beanstalkd service' do + expect(chef_run).to enable_service('beanstalkd') + expect(chef_run).to start_service('beanstalkd') + end + + it 'should creates a defaults file at /etc/default/beanstalkd' do + expect(chef_run).to(render_file('/etc/default/beanstalkd').with_content do |content| + expect(content).to include('Generated by Chef for myserver') + expect(content).to include('BEANSTALKD_LISTEN_ADDR=127.0.0.1') + expect(content).to include('BEANSTALKD_LISTEN_PORT=11300') + expect(content).to include('BEANSTALKD_EXTRA=""') + end) + end +end diff --git a/templates/ubuntu/beanstalkd.erb b/templates/ubuntu/beanstalkd.erb index fc718b6..3024873 100644 --- a/templates/ubuntu/beanstalkd.erb +++ b/templates/ubuntu/beanstalkd.erb @@ -3,12 +3,13 @@ # # Generated by Chef for <%= node[:fqdn] %> # - ## Defaults for the beanstalkd init script, /etc/init.d/beanstalkd on -## Debian systems. Append ``-b /var/lib/beanstalkd'' for persistent -## storage. -BEANSTALKD_EXTRA="<% @opts.each do |k,v| %><%= "-#{k} #{v}" %> <% end %>" -DAEMON_OPTS=$BEANSTALKD_EXTRA +## Debian systems. +<% @opts = @opts.to_hash # making a copy so we can delete keys %> -## Uncomment to enable startup during boot. -<% unless @start_during_boot %>#<% end %>START=yes \ No newline at end of file +BEANSTALKD_LISTEN_ADDR=<%= @opts.delete('l') %> +BEANSTALKD_LISTEN_PORT=<%= @opts.delete('p') %> + +# You can use BEANSTALKD_EXTRA to pass additional options. See beanstalkd(1) +# for a list of the available options. +BEANSTALKD_EXTRA="<% @opts.each do |k,v| %><%= "-#{k} #{v}" %> <% end %>"