Test cleanups for chefspec 1.3.0

ChefSpec 1.3.0 allows tests to evaluate guards.  Wired in
this cookbook to use that functionality.  Made tests a
bit clearer.

Change-Id: If6fae7b255de42ace75ecc507e99bb6bdd1be7e6
This commit is contained in:
John Dewey
2013-06-07 21:25:08 -07:00
parent 551f4b9851
commit a38ff0a276
7 changed files with 107 additions and 57 deletions

View File

@@ -3,6 +3,6 @@ source "https://rubygems.org"
gem "chef", "~> 11.4.4"
gem "json", "<= 1.7.7" # chef 11 dependency
gem "berkshelf", "~> 1.4.5"
gem "chefspec", "~> 1.2.0"
gem "chefspec", "~> 1.3.0"
gem "foodcritic"
gem "strainer"

View File

@@ -42,7 +42,7 @@ GEM
ohai (>= 0.6.0)
rest-client (>= 1.0.4, < 1.7.0)
yajl-ruby (~> 1.1)
chefspec (1.2.0)
chefspec (1.3.0)
chef (>= 10.0)
erubis
fauxhai (>= 0.1.1, < 2.0)
@@ -113,7 +113,7 @@ GEM
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nokogiri (1.5.9)
nokogiri (1.5.10)
nori (1.1.5)
ohai (6.16.0)
ipaddress
@@ -191,7 +191,7 @@ PLATFORMS
DEPENDENCIES
berkshelf (~> 1.4.5)
chef (~> 11.4.4)
chefspec (~> 1.2.0)
chefspec (~> 1.3.0)
foodcritic
json (<= 1.7.7)
strainer

View File

@@ -166,16 +166,17 @@ package "openstack-dashboard-ubuntu-theme" do
only_if { platform?("ubuntu")}
end
if platform?("debian","ubuntu") then
apache_site "000-default" do
enable false
end
elsif platform?("fedora") then
apache_site "default" do
enable false
apache_site "000-default" do
enable false
notifies :run, "execute[restore-selinux-context]", :immediately
end
only_if { platform?("debian","ubuntu") }
end
apache_site "default" do
enable false
notifies :run, "execute[restore-selinux-context]", :immediately
only_if { platform?("fedora") }
end
apache_site "openstack-dashboard" do

View File

@@ -22,8 +22,8 @@ describe "openstack-dashboard::server" do
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
::Chef::Recipe.any_instance.stub(:db).with("dashboard").and_return(
{"db_type" => "mysql", "db_name" => "flying_dolphin"})
@chef_run.converge "openstack-dashboard::server"
expect(@chef_run).to upgrade_package "python-mysql"
end
end
@@ -33,7 +33,6 @@ describe "openstack-dashboard::server" do
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
::Chef::Recipe.any_instance.stub(:db).with("dashboard").and_return(
{"db_type" => "postgresql", "db_name" => "flying_elephant"})
@chef_run.converge "openstack-dashboard::server"
end
@@ -47,11 +46,13 @@ describe "openstack-dashboard::server" do
it "creates local_settings.py" do
file = @chef_run.template "/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py"
expect(@chef_run).to create_file_with_content(file.name, "autogenerated")
end
it "creates .blackhole dir with proper owner" do
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
expect(@chef_run.directory(dir)).to be_owned_by "root"
end

View File

@@ -15,7 +15,13 @@ describe "openstack-dashboard::server" do
end
it "executes set-selinux-permissive" do
pending "TODO: how to properly test this"
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, true)
chef_run.converge "openstack-dashboard::server"
cmd = "/sbin/setenforce Permissive"
expect(chef_run).to execute_command cmd
end
it "installs packages" do
@@ -24,7 +30,13 @@ describe "openstack-dashboard::server" do
end
it "executes set-selinux-enforcing" do
pending "TODO: how to properly test this"
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, true)
chef_run.converge "openstack-dashboard::server"
cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd"
expect(chef_run).to execute_command cmd
end
describe "local_settings" do
@@ -82,9 +94,9 @@ describe "openstack-dashboard::server" do
end
it "sets the ServerName directive " do
chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS
node = chef_run.node
node.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS do |n|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
end
chef_run.converge "openstack-dashboard::server"
expect(chef_run).to create_file_with_content @file.name, "spec-test-host"
@@ -96,20 +108,36 @@ describe "openstack-dashboard::server" do
end
it "deletes openstack-dashboard.conf" do
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, true)
chef_run.converge "openstack-dashboard::server"
file = "/etc/httpd/conf.d/openstack-dashboard.conf"
expect(@chef_run).to delete_file file
expect(chef_run).to delete_file file
end
it "does not remove openstack-dashboard-ubuntu-theme package" do
pending "TODO: how to properly test this will not run"
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
expect(chef_run).not_to purge_package "openstack-dashboard-ubuntu-theme"
end
it "doesn't remove default apache site" do
pending "TODO: how to properly test this"
end
it "doesn't execute restore-selinux-context" do
pending "TODO: how to properly test this will not run"
end
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :"
it "doesn't remove default virtualhost" do
pending "TODO: how to properly test this will not run"
expect(chef_run).not_to execute_command cmd
end
end
end

