Skip to content

Commit

Permalink
update test-kitchen to account for COOK-1406
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimberman committed Nov 28, 2012
1 parent 21119ba commit 42d3e2e
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 3 deletions.
27 changes: 27 additions & 0 deletions files/default/tests/minitest/default_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require File.expand_path('../support/helpers', __FILE__)

describe 'mycookbook::default' do
include Helpers::Postgresql

it 'installs the postgresql client packages' do
node['postgresql']['client']['packages'].each do |pkg|
package(pkg).must_be_installed
end
end
end
28 changes: 28 additions & 0 deletions files/default/tests/minitest/ruby_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Cookbook Name:: postgresql_test
# Recipe:: default
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require File.expand_path('../support/helpers', __FILE__)

describe 'mycookbook::default' do
include Helpers::Postgresql

it 'installs the pg gem in Chefs ruby environment' do
assert Gem::Specification.all_names.grep("pg-.*")
end
end
43 changes: 43 additions & 0 deletions files/default/tests/minitest/server_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require File.expand_path('../support/helpers', __FILE__)

describe 'mycookbook::default' do
include Helpers::Postgresql

it 'installs the postgresql server packages' do
node['postgresql']['server']['packages'].each do |pkg|
package(pkg).must_be_installed
end
end

it 'runs the postgresql service' do
service(node['postgresql']['server']['service_name']).must_be_running
end

it 'can connect to postgresql' do
require 'pg'
conn = PG::Connection.new(
:host => 'localhost',
:port => '5432',
:password => node['postgresql']['password']['postgres'],
:user => "postgres"
)
assert_match(/localhost/, conn.host)
end

end
27 changes: 27 additions & 0 deletions files/default/tests/minitest/support/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Cookbook Name:: postgresql_test
# Recipe:: default
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Helpers
module Postgresql
include MiniTest::Chef::Assertions
include MiniTest::Chef::Context
include MiniTest::Chef::Resources

end
end
1 change: 1 addition & 0 deletions test/kitchen/Kitchenfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cookbook "postgresql" do
configuration "default"
configuration "ruby"
configuration "server"
end
5 changes: 2 additions & 3 deletions test/kitchen/cookbooks/postgresql_test/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs/Configures postgresql_test"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0"
description "This cookbook is used with test-kitchen to test the parent, postgresql cookbook"
version "1.0.0"
20 changes: 20 additions & 0 deletions test/kitchen/cookbooks/postgresql_test/recipes/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Cookbook Name:: postgresql_test
# Recipe:: default
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "postgresql::ruby"
2 changes: 2 additions & 0 deletions test/kitchen/cookbooks/postgresql_test/recipes/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#
# Cookbook Name:: postgresql_test
# Recipe:: server
Expand All @@ -19,4 +20,5 @@

node.set['postgresql']['password']['postgres'] = "iloverandompasswordsbutthiswilldo"

include_recipe "postgresql::ruby"
include_recipe "postgresql::server"

0 comments on commit 42d3e2e

Please sign in to comment.