Reworked tests to get them to pass

* brought in dependent cookbooks in librarian
* updated to most recent version of chefspec
This commit is contained in:
John Dewey
2012-11-20 16:27:19 -08:00
parent c275e4d453
commit 0f5ef59f5f
5 changed files with 24 additions and 25 deletions

View File

@@ -1,3 +1,7 @@
#!/usr/bin/env ruby
site "http://community.opscode.com/api/v1"
cookbook "database"
cookbook "openstack-utils",
:git => "git@github.com:att-cloud/cookbook-openstack-utils.git"

View File

@@ -1,6 +1,6 @@
source :rubygems
gem "chefspec", :git => "git://github.com/acrmp/chefspec.git"
gem "chefspec", "~> 0.9.0"
gem "librarian", "~> 0.0.24"
gem "foodcritic", "~> 1.6.1"
gem "hashie", "~> 1.2.0"

View File

@@ -1,13 +1,3 @@
GIT
remote: git://github.com/acrmp/chefspec.git
revision: 5cb01c464a572132edac802549efbc3c7c85485a
specs:
chefspec (0.8.0)
chef (>= 0.9.12)
erubis
minitest-chef-handler (~> 0.6.0)
rspec (~> 2.11.0)
GEM
remote: http://rubygems.org/
specs:
@@ -32,6 +22,11 @@ GEM
treetop (~> 1.4.9)
uuidtools
yajl-ruby (~> 1.1)
chefspec (0.9.0)
chef (>= 0.9.12)
erubis
minitest-chef-handler (~> 0.6.0)
rspec (~> 2.11.0)
ci_reporter (1.7.3)
builder (>= 2.1.2)
coderay (1.0.8)
@@ -115,7 +110,7 @@ PLATFORMS
ruby
DEPENDENCIES
chefspec!
chefspec (~> 0.9.0)
foodcritic (~> 1.6.1)
hashie (~> 1.2.0)
librarian (~> 0.0.24)

View File

@@ -101,7 +101,7 @@ module Openstack
user_prov = Chef::Provider::Database::PostgresqlUser
# See https://github.com/opscode-cookbooks/postgresql/blob/master/recipes/server.rb#L41
super_user = 'postgres'
super_password = node['postgresql']['password']['postgres']
super_password = @node['postgresql']['password']['postgres']
when 'mysql'
db_prov = Chef::Provider::Database::Mysql
user_prov = Chef::Provider::Database::MysqlUser
@@ -110,7 +110,7 @@ module Openstack
# For some reason, setting this to anything other than localhost fails miserably :(
host = 'localhost'
super_password = node['mysql']['server_root_password']
super_password = @node['mysql']['server_root_password']
else
Chef::Log.error("Unsupported database type #{type}")
end
@@ -129,7 +129,7 @@ module Openstack
database_name db_name
action :create
end
# create user
database_user user do
provider user_prov
@@ -137,7 +137,7 @@ module Openstack
password pass
action :create
end
# grant privs to user
database_user user do
provider user_prov

View File

@@ -3,7 +3,10 @@ require ::File.join ::File.dirname(__FILE__), "..", "libraries", "default"
describe ::Openstack do
before do
@chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default"
@chef_run = ::ChefSpec::ChefRunner.new do |n|
n.set['mysql'] = {}
n.set['mysql']['server_root_password'] = "pass"
end.converge "openstack-common::default"
@subject = ::Object.new.extend(::Openstack)
end
@@ -67,7 +70,7 @@ describe ::Openstack do
"host" => "localhost"
}
}
}
}
}
::Openstack.stub(:uri_from_hash).and_return "http://localhost"
@subject.instance_variable_set(:@node, uri_hash)
@@ -140,15 +143,12 @@ describe ::Openstack do
@subject.db_create_with_user("nonexisting", "user", "pass").should be_nil
end
it "returns db info and creates database with user when service found" do
stub_const("Chef::Provider::Database::Mysql", nil)
Chef::Recipe.any_instance.stub(:database).and_return(Hash.new)
@subject.stub(:database).and_return(Hash.new)
@subject.stub(:database_user).and_return(Hash.new)
@subject.instance_variable_set(:@node, @chef_run.node)
expect = {
'host' => '127.0.0.1',
'port' => 3306
}
result = @subject.db_create_with_user("compute", "user", "pass")
result.should eq expect
result['host'].should eq "127.0.0.1"
result['port'].should eq "3306"
end
end
end