View File

@@ -15,7 +15,13 @@ describe "openstack-dashboard::server" do
end
it "doesn't execute set-selinux-permissive" do
pending "TODO: how to properly test this will not run"
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "/sbin/setenforce Permissive"
expect(chef_run).not_to execute_command cmd
end
it "installs apache packages" do
@@ -26,7 +32,13 @@ describe "openstack-dashboard::server" do
end
it "doesn't execute set-selinux-enforcing" do
pending "TODO: how to properly test this will not run"
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd"
expect(chef_run).not_to execute_command cmd
end
it "installs packages" do
@@ -61,6 +73,7 @@ describe "openstack-dashboard::server" do
::Chef::Recipe.any_instance.stub(:memcached_servers).
and_return nil
chef_run.converge "openstack-dashboard::server"
expect(chef_run).not_to create_file_with_content @file.name,
"django.core.cache.backends.memcached.MemcachedCache"
end
@@ -70,14 +83,15 @@ describe "openstack-dashboard::server" do
::Chef::Recipe.any_instance.stub(:memcached_servers).
and_return []
chef_run.converge "openstack-dashboard::server"
expect(chef_run).not_to create_file_with_content @file.name,
"django.core.cache.backends.memcached.MemcachedCache"
end
it "has some plugins enabled" do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
node = chef_run.node
node.set["openstack"]["dashboard"]["plugins"] = ["testPlugin1" ]
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["plugins"] = ["testPlugin1" ]
end
chef_run.converge "openstack-dashboard::server"
expect(chef_run).to create_file_with_content @file.name, "testPlugin1"
@@ -124,6 +138,7 @@ describe "openstack-dashboard::server" do
it "creates .blackhole dir with proper owner" do
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
expect(@chef_run.directory(dir)).to be_owned_by "root"
end
@@ -151,22 +166,27 @@ describe "openstack-dashboard::server" do
end
it "sets the ServerName directive " do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
node = chef_run.node
node.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
end
chef_run.converge "openstack-dashboard::server"
expect(chef_run).to create_file_with_content @file.name, "spec-test-host"
end
it "notifies restore-selinux-context" do
expect(@file).to notify "execute[restore-selinux-context]", :run
end
end
it "does not delete openstack-dashboard.conf" do
pending "TODO: how to properly test this will not run"
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
file = "/etc/httpd/conf.d/openstack-dashboard.conf"
expect(chef_run).not_to delete_file file
end
it "removes openstack-dashboard-ubuntu-theme package" do
@@ -174,26 +194,20 @@ describe "openstack-dashboard::server" do
end
it "removes default virtualhost" do
chef_run = ::ChefSpec::ChefRunner.new(
:platform => "ubuntu",
:version => "12.04",
:step_into => ["apache_site"],
:log_level => :fatal
).converge "openstack-dashboard::server"
opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"])
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.converge "openstack-dashboard::server"
cmd = "/usr/sbin/a2dissite 000-default"
expect(chef_run).to execute_command cmd
end
it "enables virtualhost" do
chef_run = ::ChefSpec::ChefRunner.new(
:platform => "ubuntu",
:version => "12.04",
:step_into => ["apache_site"],
:log_level => :fatal
).converge "openstack-dashboard::server"
opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"])
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.converge "openstack-dashboard::server"
cmd = "/usr/sbin/a2ensite openstack-dashboard"
expect(chef_run).to execute_command cmd
end
@@ -202,7 +216,13 @@ describe "openstack-dashboard::server" do
end
it "doesn't execute restore-selinux-context" do
pending "TODO: how to properly test this will not run"
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :"
expect(chef_run).not_to execute_command cmd
end
end
end

View File

@@ -2,17 +2,17 @@ require "chefspec"
::LOG_LEVEL = :fatal
::REDHAT_OPTS = {
:platform => "redhat",
:version => "6.3",
:platform => "redhat",
:version => "6.3",
:log_level => ::LOG_LEVEL
}
::UBUNTU_OPTS = {
:platform => "ubuntu",
:version => "12.04",
:platform => "ubuntu",
:version => "12.04",
:log_level => ::LOG_LEVEL
}
::OPENSUSE_OPTS = {
:platform => "opensuse",
:version => "12.3",
:platform => "opensuse",
:version => "12.3",
:log_level => ::LOG_LEVEL
}