Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default['redis']['version'] = '2.8.9'
19 changes: 9 additions & 10 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@
# https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis
#

execute "apt-get update"
version_number = node['redis']['version']

package "build-essential"
execute "apt-get update"

package "tcl8.5"
package [ "build-essential", "tcl8.5" ]

# download http://download.redis.io/releases/redis-2.8.9.tar.gz
remote_file "~/redis-2.8.9.tar.gz" do
source "http://download.redis.io/releases/redis-2.8.9.tar.gz"
notifies :run, "execute[tar xzf redis-2.8.9.tar.gz]", :immediately
remote_file "~/redis-#{version_number}.tar.gz" do
source "http://download.redis.io/releases/redis-#{version_number}.tar.gz"
notifies :run, "execute[tar xzf redis-#{version_number}.tar.gz]", :immediately
end

# unzip the archive
execute "tar xzf redis-2.8.9.tar.gz" do
execute "tar xzf redis-#{version_number}.tar.gz" do
cwd "/tmp"
action :nothing
notifies :run, "execute[make && make install]", :immediately
end

# Configure the application: make and make install
execute "make && make install" do
cwd "/tmp/redis-2.8.9"
cwd "/tmp/redis-#{version_number}"
action :nothing
notifies :run, "execute[echo -n | ./install_server.sh]", :immediately
end

# Install the Server
execute "echo -n | ./install_server.sh" do
cwd "/tmp/redis-2.8.9/utils"
cwd "/tmp/redis-#{version_number}/utils"
action :nothing
end

Expand Down
33 changes: 33 additions & 0 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,41 @@
runner.converge(described_recipe)
end

let(:version) { '2.8.9' }

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end

it 'execute a package repository update' do
expect(chef_run).to run_execute('apt-get update')
end

it 'installs the necessary packages' do
expect(chef_run).to install_package([ 'build-essential', 'tcl8.5' ])
end

it 'downloads the redis archive' do
expect(chef_run).to create_remote_file("~/redis-#{version}.tar.gz")
end

it 'unpacks the redis archive' do
resource = chef_run.remote_file('~/redis-2.8.9.tar.gz')
expect(resource).to notify('execute[tar xzf redis-2.8.9.tar.gz]').to(:run).immediately
end

it 'makes redis and installs it' do
resource = chef_run.execute('tar xzf redis-2.8.9.tar.gz')
expect(resource).to notify('execute[make && make install]').to(:run).immediately
end

it 'installs redis server' do
resource = chef_run.execute('make && make install')
expect(resource).to notify('execute[echo -n | ./install_server.sh]').to(:run).immediately
end

it 'starts the redis service' do
expect(chef_run).to start_service('redis_6379')
end
end
end