Files
cookbook-openstack-common/spec/password_spec.rb
John Dewey 5df85f3706 Refactored tests
* Tests are now passing
* Removed chef-solo conditional from #memcached_server
* All tests should log if fatal encountered, this cleans up stdout
* #db_create_with_user test had a test which wouldn't occur, b/c
  the attributes have a default value
* Added a couple pending tests for the database LWRPs
2013-05-06 19:16:41 -07:00

91 lines
3.7 KiB
Ruby

require "chefspec"
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "passwords"
describe ::Openstack do
before do
@chef_run = ::ChefSpec::ChefRunner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default"
@subject = ::Object.new.extend(::Openstack)
end
describe "#secret" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@subject.stub(:node).and_return @chef_run.node
result = @subject.secret("passwords", "nova")
result.should == "nova"
end
it "returns databag when developer_mode is false" do
value = {"nova" => "this"}
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret"
::Chef::EncryptedDataBagItem.stub(:load).with("passwords", "nova", "secret").and_return value
@subject.stub(:node).and_return @chef_run.node
result = @subject.secret("passwords", "nova")
result.should == "this"
end
end
describe "#service_password" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@subject.stub(:node).and_return @chef_run.node
result = @subject.service_password("nova")
result.should == "nova"
end
it "returns databag when developer_mode is false" do
value = {"nova" => "this"}
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret"
::Chef::EncryptedDataBagItem.stub(:load).with("service_passwords", "nova", "secret").and_return value
@subject.stub(:node).and_return @chef_run.node
result = @subject.service_password("nova")
result.should == "this"
end
end
describe "#db_password" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@subject.stub(:node).and_return @chef_run.node
result = @subject.db_password("nova")
result.should == "nova"
end
it "returns databag when developer_mode is false" do
value = {"nova" => "this"}
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret"
::Chef::EncryptedDataBagItem.stub(:load).with("db_passwords", "nova", "secret").and_return value
@subject.stub(:node).and_return @chef_run.node
result = @subject.db_password("nova")
result.should == "this"
end
end
describe "#user_password" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@subject.stub(:node).and_return @chef_run.node
result = @subject.user_password("nova")
result.should == "nova"
end
it "returns databag when developer_mode is false" do
value = {"nova" => "this"}
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret"
::Chef::EncryptedDataBagItem.stub(:load).with("user_passwords", "nova", "secret").and_return value
@subject.stub(:node).and_return @chef_run.node
result = @subject.user_password("nova")
result.should == "this"
end
end
end