Skip to content

Instantly share code, notes, and snippets.

@yshnb
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save yshnb/11501428 to your computer and use it in GitHub Desktop.

Select an option

Save yshnb/11501428 to your computer and use it in GitHub Desktop.
test-kitchen + serverspecで行うchef-repoのテスト ref: http://qiita.com/yshnb/items/854a1770d0d47479ab47
driver:
name: vagrant
provisioner:
name: chef_solo
platforms:
# - name: ubuntu-12.04
- name: centos-64
suites:
- name: app
run_list:
- recipe[apache2::default]
attributes:
platform_family: "rhel"
require 'serverspec'
set :backend, :exec
# httpdがインストールされている
describe package("httpd") do
it { should be_installed }
end
# httpdプロセスが稼働している
describe process("httpd") do
it { should be_running }
end
# TCP80番で待ち受けている
describe port("80") do
it { should be_listening.with("tcp") }
end
source "http://api.berksfile.com" # berkshelfのバージョンが<3の場合は site: opscode
cookbook "apache2"
cookbook "hoge", path: "site-cookbooks/hoge" # ローカルのsite-cookbooksに直接存在するcookbook
cookbook "fuga", git: "git:fuga@fuga-repository.com" # gitのリポジトリ上に存在するcookbook
$ gem install chef
$ gem install berkshelf
$ gem install test-kitchen
$ gem install serverspec
$ kitchen converge [INSTANCE]
[2014-05-03T16:13:59+00:00] INFO: Report handlers complete
Chef Client finished, 67/74 resources updated in 67.515359435 seconds
Finished converging <default-centos-64> (2m18.63s).
# テスト用ディレクトリ
$ mkdir -p CHEF-REPO_PATH/test/integration/SUITE_NAME/TESTING_FRAMEWORK/
# テスト用ファイルの作成
$ touch CHEF-REPO_PATH/test/integration/SUITE_NAME/TESTING_FRAMEWORK/*_spec.rb
$ kitchen verify [INSTANCE]
-----> Starting Kitchen (v1.2.1)
-----> Verifying <default-centos-64>...
Suite path directory /tmp/busser/suites does not exist, skipping.
Uploading /tmp/busser/suites/serverspec/apache2_spec.rb (mode=0644)
Uploading /tmp/busser/suites/serverspec/vagrant_spec.rb (mode=0644)
-----> Running serverspec test suite
/opt/chef/embedded/bin/ruby -I/tmp/busser/suites/serverspec -S /opt/chef/embedded/bin/rspec /tmp/busser/suites/serverspec/apache2_spec.rb /tmp/busser/suites/serverspec/vagrant_spec.rb --color --format documentation
Package "httpd"
should be installed
Process "httpd"
should be running
Port "80"
should be listening
User "vagrant"
should exist []
should belong to group "wheel"
Finished in 0.35567 seconds
5 examples, 0 failures
Finished verifying <default-centos-64> (0m2.52s).
-----> Kitchen is finished. (0m3.54s)
require 'serverspec'
set :backend, :exec
# vagrantユーザについて
describe user("vagrant") do
it { should exist } # vagrantユーザが存在する
it { should belong_to_group "wheel" } # vagrantユーザはwheelに所属している
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment