Initial Chef repository
This commit is contained in:
27
cookbooks/redis/spec/client_spec.rb
Normal file
27
cookbooks/redis/spec/client_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe "redis::client" do
|
||||
let(:chef_run) do
|
||||
ChefSpec::SoloRunner.new.converge(described_recipe)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to include_recipe("redis::default") }
|
||||
|
||||
describe "package installation" do
|
||||
describe "default action" do
|
||||
it { expect(chef_run).to install_package("redis-tools") }
|
||||
it { expect(chef_run).to_not upgrade_package("redis-tools") }
|
||||
end
|
||||
|
||||
describe "when `auto_upgrade` is `true`" do
|
||||
let(:chef_run) do
|
||||
ChefSpec::SoloRunner.new do |node|
|
||||
node.set["redis"]["auto_upgrade"] = true
|
||||
end.converge(described_recipe)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to_not install_package("redis-tools") }
|
||||
it { expect(chef_run).to upgrade_package("redis-tools") }
|
||||
end
|
||||
end
|
||||
end
|
||||
19
cookbooks/redis/spec/default_spec.rb
Normal file
19
cookbooks/redis/spec/default_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe "redis::default" do
|
||||
let(:chef_run) do
|
||||
ChefSpec::SoloRunner.new.converge(described_recipe)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to add_apt_repository("chris-lea-redis-server") }
|
||||
|
||||
# debian family setup
|
||||
context "using debian platform" do
|
||||
let(:chef_run) do
|
||||
env_options = { platform: "debian", version: "6.0.5" }
|
||||
ChefSpec::SoloRunner.new(env_options).converge(described_recipe)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to add_apt_repository("dotdeb") }
|
||||
end
|
||||
end
|
||||
69
cookbooks/redis/spec/server_spec.rb
Normal file
69
cookbooks/redis/spec/server_spec.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe "redis::server" do
|
||||
let(:chef_run) do
|
||||
ChefSpec::SoloRunner.new.converge(described_recipe)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to include_recipe("redis::default") }
|
||||
|
||||
describe "package installation" do
|
||||
describe "default action" do
|
||||
it { expect(chef_run).to install_package("redis-server") }
|
||||
it { expect(chef_run).to_not upgrade_package("redis-server") }
|
||||
end
|
||||
|
||||
describe "when `auto_upgrade` is `true`" do
|
||||
let(:chef_run) do
|
||||
ChefSpec::SoloRunner.new do |node|
|
||||
node.set["redis"]["auto_upgrade"] = true
|
||||
end.converge(described_recipe)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to_not install_package("redis-server") }
|
||||
it { expect(chef_run).to upgrade_package("redis-server") }
|
||||
end
|
||||
end
|
||||
|
||||
it "creates the data directory" do
|
||||
expect(chef_run).to create_directory("/var/lib/redis").with(
|
||||
owner: "redis",
|
||||
group: "redis",
|
||||
mode: "0750",
|
||||
recursive: true
|
||||
)
|
||||
end
|
||||
|
||||
it { expect(chef_run).to enable_service("redis-server") }
|
||||
it { expect(chef_run).to start_service("redis-server") }
|
||||
|
||||
it "creates `/etc/redis/redis.conf`" do
|
||||
path = "/etc/redis/redis.conf"
|
||||
|
||||
expect(chef_run).to create_template(path).with(
|
||||
source: "redis.conf.erb",
|
||||
owner: "root",
|
||||
group: "root",
|
||||
mode: "0644"
|
||||
)
|
||||
|
||||
expect(chef_run.template(path)).to(
|
||||
notify("service[redis-server]").to(:restart)
|
||||
)
|
||||
end
|
||||
|
||||
it "creates `/etc/default/redis-server`" do
|
||||
path = "/etc/default/redis-server"
|
||||
|
||||
expect(chef_run).to create_template(path).with(
|
||||
source: "default_redis-server.erb",
|
||||
owner: "root",
|
||||
group: "root",
|
||||
mode: "0644"
|
||||
)
|
||||
|
||||
expect(chef_run.template(path)).to(
|
||||
notify("service[redis-server]").to(:restart)
|
||||
)
|
||||
end
|
||||
end
|
||||
20
cookbooks/redis/spec/spec_helper.rb
Normal file
20
cookbooks/redis/spec/spec_helper.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
begin
|
||||
require "chefspec"
|
||||
require "chefspec/berkshelf"
|
||||
rescue LoadError
|
||||
puts "Unable to run `chefspec`"
|
||||
exit
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.platform = "ubuntu"
|
||||
config.version = "12.04"
|
||||
config.log_level = :error
|
||||
config.raise_errors_for_deprecations!
|
||||
end
|
||||
|
||||
def add_apt_repository(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:apt_repository, :add, resource_name)
|
||||
end
|
||||
|
||||
at_exit { ChefSpec::Coverage.report! }
|
||||
Reference in New Issue
Block a user